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(config): refuse use_dora on a GPTQ/AWQ/AQLM/EETQ base at config load (#1466) (#1555)
Yang Bai07043e5dd1c8
diff --git a/changelog.d/0.75.1/1555.fixed.md b/changelog.d/0.75.1/1555.fixed.mdnew file mode 100644index 00000000..dd11e5dd--- /dev/null+++ b/changelog.d/0.75.1/1555.fixed.md@@ -0,0 +1,5 @@+- `training.lora.use_dora: true` with `training.quantization: gptq`, `awq`,+ `aqlm` or `eetq` is now refused when the config is loaded. peft has no DoRA+ variant for those layers, so the config used to load and fail only when the+ adapter was attached, after the model load. Autopilot's `decide_peft` reads+ the same format set (#1466 by @ybai08 in #1555).diff --git a/docs/peft-and-efficiency.md b/docs/peft-and-efficiency.mdindex d683ea45..6586dec7 100644--- a/docs/peft-and-efficiency.md+++ b/docs/peft-and-efficiency.md@@ -391,7 +391,14 @@ training:use_dora: true # Enable DoRA```-Works with all training tasks and backends.+Works with all training tasks on the transformers backend (see the note on+quantized bases below).++> **Not on GPTQ / AWQ / AQLM / EETQ bases.** peft has no DoRA variant for those+> layers and raises when the adapter is attached, so `use_dora: true` with+> `quantization: gptq`, `awq`, `aqlm` or `eetq` is refused when the config is+> loaded. Use plain LoRA on those bases, or a `4bit` / `8bit` / `hqq:Nbit` /+> unquantised base to keep DoRA.## LoRA+ (Differentiated Learning Rates)diff --git a/src/soup_cli/autopilot/decisions.py b/src/soup_cli/autopilot/decisions.pyindex ef966b9e..dc093a16 100644--- a/src/soup_cli/autopilot/decisions.py+++ b/src/soup_cli/autopilot/decisions.py@@ -9,6 +9,7 @@ from typing import Any, Literal, Mapping, Optionalfrom soup_cli.utils.flash_attn import check_flash_attn_availablefrom soup_cli.utils.liger import check_liger_available+from soup_cli.utils.quant_menu import DORA_UNSUPPORTED_FORMATSGOAL_TO_TASK: dict[str, str] = {"chat": "sft",@@ -278,7 +279,7 @@ def decide_peft(rank = 32alpha = rank * 2use_dora = data_size > 100_000 and vram_gb >= 2.0 * model_size_b- if quantization in ("gptq", "awq", "aqlm", "eetq"):+ if quantization in DORA_UNSUPPORTED_FORMATS:use_dora = Falsereturn {"r": rank,diff --git a/src/soup_cli/config/schema.py b/src/soup_cli/config/schema.pyindex fef91c82..599e1cd2 100644--- a/src/soup_cli/config/schema.py+++ b/src/soup_cli/config/schema.py@@ -5197,6 +5197,29 @@ class SoupConfig(BaseModel):)return self+ @model_validator(mode="after")+ def _validate_dora_quantization(self) -> "SoupConfig":+ """#1466 - refuse DoRA on a base whose peft LoRA layer has no DoRA variant.++ Without this the config loads and peft raises only when the adapter is+ attached, after the checkpoint download and the model load.+ """+ from soup_cli.utils.quant_menu import DORA_UNSUPPORTED_FORMATS++ if self.backend == "mlx":+ return self # mlx refuses these formats itself, DoRA or not+ quant = self.training.quantization+ if self.training.lora.use_dora and quant in DORA_UNSUPPORTED_FORMATS:+ raise ValueError(+ f"training.lora.use_dora=True is not supported with "+ f"training.quantization={quant!r}: peft cannot apply DoRA to "+ f"{', '.join(sorted(DORA_UNSUPPORTED_FORMATS))} layers and raises "+ "when the adapter is attached, after the model has loaded. Set "+ "use_dora: false to train plain LoRA on this base, or use a "+ "4bit / 8bit / hqq:Nbit / unquantised base to keep DoRA."+ )+ return self+@model_validator(mode="after")def _validate_chat_template_supported_tasks(self) -> "SoupConfig":"""Reject chat-template overrides on trainers that never render chat."""diff --git a/src/soup_cli/utils/quant_menu.py b/src/soup_cli/utils/quant_menu.pyindex d918e529..84618acc 100644--- a/src/soup_cli/utils/quant_menu.py+++ b/src/soup_cli/utils/quant_menu.py@@ -32,6 +32,11 @@ PREQUANTIZED_FORMATS: frozenset[str] = frozenset({"gptq", "awq", "aqlm", "eetq", "mxfp4", "fp8"})+# peft's LoRA layers for these formats raise "<Layer> does not support DoRA yet"+# when the adapter is attached, after the model load. bitsandbytes, HQQ and+# unquantised layers have a DoRA variant. Read by Autopilot and the schema (#1466).+DORA_UNSUPPORTED_FORMATS: frozenset[str] = frozenset({"gptq", "awq", "aqlm", "eetq"})+def is_quant_menu_format(quantization: str) -> bool:"""True for v0.38.0 quant-menu values — seven formats total: HQQ at anydiff --git a/tests/test_issue1466_dora_prequantized.py b/tests/test_issue1466_dora_prequantized.pynew file mode 100644index 00000000..324c7312--- /dev/null+++ b/tests/test_issue1466_dora_prequantized.py@@ -0,0 +1,103 @@+"""#1466 — a hand-written ``use_dora: true`` on a GPTQ / AWQ / AQLM / EETQ base+loaded, then failed when the adapter was attached.++peft's LoRA layers for those four formats raise ``<Layer> does not support DoRA+yet`` in their constructor, which runs after the checkpoint download and the+model load. The pairing is now refused when the config is loaded. Autopilot+already keeps DoRA off for the same formats (#1473); both read one set.+"""++from __future__ import annotations++import pytest++from soup_cli.config.loader import load_config_from_string++NO_DORA = ("gptq", "awq", "aqlm", "eetq")+++def _yaml(quantization: str, *, use_dora: bool, task: str = "sft") -> str:+ return (+ "base: TheBloke/Mistral-7B-Instruct-v0.2-GPTQ\n"+ f"task: {task}\n"+ "data:\n train: t.jsonl\n"+ "training:\n"+ f" quantization: {quantization}\n"+ f" lora:\n use_dora: {str(use_dora).lower()}\n"+ "output: out\n"+ )++[email protected]("quantization", NO_DORA)+def test_dora_on_prequantized_base_is_refused_at_load(quantization):+ with pytest.raises(ValueError) as excinfo:+ load_config_from_string(_yaml(quantization, use_dora=True))+ message = str(excinfo.value)+ assert "use_dora" in message+ assert repr(quantization) in message+ # Says what to change, not only what is wrong.+ assert "use_dora: false" in message++[email protected]("quantization", NO_DORA)+def test_plain_lora_on_prequantized_base_still_loads(quantization):+ cfg = load_config_from_string(_yaml(quantization, use_dora=False))+ assert cfg.training.quantization == quantization+ assert cfg.training.lora.use_dora is False++[email protected]("quantization", ["4bit", "8bit", "none", "hqq:4bit", "fp8"])+def test_dora_stays_allowed_where_peft_builds_it(quantization):+ """peft has a DoRA variant for bitsandbytes, HQQ and unquantised layers."""+ cfg = load_config_from_string(_yaml(quantization, use_dora=True))+ assert cfg.training.lora.use_dora is True+++def test_one_format_set_serves_autopilot_and_the_schema():+ from soup_cli.autopilot.decisions import decide_peft+ from soup_cli.utils.quant_menu import DORA_UNSUPPORTED_FORMATS++ assert DORA_UNSUPPORTED_FORMATS == frozenset(NO_DORA)+ headroom = {"data_size": 200_000, "model_size_b": 7.0, "vram_gb": 80.0}+ for quantization in DORA_UNSUPPORTED_FORMATS:+ assert decide_peft(**headroom, quantization=quantization)["use_dora"] is False+++def test_autopilot_yaml_for_a_gptq_base_reloads(tmp_path):+ """What Autopilot writes must pass the validator it now shares a set with."""+ import json++ from soup_cli.autopilot.generate_config import build_soup_config, write_yaml+ from soup_cli.config.loader import load_config++ data_file = tmp_path / "big.jsonl"+ data_file.write_text(+ "".join(+ json.dumps({"instruction": f"q{i}", "output": f"a{i}"}) + "\n"+ for i in range(100_001)+ ),+ encoding="utf-8",+ )+ cfg = build_soup_config(+ model="TheBloke/Mistral-7B-Instruct-v0.2-GPTQ",+ data_path=str(data_file),+ goal="chat",+ vram_gb=24.0,+ )+ out = tmp_path / "soup.yaml"+ write_yaml(cfg, out)+ reloaded = load_config(out)+ assert reloaded.training.quantization == "gptq"+ assert reloaded.training.lora.use_dora is False++[email protected]("quantization", ["gptq", "awq"])+def test_the_mlx_backend_keeps_its_own_refusal(quantization):+ """mlx refuses these formats outright; sending the user to `use_dora: false`+ first would only lead them to that second refusal."""+ yaml = _yaml(quantization, use_dora=True).replace("task: sft\n", "task: sft\nbackend: mlx\n")+ with pytest.raises(ValueError) as excinfo:+ load_config_from_string(yaml)+ message = str(excinfo.value)+ assert "not supported on the mlx backend" in message+ assert "use_dora: false" not in message