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.

Studio: make the fp8 smoke probe catch a missing activation scale floor (#8008)

Daniel Han1d321595fbf4
diff --git a/studio/backend/core/inference/diffusion_transformer_quant.py b/studio/backend/core/inference/diffusion_transformer_quant.py
index 73e06a02efc..7672fae415a 100644
--- a/studio/backend/core/inference/diffusion_transformer_quant.py
+++ b/studio/backend/core/inference/diffusion_transformer_quant.py
@@ -266,9 +266,22 @@ def _scheme_supported(scheme: str, device: str) -> bool:
def _smoke_probe(scheme: str, device: str) -> bool:
- """True iff a tiny Linear quantised with ``scheme`` runs one M=32 forward. Cached per
- (scheme, device). Makes ``auto`` robust to a build lacking a prototype kernel: it fails
- here and the ladder moves on, rather than crashing at the first real denoise step."""
+ """True iff a tiny Linear quantised with ``scheme`` runs one M=32 forward and returns
+ finite values. Cached per (scheme, device). Makes ``auto`` robust to a build lacking a
+ prototype kernel: it fails here and the ladder moves on, rather than crashing at the first
+ real denoise step.
+
+ Half the input is all-zero rows and the output is checked for finiteness, because a kernel
+ that runs is not the same as one that is usable. torchao's ``_choose_scale_float8`` has no
+ eps clamp, so a zero row yields scale 0 and NaN qdata; that is the root cause behind
+ qwen-image's fp8 black frames (its txt stream emits all-zero token rows through a set of
+ ``txt_mlp.net.2`` linears that changes run to run, which is why keeping a fixed subset bf16
+ does not fix it). ``_make_quant_config`` floors it with ``activation_value_lb``, but only
+ when the installed torchao exposes that kwarg, and without a zero row the probe passed on a
+ build lacking it. Zero rows are not exotic: every Wan pipeline pads prompt embeddings with
+ ``new_zeros`` out to 226 or 512, so the tail rows reaching the DiT are exactly zero.
+ Measured on B200, 4096-wide Linear: 412 of 512 rows non-finite without the floor, 0 of 512
+ with it. Failing here costs one ladder step down to int8 instead."""
key = (scheme, device)
if key in _SMOKE_CACHE:
return _SMOKE_CACHE[key]
@@ -279,11 +292,13 @@ def _smoke_probe(scheme: str, device: str) -> bool:
lin = torch.nn.Linear(512, 512, bias = False).to(device = device, dtype = torch.bfloat16)
quantize_(lin, _make_quant_config(scheme), filter_fn = make_filter_fn(0))
+ # M stays 32 (scaled_mm wants 16-aligned dims); the zero rows go inside it, not after it.
x = torch.randn(32, 512, device = device, dtype = torch.bfloat16)
+ x[16:] = 0
with torch.no_grad():
- lin(x)
+ out = lin(x)
torch.cuda.synchronize()
- ok = True
+ ok = bool(torch.isfinite(out).all().item())
except Exception:
ok = False
_SMOKE_CACHE[key] = ok
diff --git a/studio/backend/tests/test_diffusion_transformer_quant.py b/studio/backend/tests/test_diffusion_transformer_quant.py
index 3210c92f80b..84979e8cd99 100644
--- a/studio/backend/tests/test_diffusion_transformer_quant.py
+++ b/studio/backend/tests/test_diffusion_transformer_quant.py
@@ -193,9 +193,31 @@ def test_scheme_supported_shortcircuits(monkeypatch):
assert tq._scheme_supported(TQ_FP8, "cuda") is False
+class _FakeTensor:
+ """Records the probe's zero-row write so the assertion below can check it happened."""
+
+ def __init__(self):
+ self.zeroed = []
+
+ def __setitem__(self, key, value):
+ self.zeroed.append((key, value))
+
+
+class _FakeBool:
+ def __init__(self, value):
+ self.value = value
+
+ def all(self):
+ return self
+
+ def item(self):
+ return self.value
+
+
def test_smoke_probe_caches_and_tolerates_failure(monkeypatch):
tq._SMOKE_CACHE.clear()
calls = {"n": 0}
+ finite = {"ok": True}
class _Lin:
def __init__(self, *a, **k):
@@ -207,7 +229,8 @@ def test_smoke_probe_caches_and_tolerates_failure(monkeypatch):
torch = types.ModuleType("torch")
torch.bfloat16 = "bfloat16"
torch.nn = types.SimpleNamespace(Linear = _Lin)
- torch.randn = lambda *a, **k: object()
+ torch.randn = lambda *a, **k: _FakeTensor()
+ torch.isfinite = lambda t: _FakeBool(finite["ok"])
torch.no_grad = lambda: __import__("contextlib").nullcontext()
torch.cuda = types.SimpleNamespace(is_available = lambda: True, synchronize = lambda: None)
monkeypatch.setitem(sys.modules, "torch", torch)
@@ -245,6 +268,54 @@ def test_smoke_probe_caches_and_tolerates_failure(monkeypatch):
tqz.quantize_ = _quantize_boom
assert tq._smoke_probe(TQ_FP8, "cuda") is False
+ # A kernel that RUNS but returns non-finite values probes False too. torchao's fp8 scale
+ # chooser has no eps clamp, so a zero activation row gives scale 0 and NaN qdata unless the
+ # config floors it, and the floor is applied only on a torchao exposing activation_value_lb.
+ # Without this the probe passed on such a build and every zero-padded text stream went black.
+ # int8, not fp8: _make_quant_config(fp8) imports PerRow, which this stub module does not
+ # carry, so an fp8 probe here would return False from the ImportError and prove nothing.
+ tq._SMOKE_CACHE.clear()
+ tqz.quantize_ = _quantize_ok
+ finite["ok"] = False
+ assert tq._smoke_probe(TQ_INT8, "cuda") is False
+
+
+def test_the_smoke_probe_feeds_zero_rows_not_only_noise(monkeypatch):
+ # The finiteness check above is only meaningful if the input actually contains a zero row:
+ # torch.randn alone never produces one, which is exactly how the silent degradation survived.
+ tq._SMOKE_CACHE.clear()
+ seen = {}
+
+ class _Lin:
+ def __init__(self, *a, **k):
+ pass
+
+ def to(self, **k):
+ return self
+
+ def __call__(self, x):
+ seen["x"] = x
+ return x
+
+ torch = types.ModuleType("torch")
+ torch.bfloat16 = "bfloat16"
+ torch.nn = types.SimpleNamespace(Linear = _Lin)
+ torch.randn = lambda *a, **k: _FakeTensor()
+ torch.isfinite = lambda t: _FakeBool(True)
+ torch.no_grad = lambda: __import__("contextlib").nullcontext()
+ torch.cuda = types.SimpleNamespace(is_available = lambda: True, synchronize = lambda: None)
+ monkeypatch.setitem(sys.modules, "torch", torch)
+
+ tqz = types.ModuleType("torchao.quantization")
+ tqz.quantize_ = lambda module, config, filter_fn = None: None
+ tqz.Int8DynamicActivationInt8WeightConfig = lambda: "int8cfg"
+ tqz.Float8DynamicActivationFloat8WeightConfig = lambda: "fp8cfg"
+ monkeypatch.setitem(sys.modules, "torchao.quantization", tqz)
+
+ assert tq._smoke_probe(TQ_INT8, "cuda") is True
+ assert seen["x"].zeroed, "probe input was never zeroed anywhere"
+ assert all(value == 0 for _, value in seen["x"].zeroed)
+
# ── consumer-vs-datacenter detection (fp8 fast-accumulate gate) ──────────────────