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(config): refuse a non-default moe_aux_loss_coeff on SFT vision and audio (#1394) (#1404)

Maxia67249c02298
diff --git a/changelog.d/0.75.1/1404.fixed.md b/changelog.d/0.75.1/1404.fixed.md
new file mode 100644
index 00000000..ca36796b
--- /dev/null
+++ b/changelog.d/0.75.1/1404.fixed.md
@@ -0,0 +1 @@
+- `training.moe_aux_loss_coeff` set to a non-default value on `task: sft` with `modality: vision` or `audio` is now refused at config load instead of loading and being ignored: only the text setup applies the MoE auxiliary loss (#1394 by @maximilianfeix in #1404).
diff --git a/docs/performance-and-quantization.md b/docs/performance-and-quantization.md
index b483c9e1..9f7aca71 100644
--- a/docs/performance-and-quantization.md
+++ b/docs/performance-and-quantization.md
@@ -1155,7 +1155,7 @@ Both reject silently-no-op combinations: setting either flag without `moe_lora=t
|---|---|---|
| `moe_lora` | `sft`, `pretrain`, `tts`, (since #798) `dpo`, `kto`, `orpo`, `simpo`, `grpo`, (since #1099) `ipo`, `bco`, `reward_model`, `ppo`, `embedding`, `online_dpo`, and (since #1151) `distill`, `unlearn`, and `classifier`, `reranker`, `cross_encoder` with `classifier_lora: true` | refused at config load, naming the reason, on `asr`, `moe_lora_routing`, `prm`, the classifier family without `classifier_lora: true` and `lora.r > 0`, `backend: unsloth` (any task), and `task: sft` with `modality: vision` or `audio` |
| `moe_expert_quant`, `train_router_only` | `sft`, `tts` | refused at config load, naming the task |
-| `moe_aux_loss_coeff` | `sft`, `tts`, `pretrain` | a **non-default** value is refused; the default `0.01` still loads, because every stored config and eleven shipped recipes write it |
+| `moe_aux_loss_coeff` | `sft` (text), `tts`, `pretrain` | a **non-default** value is refused, including on `task: sft` with `modality: vision` or `audio` (#1394), whose setup never applies the auxiliary loss; the default `0.01` still loads, because every stored config and the shipped MoE recipes on those tasks write it |
**`moe_lora` on the remaining LoRA tasks (#1099).** #798 left it loading but unread on `ipo`, `bco`, `reward_model`, `ppo` and `embedding`, and `online_dpo` had the same gap. All six build their adapter through the same `build_lora_config` path, so they were wired to the same helper rather than refused. On `embedding` it applies only with `lora.r >= 1`; at `r: 0` that trainer full-fine-tunes and builds no adapter for the flag to select. #1151 closed the remainder: `distill` and `unlearn` build their adapter the same way and are wired to the same helper, and so is `classifier` / `reranker` / `cross_encoder` (one trainer) on its opt-in adapter path. Without `classifier_lora: true` and `lora.r > 0` that trainer full-fine-tunes and builds no adapter, so there the flag is refused at config load; `asr`, which trains only Whisper (no experts), `moe_lora_routing`, which builds no LoRA adapter, and `prm`, which fine-tunes every base parameter, refuse the flag at config load. Two paths refuse it whatever the task: `task: sft` with `modality: vision` or `audio`, whose setup builds its adapter without the MoE step, and `backend: unsloth`. On unsloth the reason depends on the task (#1264): the thirteen tasks with an unsloth setup attach its fixed attention list and never read the flag, while the rest have no unsloth setup at all, so there it is the backend that goes unapplied. Both messages point to `backend: transformers`, where the flag is read. The other `moe_lora` refusals in the same check come first, so `asr`, `prm`, `moe_lora_routing` and SFT vision/audio get one refusal whatever the backend. Every path now either reads `moe_lora` or refuses it, except `backend: mlx`, where it loads and `soup doctor --config` reports it as ignored; a source ratchet keeps a new adapter-building trainer from missing it. `train_router_only` and `moe_expert_quant` require `moe_lora: true`, so on `backend: unsloth` they now fail to load with the same message. `preference` is covered through the trainers it dispatches to, and `tts` through the SFT trainer it subclasses.
diff --git a/src/soup_cli/config/schema.py b/src/soup_cli/config/schema.py
index a2eb86b9..48016cb9 100644
--- a/src/soup_cli/config/schema.py
+++ b/src/soup_cli/config/schema.py
@@ -5697,7 +5697,7 @@ class SoupConfig(BaseModel):
``moe_aux_loss_coeff``'s default is ``0.01``, and a dumped config writes
it out, so only a NON-DEFAULT value is refused: refusing the default
- would break every stored config and the eleven shipped recipes that
+ would break every stored config and the shipped MoE recipes that
write it explicitly.
"""
tcfg = self.training
@@ -5720,6 +5720,19 @@ class SoupConfig(BaseModel):
f"{sorted(_MOE_AUX_LOSS_TASKS)} read it (sft.py, "
f"pretrain.py). Remove it, or use one of those tasks."
)
+ return self
+ if self.task == "sft" and self.modality in ("vision", "audio"):
+ # #1394: only SFT's text setup reads it. The vision and audio setups
+ # build their model without the MoE step, the same gap #1179 closed
+ # for moe_lora on these paths.
+ default = type(tcfg).model_fields["moe_aux_loss_coeff"].default
+ if tcfg.moe_aux_loss_coeff != default:
+ raise ValueError(
+ f"training.moe_aux_loss_coeff={tcfg.moe_aux_loss_coeff!r} is "
+ f"not applied by task='sft' with modality={self.modality!r}: "
+ "that setup never applies the MoE auxiliary loss. Remove it, "
+ "or train with modality: text."
+ )
return self
@model_validator(mode="after")
diff --git a/tests/test_issue1394_moe_aux_loss_modality.py b/tests/test_issue1394_moe_aux_loss_modality.py
new file mode 100644
index 00000000..bc711321
--- /dev/null
+++ b/tests/test_issue1394_moe_aux_loss_modality.py
@@ -0,0 +1,50 @@
+"""#1394 — ``training.moe_aux_loss_coeff`` is read only by SFT's text setup.
+
+``SFTTrainerWrapper._setup_transformers`` applies it; the vision and audio
+setups never do, so a non-default value on those modalities loaded and was
+silently ignored. It is refused at load now, like #1179's ``moe_lora``.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from soup_cli.config.loader import load_config_from_string
+
+
+def _yaml(task: str, modality: str | None, coeff: str | None) -> str:
+ lines = ["base: some/model", f"task: {task}"]
+ if modality is not None:
+ lines.append(f"modality: {modality}")
+ lines += ["data:", " train: ./data.jsonl", " format: auto"]
+ if coeff is not None:
+ lines += ["training:", f" moe_aux_loss_coeff: {coeff}"]
+ return "\n".join(lines) + "\n"
+
+
[email protected]("modality", ["vision", "audio"])
+def test_non_default_coeff_refused_on_vision_and_audio(modality):
+ with pytest.raises(ValueError, match=rf"modality='{modality}'") as exc:
+ load_config_from_string(_yaml("sft", modality, "0.05"))
+ assert "moe_aux_loss_coeff" in str(exc.value)
+ assert "modality: text" in str(exc.value)
+
+
[email protected]("modality", [None, "text", "vision", "audio", "audio_out"])
[email protected]("coeff", [None, "0.01"])
+def test_default_coeff_still_loads_everywhere(modality, coeff):
+ cfg = load_config_from_string(_yaml("sft", modality, coeff))
+ assert cfg.training.moe_aux_loss_coeff == 0.01
+
+
[email protected]("modality", [None, "text", "audio_out"])
+def test_text_sft_keeps_a_non_default_coeff(modality):
+ # audio_out is neither "vision" nor "audio", so SFTTrainerWrapper.setup()
+ # dispatches it to the text setup, which applies the coefficient.
+ cfg = load_config_from_string(_yaml("sft", modality, "0.05"))
+ assert cfg.training.moe_aux_loss_coeff == 0.05
+
+
+def test_pretrain_keeps_a_non_default_coeff():
+ cfg = load_config_from_string(_yaml("pretrain", None, "0.05"))
+ assert cfg.training.moe_aux_loss_coeff == 0.05