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.

Refuse training.freeze_trainable_layers without expand_layers (#1396) (#1399)

Kratosbf6ccf00496a
diff --git a/changelog.d/0.75.1/1399.fixed.md b/changelog.d/0.75.1/1399.fixed.md
new file mode 100644
index 00000000..dc8787af
--- /dev/null
+++ b/changelog.d/0.75.1/1399.fixed.md
@@ -0,0 +1 @@
+- **`training.freeze_trainable_layers` without `training.expand_layers` is now refused at config load (#1396 by @wanjinhao1 in #1399).** The field was accepted on its own but read by nothing: without `expand_layers`, `utils/block_expansion.py` returned before looking at it, so a config that set `freeze_trainable_layers: 2` to train only the top two layers trained the whole model (or every LoRA target), with no message. The error names both fields and the remedy (remove it, or set `expand_layers`); the field description and `docs/peft-and-efficiency.md` now say it applies only together with `expand_layers`.
diff --git a/docs/peft-and-efficiency.md b/docs/peft-and-efficiency.md
index 240a6430..fd4e76fa 100644
--- a/docs/peft-and-efficiency.md
+++ b/docs/peft-and-efficiency.md
@@ -176,7 +176,7 @@ data:
train: ./domain.jsonl
training:
expand_layers: 4 # append 4 zero-init decoder blocks
- freeze_trainable_layers: 4 # train only the appended blocks
+ freeze_trainable_layers: 4 # train only the appended blocks (requires expand_layers)
lr: 5e-5
epochs: 1
```
diff --git a/src/soup_cli/config/schema.py b/src/soup_cli/config/schema.py
index ea206d30..be147304 100644
--- a/src/soup_cli/config/schema.py
+++ b/src/soup_cli/config/schema.py
@@ -1270,9 +1270,10 @@ class TrainingConfig(BaseModel):
freeze_trainable_layers: Optional[int] = Field(
default=None,
description=(
- "LLaMA Pro: signed int. Positive = train only top-N decoder "
- "layers; negative = train only bottom-N. Magnitude capped at "
- "1000. (v0.41.0)"
+ "LLaMA Pro: applies only together with expand_layers and is "
+ "refused without it. A positive value freezes every parameter "
+ "except the appended blocks. Magnitude capped at 1000. "
+ "(v0.41.0)"
),
)
# v0.41.0 Part C schema / v0.71.12 #84 live — Mixture-of-Depths routing.
@@ -4136,6 +4137,14 @@ class TrainingConfig(BaseModel):
"freezes the original layers and trains only the new blocks). "
"Set freeze_trainable_layers: <signed int>."
)
+ if self.expand_layers is None and self.freeze_trainable_layers is not None:
+ raise ValueError(
+ "freeze_trainable_layers only applies together with "
+ "expand_layers (LLaMA Pro block expansion), where a positive "
+ "value trains only the appended blocks. Without expand_layers "
+ "nothing reads it, so the run trains as if it were unset. "
+ "Remove it, or set expand_layers: <int> to append new blocks."
+ )
return self
@model_validator(mode="after")
diff --git a/tests/test_v0410_part_c.py b/tests/test_v0410_part_c.py
index 1cd04a41..f9acc174 100644
--- a/tests/test_v0410_part_c.py
+++ b/tests/test_v0410_part_c.py
@@ -135,10 +135,31 @@ class TestSchemaBlockExpansion:
assert cfg.expand_layers == 4
assert cfg.freeze_trainable_layers == 4
- def test_freeze_trainable_layers_alone_ok(self):
- cfg = TrainingConfig(freeze_trainable_layers=-4)
- assert cfg.freeze_trainable_layers == -4
- assert cfg.expand_layers is None
+ @pytest.mark.parametrize("freeze", [2, -4, 0])
+ def test_freeze_trainable_layers_alone_refused(self, freeze):
+ # #1396: without expand_layers nothing reads the field, so every value
+ # (positive, negative or zero) trained as if it were unset.
+ with pytest.raises(
+ ValidationError,
+ match="freeze_trainable_layers only applies together with expand_layers",
+ ):
+ TrainingConfig(freeze_trainable_layers=freeze)
+
+ @pytest.mark.parametrize("task", ["sft", "pretrain"])
+ def test_freeze_trainable_layers_alone_refused_at_load(self, task):
+ # The issue's own case, through the loader `soup train` uses.
+ from soup_cli.config.loader import load_config_from_string
+
+ with pytest.raises(
+ ValueError,
+ match="only applies together with expand_layers.*Remove it",
+ ):
+ load_config_from_string(
+ "base: org/model\n"
+ f"task: {task}\n"
+ "data:\n train: ./data.jsonl\n"
+ "training:\n freeze_trainable_layers: 2\n"
+ )
def test_freeze_magnitude_oob(self):
with pytest.raises(ValidationError, match="magnitude"):
diff --git a/tests/test_v07134.py b/tests/test_v07134.py
index 3ea35f74..a57487c6 100644
--- a/tests/test_v07134.py
+++ b/tests/test_v07134.py
@@ -679,7 +679,7 @@ training:
(" loraplus_lr_ratio: 4.0\n", "loraplus_lr_ratio"),
(" unfrozen_parameters: ['model.layers.0.mlp']\n", "unfrozen_parameters"),
(" expand_layers: 2\n", "expand_layers"),
- (" freeze_trainable_layers: 3\n", "freeze_trainable_layers"),
+ (" expand_layers: 2\n freeze_trainable_layers: 2\n", "freeze_trainable_layers"),
],
)
def test_mutual_exclusion(self, extra, kw):