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.

test(torchao): keep FP8 gate stubs package-safe (#1284)

yi1118bb270ad0a6b
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 84eeab24..076a68ea 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -201,6 +201,7 @@ jobs:
run: |
pytest -o addopts= -q \
tests/test_issue826_torchao_class_names.py \
+ tests/test_issue835_fp8_gate.py \
tests/test_v07121.py
pytorch-smoke:
# #596: exercise the real PyTorch SFT + DPO training pipeline on every PR.
diff --git a/tests/test_issue835_fp8_gate.py b/tests/test_issue835_fp8_gate.py
index 0d519eba..d290820f 100644
--- a/tests/test_issue835_fp8_gate.py
+++ b/tests/test_issue835_fp8_gate.py
@@ -41,30 +41,48 @@ def converts(monkeypatch):
"""Stub torchao.float8; returns the list of recorded conversions."""
calls: list[str] = []
- float8 = ModuleType("torchao.float8")
-
def _convert(model, config=None, module_filter_fn=None):
calls.append(config)
+ package_names = {
+ "torchao",
+ "torchao.float8",
+ "torchao.prototype",
+ "torchao.prototype.safetensors",
+ }
+ module_names = package_names | {
+ "torchao.float8.config",
+ "torchao.prototype.safetensors.safetensors_support",
+ }
+ modules = {name: ModuleType(name) for name in module_names}
+ for name, module in modules.items():
+ is_package = name in package_names
+ if is_package:
+ module.__path__ = []
+ module.__spec__ = importlib.machinery.ModuleSpec(name, None, is_package=is_package)
+
+ float8 = modules["torchao.float8"]
float8.convert_to_float8_training = _convert
-
- config_mod = ModuleType("torchao.float8.config")
+ float8.config = modules["torchao.float8.config"]
class Float8LinearConfig:
@staticmethod
def from_recipe_name(name):
return name
- config_mod.Float8LinearConfig = Float8LinearConfig
+ float8.config.Float8LinearConfig = Float8LinearConfig
+
+ prototype = modules["torchao.prototype"]
+ safetensors = modules["torchao.prototype.safetensors"]
+ safetensors_support = modules["torchao.prototype.safetensors.safetensors_support"]
+ safetensors_support.flatten_tensor_state_dict = lambda *args, **kwargs: None
+ safetensors.safetensors_support = safetensors_support
+ prototype.safetensors = safetensors
+ modules["torchao"].prototype = prototype
+ modules["torchao"].float8 = float8
- torchao = ModuleType("torchao")
- # A spec, because setup code asks importlib.util.find_spec("torchao"), which
- # raises on a module whose __spec__ is None.
- for module in (torchao, float8, config_mod):
- module.__spec__ = importlib.machinery.ModuleSpec(module.__name__, None)
- monkeypatch.setitem(sys.modules, "torchao", torchao)
- monkeypatch.setitem(sys.modules, "torchao.float8", float8)
- monkeypatch.setitem(sys.modules, "torchao.float8.config", config_mod)
+ for name, module in modules.items():
+ monkeypatch.setitem(sys.modules, name, module)
return calls
@@ -332,6 +350,8 @@ class TestQuantizationAwareFp8:
_card(monkeypatch, (9, 0))
monkeypatch.setattr("soup_cli.utils.fp8.is_fp8_available", lambda: True)
+ for name in [n for n in sys.modules if n == "torchao" or n.startswith("torchao.")]:
+ monkeypatch.delitem(sys.modules, name, raising=False)
monkeypatch.setitem(sys.modules, "torchao", None)
with pytest.raises(FP8DependencyMissingError):
apply_fp8_training(_Attn())
@@ -885,6 +905,8 @@ class TestTheTorchaoProbeItself:
def test_no_torchao_at_all_is_not_available(self, monkeypatch):
from soup_cli.utils.fp8 import is_torchao_float8_available
+ for name in [n for n in sys.modules if n == "torchao" or n.startswith("torchao.")]:
+ monkeypatch.delitem(sys.modules, name, raising=False)
monkeypatch.setitem(sys.modules, "torchao", None)
assert is_torchao_float8_available() is False