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 `training.neftune_alpha` is accepted on every task but applied only by seven wrappers; elsewhere it is silently dropped (#1883)
DBVamsibe19042925f7
diff --git a/changelog.d/0.76.0/1883.fixed.md b/changelog.d/0.76.0/1883.fixed.mdnew file mode 100644index 00000000..72481cec--- /dev/null+++ b/changelog.d/0.76.0/1883.fixed.md@@ -0,0 +1 @@+- `training.neftune_alpha` is now refused at config load on the 14 tasks whose trainer never forwards it to `TrainingArguments.neftune_noise_alpha` (it was silently dropped); `docs/peft-and-efficiency.md` now lists the 9 tasks that apply it (#1820 by @DBVamsi in #1883)diff --git a/docs/peft-and-efficiency.md b/docs/peft-and-efficiency.mdindex 931a91d6..54ccabdd 100644--- a/docs/peft-and-efficiency.md+++ b/docs/peft-and-efficiency.md@@ -500,7 +500,7 @@ training:neftune_alpha: 5.0 # Noise intensity (0-50, typically 5-15)```-Works with SFT, DPO, KTO, ORPO, SimPO, and IPO tasks.+Works with SFT, TTS, DPO, KTO, ORPO, SimPO, IPO, BCO, and preference tasks.## Sample Packingdiff --git a/src/soup_cli/config/schema.py b/src/soup_cli/config/schema.pyindex 25bea321..9f7a86c4 100644--- a/src/soup_cli/config/schema.py+++ b/src/soup_cli/config/schema.py@@ -4853,6 +4853,13 @@ FREEZE_APPLYING_TASKS: frozenset[str] = frozenset({"sft", "tts"})#: within these tasks on every path that does not reach those two methods.ROPE_SCALING_APPLYING_TASKS: frozenset[str] = frozenset({"sft", "tts", "pretrain"})+#: #1820 — the tasks whose trainer reads ``training.neftune_alpha`` and passes+#: it as ``neftune_noise_alpha`` to ``TrainingArguments``. Every other task+#: ignores the field, so it is refused there at config load.+NEFTUNE_APPLYING_TASKS: frozenset[str] = frozenset({+ "sft", "tts", "dpo", "ipo", "kto", "orpo", "simpo", "bco", "preference",+})+#: The bitsandbytes values: ``4bit`` was the default, so every config Soup dumped#: for these tasks carries one of them literally (#795 review)._BNB_QUANTIZATION_VALUES = frozenset({"4bit", "8bit"})@@ -6111,6 +6118,30 @@ class SoupConfig(BaseModel):)return self+ @model_validator(mode="after")+ def _validate_neftune_alpha_task_gate(self) -> "SoupConfig":+ """#1820: refuse ``neftune_alpha`` on tasks whose trainer never reads it.++ ``training.neftune_alpha`` is forwarded to+ ``TrainingArguments.neftune_noise_alpha`` by the SFT-family wrappers+ (``sft.py``, inherited by ``tts.py``) and by the preference-style+ wrappers (``dpo.py``, ``ipo.py``, ``kto.py``, ``orpo.py``,+ ``simpo.py``, ``bco.py``). The ``preference`` dispatcher delegates to+ one of those, so it also applies. Every other task silently drops the+ field — refuse it at load time so the user sees the mismatch instead of+ training without NEFTune noise and wondering why.+ """+ tcfg = self.training+ if tcfg.neftune_alpha is not None and self.task not in NEFTUNE_APPLYING_TASKS:+ raise ValueError(+ f"training.neftune_alpha={tcfg.neftune_alpha!r} is set, but "+ f"task={self.task!r} never applies it (any value, including 0.0, "+ f"is refused). Only tasks in {sorted(NEFTUNE_APPLYING_TASKS)} forward "+ f"it to ``TrainingArguments.neftune_noise_alpha``. Remove "+ f"training.neftune_alpha, or use one of those tasks."+ )+ return self+@model_validator(mode="after")def _validate_moe_flags_reach_a_trainer(self) -> "SoupConfig":"""#798 — refuse MoE flags on tasks whose trainer never reads them.diff --git a/tests/test_neftune_rslora.py b/tests/test_neftune_rslora.pyindex 8f9c4020..2f6debb5 100644--- a/tests/test_neftune_rslora.py+++ b/tests/test_neftune_rslora.py@@ -1,8 +1,16 @@"""Tests for NEFTune (neftune_alpha) and rsLoRA (use_rslora) support."""+import typing+import pytest+from pydantic import ValidationError-from soup_cli.config.schema import LoraConfig, SoupConfig, TrainingConfig+from soup_cli.config.schema import (+ NEFTUNE_APPLYING_TASKS,+ LoraConfig,+ SoupConfig,+ TrainingConfig,+)# ---------------------------------------------------------------------------# NEFTune config tests@@ -238,3 +246,107 @@ class TestRsLoRASweep:}_set_nested_param(config_dict, "use_rslora", True)assert config_dict["training"]["lora"]["use_rslora"] is True+++# ---------------------------------------------------------------------------+# NEFTune task-gate (issue #1820)+# ---------------------------------------------------------------------------++#: All tasks declared in the ``task`` Literal of SoupConfig, derived via+#: ``typing.get_args`` so adding a task to the schema Literal updates this.+ALL_TASKS: frozenset[str] = frozenset(+ typing.get_args(SoupConfig.model_fields["task"].annotation),+)++#: NEFTUNE_APPLYING_TASKS must be a subset of ALL_TASKS.+assert NEFTUNE_APPLYING_TASKS.issubset(ALL_TASKS)+++class TestNEFTuneTaskGate:+ """#1820: neftune_alpha is refused on tasks whose trainer never reads it."""++ def _make_cfg(+ self,+ task: str,+ neftune_alpha: float = 5.0,+ **extra_training,+ ) -> SoupConfig:+ """Build a minimal SoupConfig with a given task and neftune_alpha.++ Some tasks need extra fields to pass validation (tts needs modality,+ preference needs preference_loss, classifier/reranker/cross_encoder+ need num_labels, distill needs teacher_model). Those are passed via+ *extra_training* so the caller can satisfy those preconditions.+ """+ training_kw = {"neftune_alpha": neftune_alpha}+ training_kw.update(extra_training)+ modality = "text"+ if task == "tts":+ modality = "audio_out"+ return SoupConfig(+ base="test-model",+ task=task,+ modality=modality,+ data={"train": "./data.jsonl"},+ training=training_kw,+ )++ @pytest.mark.parametrize("task", sorted(NEFTUNE_APPLYING_TASKS))+ def test_applying_tasks_accept_neftune_alpha(self, task):+ """Tasks in NEFTUNE_APPLYING_TASKS accept neftune_alpha without error."""+ # preference needs preference_loss; tts needs audio_out modality+ # and a tts_family.+ extra: dict = {}+ if task == "preference":+ extra["preference_loss"] = "dpo"+ if task == "tts":+ extra["tts_family"] = "orpheus"+ cfg = self._make_cfg(task, 5.0, **extra)+ assert cfg.training.neftune_alpha == 5.0++ @pytest.mark.parametrize("task", sorted(ALL_TASKS - NEFTUNE_APPLYING_TASKS))+ def test_non_applying_tasks_reject_neftune_alpha(self, task):+ """Tasks NOT in NEFTUNE_APPLYING_TASKS reject neftune_alpha at load."""+ # Some tasks need extra fields to reach the neftune gate.+ extra: dict = {}+ if task in ("classifier", "reranker", "cross_encoder"):+ extra["num_labels"] = 2+ if task == "distill":+ extra["teacher_model"] = "teacher"+ with pytest.raises(+ ValidationError, match=rf"training\.neftune_alpha.*task='{task}'"+ ):+ self._make_cfg(task, 5.0, **extra)++ def test_mutation_check_drop_one_task(self, monkeypatch):+ """Mutation test: removing a task from NEFTUNE_APPLYING_TASKS fails.++ Verifies that the validator uses the NEFTUNE_APPLYING_TASKS constant+ (not a hardcoded set) by dropping one task and checking that the+ config is then rejected for that task.+ """+ import soup_cli.config.schema as schema_module++ monkeypatch.setattr(+ schema_module,+ "NEFTUNE_APPLYING_TASKS",+ NEFTUNE_APPLYING_TASKS - {"dpo"},+ )+ # dpo is no longer in the set, so neftune_alpha=5.0 should be refused.+ with pytest.raises(+ ValidationError, match=r"training\.neftune_alpha.*task='dpo'"+ ):+ self._make_cfg("dpo", 5.0)++ def test_neftune_alpha_zero_is_refused(self):+ """neftune_alpha=0.0 is refused on non-applying tasks (gate checks is not None)."""+ with pytest.raises(+ ValidationError, match=r"training\.neftune_alpha.*task='grpo'"+ ):+ self._make_cfg("grpo", 0.0)++ def test_applying_tasks_pinned(self):+ """NEFTUNE_APPLYING_TASKS is pinned literally — removing any task fails."""+ assert NEFTUNE_APPLYING_TASKS == frozenset({+ "sft", "tts", "dpo", "ipo", "kto", "orpo", "simpo", "bco", "preference",+ })