Skip to content

armgit / Soup

Public Imported from GitHub
0

Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.

fix(distill): refuse unsupported vision and audio modalities (#2014)

Nurkhan Esenbek8d7fef7d224b
diff --git a/changelog.d/0.76.0/2014.fixed.md b/changelog.d/0.76.0/2014.fixed.md
new file mode 100644
index 00000000..4182a89d
--- /dev/null
+++ b/changelog.d/0.76.0/2014.fixed.md
@@ -0,0 +1 @@
+- Refuse vision/audio distillation at config load and in `soup doctor` instead of accepting modalities the text-only trainer ignores; preserve supported token/sequence text distillation and document the boundary. (#1186 item 1 by @kok-o in #2014)
diff --git a/docs/training.md b/docs/training.md
index 6efcdf23..674a952c 100644
--- a/docs/training.md
+++ b/docs/training.md
@@ -624,7 +624,7 @@ soup train
## Knowledge Distillation
-Train a small student model to match a larger teacher's output distribution. Every train/val row must keep at least one causal-loss target after truncation at `data.max_length`, and a row without one is refused at setup by split and row number, as SFT does.
+Train a small student model to match a larger teacher's output distribution. Every train/val row must keep at least one causal-loss target after truncation at `data.max_length`, and a row without one is refused at setup by split and row number, as SFT does. Both token-level and sequence-level distillation require `modality: text`; vision and audio inputs are refused at config load because this trainer is text-only.
```yaml
base: HuggingFaceTB/SmolLM2-135M
@@ -2130,7 +2130,7 @@ training:
distill_temperature: 2.0
```
-The cross-validator rejects `task='distill'` without `teacher_model`, and rejects `teacher_model` / `distill_*` fields when `task` is anything other than `distill`. It also refuses `task='distill'` on `backend: mlx` and `backend: unsloth` at config load; distillation runs on `backend: transformers` only.
+The cross-validator rejects `task='distill'` without `teacher_model`, and rejects `teacher_model` / `distill_*` fields when `task` is anything other than `distill`. It also refuses `task='distill'` on `backend: mlx` and `backend: unsloth` at config load; distillation runs on `backend: transformers` only. Both token-level and sequence-level distillation require `modality: text`; `vision` and `audio` are refused at config load because the distill trainer has no multimodal input path.
## EBFT + GDPO (BETA, v0.52.0)
diff --git a/src/soup_cli/config/schema.py b/src/soup_cli/config/schema.py
index 8c139ee5..eb169725 100644
--- a/src/soup_cli/config/schema.py
+++ b/src/soup_cli/config/schema.py
@@ -5979,6 +5979,13 @@ class SoupConfig(BaseModel):
except ValueError as exc:
raise ValueError(str(exc)) from exc
+ if self.modality != "text":
+ raise ValueError(
+ "task='distill' requires modality='text': the distill trainer "
+ "loads a text-only student and teacher and does not process "
+ f"vision or audio inputs; got modality={self.modality!r}."
+ )
+
chunk_offenders = [
name
for name, val in (
diff --git a/tests/test_distill_modality.py b/tests/test_distill_modality.py
new file mode 100644
index 00000000..545c80cc
--- /dev/null
+++ b/tests/test_distill_modality.py
@@ -0,0 +1,58 @@
+"""Distillation must not accept modalities its text-only trainer never reads."""
+
+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, mode="token", backend="transformers"):
+ return {
+ "base": "org/student", "task": "distill", "backend": backend,
+ "modality": modality, "data": {"train": "./train.jsonl"},
+ "training": {"teacher_model": "org/teacher", "distill_mode": mode},
+ }
+
+
[email protected]("modality", ["vision", "audio"])
[email protected]("mode", ["token", "sequence"])
[email protected]("loader", [SoupConfig.model_validate, lambda raw:
+ load_config_from_string(yaml.safe_dump(raw))])
+def test_nontext_distillation_is_refused_at_load(modality, mode, loader):
+ with pytest.raises(ValueError) as caught:
+ loader(_config(modality, mode))
+ message = str(caught.value)
+ assert "task='distill' requires modality='text'" in message
+ assert f"got modality={modality!r}" in message
+ assert "text-only" in message
+
+
[email protected]("mode", ["token", "sequence"])
+def test_text_distillation_still_loads(mode):
+ cfg = load_config_from_string(yaml.safe_dump(_config("text", mode)))
+ assert cfg.modality == "text" and cfg.training.distill_mode == mode
+
+
[email protected]("backend", ["mlx", "unsloth"])
+def test_existing_backend_refusal_keeps_its_reason(backend):
+ with pytest.raises(ValueError, match=f"not supported on backend={backend}"):
+ SoupConfig.model_validate(_config("text", backend=backend))
+
+
[email protected]("modality", ["vision", "audio"])
[email protected]("color", [False, True])
+def test_doctor_reports_unsupported_modality(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='distill' requires modality='text'" in output
+ assert f"got modality={modality!r}" in output