Skip to content

Commit c42de7f

Browse files
committed
[Quantization] Pin NVFP4 calibrator collect tests to reference path
After folding the Triton fast path into NVFP4MSECalibrator.collect(), two tests in tests/gpu/torch/quantization/test_nvfp4_static_quantizer_cuda.py broke because they inspect path-specific state: - test_collect_and_compute_amax asserts ``cal._losses_sum is not None`` with ``len == 126``. Only the reference 126-step sweep populates that list; the Triton fast path produces ``_best_amax_fast`` directly and leaves ``_losses_sum = None``. - test_multiple_collections asserts that two ``collect()`` calls accumulate. The Triton fast path is one-shot by design and refuses a second collect until ``reset()``, so multi-collect is fundamentally reference-path semantics. Fix: take the ``monkeypatch`` fixture in both tests and force ``MODELOPT_NVFP4_TRITON_SWEEP=0`` so they exercise the reference accumulator. Triton-path coverage stays in test_nvfp4_fp8_sweep_kernel.py (parity, dispatch predicate, end-to-end mtq.quantize). The other tests in the same class (initialization, candidate generation, per-block independence) are path-agnostic and unchanged. Signed-off-by: Chenjie Luo <chenjiel@nvidia.com>
1 parent 2bc8a54 commit c42de7f

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

tests/gpu/torch/quantization/test_nvfp4_static_quantizer_cuda.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,15 @@ def test_fp8_candidates_generation(self, device):
164164
assert torch.all(torch.isfinite(candidates))
165165
assert torch.all(candidates > 0)
166166

167-
def test_collect_and_compute_amax(self, device):
168-
"""Test collect and compute_amax workflow."""
167+
def test_collect_and_compute_amax(self, device, monkeypatch):
168+
"""Test reference-path collect and compute_amax workflow.
169+
170+
Pinned to the reference 126-step sweep (``MODELOPT_NVFP4_TRITON_SWEEP=0``)
171+
because this test inspects ``_losses_sum``, which only the reference path
172+
populates; the Triton fast path produces ``_best_amax_fast`` directly and
173+
is covered separately in ``test_nvfp4_fp8_sweep_kernel.py``.
174+
"""
175+
monkeypatch.setenv("MODELOPT_NVFP4_TRITON_SWEEP", "0")
169176
num_blocks = 8
170177
block_size = 16
171178
per_block_amax = torch.ones(num_blocks, device=device)
@@ -193,8 +200,14 @@ def quant_func(x, amax):
193200
assert torch.all(torch.isfinite(amax))
194201
assert torch.all(amax > 0)
195202

196-
def test_multiple_collections(self, device):
197-
"""Test that multiple collections accumulate correctly."""
203+
def test_multiple_collections(self, device, monkeypatch):
204+
"""Test that multiple collections accumulate correctly.
205+
206+
Multi-collect is reference-path-only — the Triton fast path is one-shot
207+
and refuses a second ``collect()`` until ``reset()``. Forcing the env var
208+
keeps this exercising the accumulator.
209+
"""
210+
monkeypatch.setenv("MODELOPT_NVFP4_TRITON_SWEEP", "0")
198211
num_blocks = 4
199212
block_size = 16
200213
per_block_amax = torch.ones(num_blocks, device=device)

0 commit comments

Comments
 (0)