From 06ec3b34dca6d74c1658c7586b57028c723b245c Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Mon, 6 Jul 2026 10:31:01 +0000 Subject: [PATCH] diffusion speed: make the fp16-accum kill switch case-insensitive UNSLOTH_DISABLE_FP16_ACCUM is the documented safety escape hatch for fp16-accumulation numerical drift, but it was matched as .strip() in (1, true, yes) with no lowercasing, so UNSLOTH_DISABLE_FP16_ACCUM=TRUE (or YES / On) was silently ignored and fp16 accumulation stayed on. Lowercase before matching (the family-name check on the next line already does) and accept on. Existing 1/true/yes still match. --- studio/backend/core/inference/diffusion_speed.py | 2 +- studio/backend/tests/test_diffusion_speed.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/studio/backend/core/inference/diffusion_speed.py b/studio/backend/core/inference/diffusion_speed.py index 8c2524dfda..52ace4d30a 100644 --- a/studio/backend/core/inference/diffusion_speed.py +++ b/studio/backend/core/inference/diffusion_speed.py @@ -374,7 +374,7 @@ def _enable_fp16_accumulation( process-wide flag to its prior value on unload.""" import os - if os.environ.get("UNSLOTH_DISABLE_FP16_ACCUM", "").strip() in ("1", "true", "yes"): + if os.environ.get("UNSLOTH_DISABLE_FP16_ACCUM", "").strip().lower() in ("1", "true", "yes", "on"): return False name = str(getattr(family, "name", family or "")).lower() if name in _FP16_ACCUM_DENY: diff --git a/studio/backend/tests/test_diffusion_speed.py b/studio/backend/tests/test_diffusion_speed.py index 9a18090e36..e6ce77116e 100644 --- a/studio/backend/tests/test_diffusion_speed.py +++ b/studio/backend/tests/test_diffusion_speed.py @@ -427,6 +427,20 @@ def test_fp16_accum_respects_kill_switch(monkeypatch): assert applied["fp16_accum"] is False +@pytest.mark.parametrize("value", ["TRUE", "Yes", "On", " true "]) +def test_fp16_accum_kill_switch_is_case_insensitive(monkeypatch, value): + # The documented safety escape hatch must honor the common boolean spellings, not only + # lowercase "1"/"true"/"yes": an operator setting UNSLOTH_DISABLE_FP16_ACCUM=TRUE to stop + # fp16-accumulation drift would otherwise be silently ignored. + _stub_torch_fp16_accum(monkeypatch, consumer = True) + _stub_gguf_accel(monkeypatch) + monkeypatch.setenv("UNSLOTH_DISABLE_FP16_ACCUM", value) + applied = apply_speed_optims( + _Pipe(), _target(), is_gguf = True, family = _family(), speed_mode = "default" + ) + assert applied["fp16_accum"] is False + + def test_fp16_accum_respects_family_deny_list(monkeypatch): _stub_torch_fp16_accum(monkeypatch, consumer = True) _stub_gguf_accel(monkeypatch)