Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.
Python cliconsumer-gpudpofine-tuningggufhuggingfacellmllmopslocal-ailocal-llmloralow-vrammachine-learningollamapeftpythonpytorchqlorasfttransformers
fix(sft): refuse ignored Unsloth backend for vision and audio (#2015)
Nurkhan Esenbekee01481e207b
diff --git a/changelog.d/0.76.0/2015.fixed.md b/changelog.d/0.76.0/2015.fixed.mdnew file mode 100644index 00000000..7f7ba6d3--- /dev/null+++ b/changelog.d/0.76.0/2015.fixed.md@@ -0,0 +1 @@+- Refuse Unsloth vision/audio SFT at config load instead of silently using transformers, report the supported backend in `soup doctor`, and correct both inline and file-backed multimodal templates. (#1186 item 2 by @kok-o in #2015)diff --git a/docs/training.md b/docs/training.mdindex 674a952c..4dc901ff 100644--- a/docs/training.md+++ b/docs/training.md@@ -59,6 +59,11 @@---+Multimodal SFT (`task: sft` with `modality: vision` or `audio`) requires+`backend: transformers` rather than `backend: unsloth`. The vision and audio setup+paths do not use Unsloth; requesting it is refused at config load instead of+silently falling back to transformers. Text SFT continues to support Unsloth.+## Validation split & evaluation (`training.eval_steps`)`data.val_split` (default `0.1`) holds that share of the rows out of training,diff --git a/src/soup_cli/config/schema.py b/src/soup_cli/config/schema.pyindex eb169725..d7abfac0 100644--- a/src/soup_cli/config/schema.py+++ b/src/soup_cli/config/schema.py@@ -8580,6 +8580,18 @@ class SoupConfig(BaseModel):f"checkpoint's own RoPE. Use {changes}, or remove {keys}.")+ @model_validator(mode="after")+ def _validate_unsloth_sft_modality(self) -> "SoupConfig":+ """#1186: multimodal SFT setup does not use the requested Unsloth backend."""+ if self.task == "sft" and self.backend == "unsloth" and self.modality != "text":+ raise ValueError(+ "task='sft' with backend='unsloth' requires modality='text': "+ "the vision and audio setup paths load through transformers and "+ f"do not use Unsloth; got modality={self.modality!r}. "+ "Use backend: transformers for multimodal SFT."+ )+ return self+@model_validator(mode="after")def _validate_unsloth_has_a_setup(self) -> "SoupConfig":"""#1357 — ``backend: unsloth`` on a task outside@@ -8695,7 +8707,7 @@ output: ./outputbase: meta-llama/Llama-3.2-11B-Vision-Instructtask: sftmodality: vision-# backend: unsloth # 2-5x faster, pip install "soup-cli[fast]"+backend: transformers # The vision SFT path does not use Unsloth.data:train: ./data/vision_train.jsonl@@ -9042,7 +9054,7 @@ output: ./output_embeddingbase: Qwen/Qwen2-Audio-7B-Instructtask: sftmodality: audio-# backend: unsloth # 2-5x faster, pip install "soup-cli[fast]"+backend: transformers # The audio SFT path does not use Unsloth.data:train: ./data/audio_train.jsonldiff --git a/src/soup_cli/templates/audio.yaml b/src/soup_cli/templates/audio.yamlindex 0dd11196..955145bd 100644--- a/src/soup_cli/templates/audio.yaml+++ b/src/soup_cli/templates/audio.yaml@@ -11,7 +11,7 @@base: Qwen/Qwen2-Audio-7B-Instructtask: sftmodality: audio-# backend: unsloth # 2-5x faster, pip install "soup-cli[fast]"+backend: transformers # The audio SFT path does not use Unsloth.data:train: ./data/audio_train.jsonldiff --git a/src/soup_cli/templates/vision.yaml b/src/soup_cli/templates/vision.yamlindex 84a1a4fc..75b0545a 100644--- a/src/soup_cli/templates/vision.yaml+++ b/src/soup_cli/templates/vision.yaml@@ -4,7 +4,7 @@base: meta-llama/Llama-3.2-11B-Vision-Instructtask: sftmodality: vision-# backend: unsloth # 2-5x faster, pip install "soup-cli[fast]"+backend: transformers # The vision SFT path does not use Unsloth.data:train: ./data/vision_train.jsonldiff --git a/tests/test_issue1124_sft_audio_stream_unsloth_fp8.py b/tests/test_issue1124_sft_audio_stream_unsloth_fp8.pyindex dd8f371d..50db464e 100644--- a/tests/test_issue1124_sft_audio_stream_unsloth_fp8.py+++ b/tests/test_issue1124_sft_audio_stream_unsloth_fp8.py@@ -414,6 +414,13 @@ class TestBackendSupportRegistryUnsloth:data = {"train": "tests/fixtures/sample_train.jsonl"}if modality == "vision":data["format"] = "multimodal"+ # #1186 now refuses the ignored backend even without precision knobs.+ with pytest.raises(ValueError, match="requires modality='text'"):+ SoupConfig(+ base="test/model", task="sft", backend="unsloth",+ modality=modality, data=data,+ )+ returncfg = SoupConfig(base="test/model", task="sft", backend="unsloth", modality=modality, data=data)diff --git a/tests/test_issue1358_vocab_expansion_refused.py b/tests/test_issue1358_vocab_expansion_refused.pyindex dfeebe38..2c12c37a 100644--- a/tests/test_issue1358_vocab_expansion_refused.py+++ b/tests/test_issue1358_vocab_expansion_refused.py@@ -224,18 +224,29 @@ class TestTheSplitMatchesTheTrainers:class TestSftVisionAndAudioOnUnsloth:- """SFT's setup() sends vision / audio to their transformers setups before it- reads the backend, and both of those call apply_vocab_expansion (review of- #1622); only the text path reaches _setup_unsloth. MLX stays refused: it- ignores modality."""+ """#1186 refuses the ignored backend, including with vocabulary additions.++ The supported transformers multimodal paths still apply those additions.+ """@pytest.mark.parametrize("field", _FIELDS)@pytest.mark.parametrize(("modality", "fmt"), [("vision", "llava"), ("audio", "audio")])- def test_they_still_load(self, modality, fmt, field):- cfg = load_config_from_string(+ def test_unsloth_is_refused_instead_of_falling_back(self, modality, fmt, field):+ message = _refusal(_yaml("sft", backend="unsloth", field=field, modality=modality,data={"format": fmt}))+ assert "task='sft' with backend='unsloth' requires modality='text'" in message+ assert f"got modality={modality!r}" in message+ assert "Use backend: transformers" in message++ @pytest.mark.parametrize("field", _FIELDS)+ @pytest.mark.parametrize(("modality", "fmt"), [("vision", "llava"), ("audio", "audio")])+ def test_transformers_still_loads_vocabulary_additions(self, modality, fmt, field):+ cfg = load_config_from_string(+ _yaml("sft", backend="transformers", field=field, modality=modality,+ data={"format": fmt})+ )assert getattr(cfg.data, field) == ["<x>"]diff --git a/tests/test_unsloth.py b/tests/test_unsloth.pyindex 9debb4d4..b6f110d4 100644--- a/tests/test_unsloth.py+++ b/tests/test_unsloth.py@@ -326,13 +326,18 @@ class TestTemplatesHaveUnslothHint:assert "unsloth" in TEMPLATES["medical"]def test_templates_default_backend_commented(self):- """Templates should have unsloth commented out (not active by default)."""+ """Only supported paths recommend opting into Unsloth."""for name, template in TEMPLATES.items():if name == "longcontext":# #1697: it sets rope_scaling_type, which unsloth's setup does not# read, so the hint would suggest a line the loader refuses.assert "unsloth" not in templatecontinue+ if name in ("vision", "audio"):+ # #1186: the multimodal SFT paths never invoke Unsloth.+ assert "backend: transformers" in template+ assert "backend: unsloth" not in template+ continueassert "# backend: unsloth" in template, f"{name} template missing unsloth hint"diff --git a/tests/test_unsloth_sft_modality.py b/tests/test_unsloth_sft_modality.pynew file mode 100644index 00000000..124de058--- /dev/null+++ b/tests/test_unsloth_sft_modality.py@@ -0,0 +1,67 @@+"""Multimodal SFT must not silently drop a requested Unsloth backend."""++import pytest+import yaml+from typer.testing import CliRunner++from soup_cli.cli import app+from soup_cli.config.loader import load_config_from_string+from soup_cli.config.schema import SoupConfig+from tests.conftest import strip_ansi+++def _config(modality, backend="unsloth"):+ return {+ "base": "org/model", "task": "sft", "backend": backend,+ "modality": modality, "data": {"train": "./train.jsonl"},+ }++[email protected]("modality", ["vision", "audio"])[email protected]("loader", [SoupConfig.model_validate, lambda raw:+ load_config_from_string(yaml.safe_dump(raw))])+def test_unsloth_multimodal_sft_is_refused_at_load(modality, loader):+ with pytest.raises(ValueError) as caught:+ loader(_config(modality))+ message = str(caught.value)+ assert "task='sft' with backend='unsloth' requires modality='text'" in message+ assert f"got modality={modality!r}" in message+ assert "Use backend: transformers" in message++[email protected]("modality", ["vision", "audio", "text"])+def test_transformers_sft_still_loads(modality):+ cfg = load_config_from_string(yaml.safe_dump(_config(modality, "transformers")))+ assert cfg.backend == "transformers" and cfg.modality == modality+++def test_unsloth_text_sft_still_loads():+ cfg = SoupConfig.model_validate(_config("text"))+ assert cfg.backend == "unsloth" and cfg.modality == "text"++[email protected]("modality", ["vision", "audio"])[email protected]("inline", [False, True])+def test_shipped_multimodal_templates_use_supported_backend(modality, inline):+ from soup_cli.config.schema import TEMPLATES+ from soup_cli.templates import load_template++ text = TEMPLATES[modality] if inline else load_template(modality)+ cfg = load_config_from_string(text)+ assert cfg.backend == "transformers" and cfg.modality == modality+ assert "backend: unsloth" not in text++[email protected]("modality", ["vision", "audio"])[email protected]("color", [False, True])+def test_doctor_reports_ignored_backend(tmp_path, modality, color):+ path = tmp_path / "soup.yaml"+ path.write_text(yaml.safe_dump(_config(modality)), encoding="utf-8")+ result = CliRunner().invoke(+ app, ["doctor", "--config", str(path)], color=color,+ env={"FORCE_COLOR": "1" if color else "0"},+ )+ assert result.exit_code == 2, (result.output, result.exception)+ output = " ".join(strip_ansi(result.output).split())+ assert "task='sft' with backend='unsloth' requires modality='text'" in output+ assert "Use backend: transformers" in outputdiff --git a/tests/test_vision.py b/tests/test_vision.pyindex ae038a79..b764c89e 100644--- a/tests/test_vision.py+++ b/tests/test_vision.py@@ -481,9 +481,10 @@ class TestVisionTemplate:"""Vision template should use a vision model."""assert "Vision" in TEMPLATES["vision"]- def test_vision_template_mentions_unsloth(self):- """Vision template should mention unsloth as an option."""- assert "unsloth" in TEMPLATES["vision"]+ def test_vision_template_selects_supported_backend(self):+ """#1186: vision SFT runs on transformers and must not recommend Unsloth."""+ assert "backend: transformers" in TEMPLATES["vision"]+ assert "backend: unsloth" not in TEMPLATES["vision"]def test_vision_template_is_valid_yaml(self):"""Vision template should be valid YAML that parses."""