Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

tests: restore transformers' Fp8Dequantize after the fp8 save policy tests (#14741)

Daniel Han0811e559d968
diff --git a/tests/test_fp8_dequant_save_policy.py b/tests/test_fp8_dequant_save_policy.py
index edc8c3fc6f4..6ffa659f1ad 100644
--- a/tests/test_fp8_dequant_save_policy.py
+++ b/tests/test_fp8_dequant_save_policy.py
@@ -22,6 +22,22 @@ ROOT = Path(__file__).resolve().parents[1]
BLOCK = 8
[email protected](autouse = True)
+def _restore_fp8_integration(monkeypatch):
+ # A real fp8 load patches Fp8Dequantize process-wide; later test files check the unpatched class.
+ try:
+ import transformers.integrations.finegrained_fp8 as fp8_integration
+ except Exception:
+ return
+ cls = getattr(fp8_integration, "Fp8Dequantize", None)
+ if cls is not None:
+ for name, value in list(vars(cls).items()):
+ if not name.startswith("__"):
+ monkeypatch.setattr(cls, name, value)
+ if hasattr(fp8_integration, "replace_with_fp8_linear"):
+ monkeypatch.setattr(fp8_integration, "replace_with_fp8_linear", fp8_integration.replace_with_fp8_linear)
+
+
def _helper():
# Exact source, without importing unsloth (which needs an accelerator).
path = ROOT / "unsloth" / "models" / "loader_utils.py"