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(quant): refuse quantization: fp8 below transformers 5.17.0, with the reason (#1731) (#1745)

Yang Bai3515a8f030fc
diff --git a/changelog.d/0.75.1/1745.fixed.md b/changelog.d/0.75.1/1745.fixed.md
new file mode 100644
index 00000000..ae5a67d4
--- /dev/null
+++ b/changelog.d/0.75.1/1745.fixed.md
@@ -0,0 +1 @@
+- **`training.quantization: fp8` stops with the reason on transformers below 5.17.0 (#1731 by @ybai08 in #1745).** Soup's declared floor is 5.16.1, and there the FP8 quantizer raises `AttributeError: 'NoneType' object has no attribute 'get'` in `update_tp_plan` when it loads a dense base, so an `fp8` run died inside transformers. The run now stops where the quantization config is built: `quantization: fp8 needs transformers >= 5.17.0, and 5.16.1 is installed`, with the cause and `pip install -U 'transformers>=5.17.0'`. Every other quantization mode is unchanged on 5.16.1. The Quant Menu row and the missing-class message said `>= 4.45`; both now say 5.17.0.
diff --git a/docs/performance-and-quantization.md b/docs/performance-and-quantization.md
index 67a90aaa..3ffb964b 100644
--- a/docs/performance-and-quantization.md
+++ b/docs/performance-and-quantization.md
@@ -371,7 +371,7 @@ training:
| `aqlm` | 2 | Extreme compression. | aqlm |
| `eetq` | 8 | Fast 8-bit kernel for SM75+. | eetq |
| `mxfp4` | 4 (stored) | Train LoRA on top of an MXFP4 pre-quantized checkpoint (for example GPT-OSS). Loaded with `Mxfp4Config(dequantize=True)`, so it trains in bf16: transformers does not train MXFP4 weights as loaded. Budget memory for the bf16 model, an estimated 2 bytes per parameter (roughly 42 GB for a 20B base). The `soup train` VRAM pre-flight checks an `mxfp4` run against that estimate, as it does a `quantization: none` run, and `--allow-oom-attempt` launches one it refuses. | — |
-| `fp8` | — | Train LoRA on top of an FP8-released checkpoint. Loaded with `FineGrainedFP8Config(dequantize=True)`, so it trains in bf16: budget memory for the bf16 model, an estimated 2 bytes per parameter, not for the FP8 file. | transformers ≥ 4.45 |
+| `fp8` | — | Train LoRA on top of an FP8-released checkpoint. Loaded with `FineGrainedFP8Config(dequantize=True)`, so it trains in bf16: budget memory for the bf16 model, an estimated 2 bytes per parameter, not for the FP8 file. | transformers ≥ 5.17.0 |
**VRAM pre-flight.** Before the model loads, `soup train` prices the weights
of the chosen format and refuses a run that does not fit the card
diff --git a/src/soup_cli/utils/quant_menu.py b/src/soup_cli/utils/quant_menu.py
index 9daac55b..9e1df822 100644
--- a/src/soup_cli/utils/quant_menu.py
+++ b/src/soup_cli/utils/quant_menu.py
@@ -282,6 +282,34 @@ def build_fp8_dequant_config() -> dict[str, Any]:
return {"dequantize": True}
+#: #1731 — the first transformers whose FP8 quantizer loads a dense base. Up to
+#: 5.16.1, ``FineGrainedFP8HfQuantizer.update_tp_plan`` reads
+#: ``FP8Experts._impl_tp_layer_overrides.get(impl)`` with no default, and a base
+#: without MegaMoE experts raises ``AttributeError`` before a weight is read.
+FP8_MIN_TRANSFORMERS = "5.17.0"
+
+
+def _refuse_fp8_on_old_transformers() -> None:
+ """Stop an ``fp8`` run where its config is built, not inside the load.
+
+ Here and not in the schema: it depends on what is installed, not on the
+ config. A pre-release of the minimum sorts below it and is refused too.
+ """
+ import transformers
+ from packaging.version import Version
+
+ installed = transformers.__version__
+ if Version(installed) < Version(FP8_MIN_TRANSFORMERS):
+ raise RuntimeError(
+ f"quantization: fp8 needs transformers >= {FP8_MIN_TRANSFORMERS}, and "
+ f"{installed} is installed: its FP8 quantizer raises AttributeError in "
+ "update_tp_plan when it loads a dense base (fixed in "
+ f"{FP8_MIN_TRANSFORMERS}). Upgrade with "
+ f"pip install -U 'transformers>={FP8_MIN_TRANSFORMERS}', or pick another "
+ "quantization."
+ )
+
+
# ---------------------------------------------------------------------------
# Part H — Compatibility matrix (quant × multi-GPU)
# ---------------------------------------------------------------------------
@@ -510,6 +538,7 @@ def build_quantization_config_for_loader(
)
return Mxfp4Config(**build_mxfp4_config())
if quantization == "fp8":
+ _refuse_fp8_on_old_transformers()
try:
from transformers import FineGrainedFP8Config as _FP8Cfg
except ImportError:
@@ -518,7 +547,8 @@ def build_quantization_config_for_loader(
except ImportError as exc:
raise RuntimeError(
"transformers does not expose an FP8 config — "
- "upgrade transformers >= 4.45 to use quantization='fp8'."
+ f"upgrade transformers >= {FP8_MIN_TRANSFORMERS} to use "
+ "quantization='fp8'."
) from exc
if console is not None:
console.print("[green]FP8:[/] dequantize-on-load")
diff --git a/tests/test_issue1652_preflight_prequantized.py b/tests/test_issue1652_preflight_prequantized.py
index 0b14a613..42951439 100644
--- a/tests/test_issue1652_preflight_prequantized.py
+++ b/tests/test_issue1652_preflight_prequantized.py
@@ -163,31 +163,52 @@ def _fp8_checkpoint(path: Path) -> tuple[str, int]:
return str(path), params
[email protected](scope="module")
+def fp8_checkpoint(tmp_path_factory) -> tuple[str, int]:
+ """One checkpoint for both tests below: neither writes to it."""
+ return _fp8_checkpoint(tmp_path_factory.mktemp("fp8") / "base")
+
+
+def _skip_below_the_fp8_minimum() -> None:
+ """#1731: below this version transformers cannot load a dense base with an
+ FP8 config (its quantizer raises in ``update_tp_plan``), and Soup refuses
+ ``fp8`` when it builds the config."""
+ import transformers
+ from packaging.version import Version
+
+ from soup_cli.utils.quant_menu import FP8_MIN_TRANSFORMERS
+
+ if Version(transformers.__version__) < Version(FP8_MIN_TRANSFORMERS):
+ pytest.skip(f"quantization: fp8 needs transformers >= {FP8_MIN_TRANSFORMERS}")
+
+
class TestAnFp8BaseOnceLoaded:
"""The figure in the table is what a load through the real config holds."""
- def test_the_loader_s_config_dequantizes(self, tmp_path):
+ def test_the_loader_s_config_dequantizes(self, fp8_checkpoint):
import transformers
from soup_cli.utils.quant_menu import build_quantization_config_for_loader
- base, _ = _fp8_checkpoint(tmp_path / "base")
+ _skip_below_the_fp8_minimum()
+ base, _ = fp8_checkpoint
quant = build_quantization_config_for_loader(tcfg=_cfg("fp8").training, base=base)
assert isinstance(quant, transformers.FineGrainedFP8Config)
assert quant.dequantize is True
- def test_a_loaded_fp8_base_holds_the_bytes_per_parameter_the_table_charges(self, tmp_path):
+ def test_a_loaded_fp8_base_holds_the_bytes_per_parameter_the_table_charges(
+ self, fp8_checkpoint
+ ):
+ """Without a GPU transformers dequantizes an FP8 load whatever the flag
+ says, so on a CPU box this test alone cannot tell the flag's value; the
+ test above pins it."""
import torch
import transformers
- from packaging.version import Version
from soup_cli.utils.quant_menu import build_quantization_config_for_loader
- if Version(transformers.__version__) < Version("5.17.0"):
- # 5.16.1 raises AttributeError in the FP8 quantizer's update_tp_plan
- # for any model without MoE experts, before a weight is read.
- pytest.skip("transformers < 5.17.0 cannot load a dense model with an FP8 config")
- base, params = _fp8_checkpoint(tmp_path / "base")
+ _skip_below_the_fp8_minimum()
+ base, params = fp8_checkpoint
model = transformers.AutoModelForCausalLM.from_pretrained(
base,
torch_dtype="auto", # what Soup passes for a frozen base
diff --git a/tests/test_issue1731_fp8_needs_transformers_5_17.py b/tests/test_issue1731_fp8_needs_transformers_5_17.py
new file mode 100644
index 00000000..855da5ee
--- /dev/null
+++ b/tests/test_issue1731_fp8_needs_transformers_5_17.py
@@ -0,0 +1,183 @@
+"""#1731 — ``quantization: fp8`` is refused below transformers 5.17.0, with the reason.
+
+Soup declares ``transformers>=5.16.1``. On 5.16.1 the FP8 quantizer's
+``update_tp_plan`` reads ``FP8Experts._impl_tp_layer_overrides.get(impl)`` with
+no default, so a load of any base without MegaMoE experts raised
+``AttributeError: 'NoneType' object has no attribute 'get'`` from inside
+transformers; 5.17.0 added the ``{}`` default. ``build_quantization_config_for_loader``
+handed every ``fp8`` run that config, so the run died there. It now stops where
+the config is built, naming the installed version, the one it needs and why.
+
+The installed version is stubbed: nothing is loaded here. The failing load itself
+is in the issue, run on 5.16.1, 5.17.0 and 5.18.0.
+"""
+
+from __future__ import annotations
+
+import re
+import sys
+import types
+from pathlib import Path
+
+import pytest
+import yaml
+
+from soup_cli.config.loader import load_config_from_string
+from soup_cli.utils import quant_menu
+from soup_cli.utils.quant_menu import build_quantization_config_for_loader
+
+DOCS = Path(__file__).resolve().parent.parent / "docs" / "performance-and-quantization.md"
+
+
+def _tcfg(quantization: str):
+ raw = {
+ "base": "org/m", "task": "sft", "data": {"train": "./x.jsonl"},
+ "training": {"quantization": quantization},
+ }
+ return load_config_from_string(yaml.safe_dump(raw)).training
+
+
+def _installed(monkeypatch, version: str) -> None:
+ import transformers
+
+ monkeypatch.setattr(transformers, "__version__", version)
+
+
+def _build(quantization: str = "fp8"):
+ return build_quantization_config_for_loader(tcfg=_tcfg(quantization), base="org/m")
+
+
+def test_the_minimum_is_the_release_that_fixed_the_quantizer():
+ assert quant_menu.FP8_MIN_TRANSFORMERS == "5.17.0"
+
+
+class TestRefusedBelowTheMinimum:
+ def test_the_floor_gets_the_whole_message(self, monkeypatch):
+ _installed(monkeypatch, "5.16.1")
+
+ with pytest.raises(RuntimeError) as info:
+ _build()
+
+ assert str(info.value) == (
+ "quantization: fp8 needs transformers >= 5.17.0, and 5.16.1 is installed: "
+ "its FP8 quantizer raises AttributeError in update_tp_plan when it loads a "
+ "dense base (fixed in 5.17.0). Upgrade with "
+ "pip install -U 'transformers>=5.17.0', or pick another quantization."
+ )
+
+ @pytest.mark.parametrize(
+ "version", ["5.16.1", "5.16.2", "5.16.10", "5.9.0", "4.57.1", "5.17.0rc1", "5.17.0.dev0"]
+ )
+ def test_every_older_version_is_refused_by_name(self, monkeypatch, version):
+ """Compared as versions, not as text (5.9.0 and 5.16.10 are both older).
+ The two pre-releases are refused because they sort below 5.17.0; which
+ of them first carried the upstream fix was not checked."""
+ _installed(monkeypatch, version)
+
+ with pytest.raises(RuntimeError, match=re.escape(f"and {version} is installed")):
+ _build()
+
+ def test_nothing_is_printed_before_the_refusal(self, monkeypatch):
+ """The "dequantize-on-load" line would say the config was built."""
+ _installed(monkeypatch, "5.16.1")
+ printed = []
+ console = types.SimpleNamespace(print=printed.append)
+
+ with pytest.raises(RuntimeError):
+ build_quantization_config_for_loader(tcfg=_tcfg("fp8"), base="org/m", console=console)
+
+ assert printed == []
+
+
+class TestBuiltFromTheMinimumUp:
+ @pytest.mark.parametrize("version", ["5.17.0", "5.17.1", "5.18.0", "5.100.0", "6.0.0"])
+ def test_the_dequantizing_config_is_built(self, monkeypatch, version):
+ import transformers
+
+ fp8_config = transformers.FineGrainedFP8Config
+ _installed(monkeypatch, version)
+
+ config = _build()
+
+ assert isinstance(config, fp8_config)
+ assert config.dequantize is True
+
+ def test_the_installed_transformers_is_not_refused(self):
+ """No stub: the version this suite runs on is a supported one for fp8,
+ or the refusal is what it gets."""
+ import transformers
+ from packaging.version import Version
+
+ if Version(transformers.__version__) < Version("5.17.0"):
+ with pytest.raises(RuntimeError, match="needs transformers >= 5.17.0"):
+ _build()
+ else:
+ assert _build().dequantize is True
+
+
+class TestTheOtherModesOnTheFloor:
+ """The refusal is about fp8: on 5.16.1 every other mode builds what it built."""
+
+ def test_none_is_still_no_config(self, monkeypatch):
+ _installed(monkeypatch, "5.16.1")
+
+ assert _build("none") is None
+
+ @pytest.mark.parametrize(
+ ("quantization", "flag"), [("4bit", "load_in_4bit"), ("8bit", "load_in_8bit")]
+ )
+ def test_bitsandbytes(self, monkeypatch, quantization, flag):
+ _installed(monkeypatch, "5.16.1")
+
+ assert getattr(_build(quantization), flag) is True
+
+ def test_eetq(self, monkeypatch):
+ import transformers
+
+ _installed(monkeypatch, "5.16.1")
+
+ assert isinstance(_build("eetq"), transformers.EetqConfig)
+
+
[email protected]("quantization", ["gptq", "awq", "aqlm", "mxfp4"])
+def test_the_checkpoint_formats_never_reach_the_fp8_gate(monkeypatch, quantization):
+ """On 5.16.1 only fp8 is refused: the gate must not be called for another
+ mode. These four need a checkpoint to validate, so the class above cannot
+ build them; here the validation is stubbed and the gate is a tripwire."""
+ _installed(monkeypatch, "5.16.1")
+ for name in (
+ "validate_gptq_checkpoint", "validate_awq_checkpoint", "validate_mxfp4_checkpoint",
+ ):
+ monkeypatch.setattr(quant_menu, name, lambda base: None)
+
+ def _fail():
+ raise AssertionError("the fp8 gate ran for " + quantization)
+
+ monkeypatch.setattr(quant_menu, "_refuse_fp8_on_old_transformers", _fail)
+
+ assert _build(quantization) is not None
+
+
+def test_a_transformers_without_the_class_names_the_same_minimum(monkeypatch):
+ """The old message said ">= 4.45", which no supported install can be below."""
+ fake = types.ModuleType("transformers")
+ fake.__version__ = "5.17.0"
+ monkeypatch.setitem(sys.modules, "transformers", fake)
+
+ with pytest.raises(RuntimeError) as info:
+ _build()
+
+ message = str(info.value)
+ assert "does not expose an FP8 config" in message
+ assert "transformers >= 5.17.0" in message
+ assert "4.45" not in message
+
+
+def test_the_quant_menu_row_names_the_same_minimum():
+ rows = [
+ line for line in DOCS.read_text(encoding="utf-8").splitlines()
+ if line.startswith("| `fp8` |")
+ ]
+
+ assert len(rows) == 1
+ assert rows[0].rstrip().endswith(f"| transformers ≥ {quant_menu.FP8_MIN_TRANSFORMERS} |")