Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions auto_round_extension/ark/test/test_moe_prefill_accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,23 @@ def _reference_moe_prefill(activations, dequant_weights_NK, num_tokens_per_exper


def _tol_for_dtype(base, dtype):
"""Return tolerances loosened for bf16 accumulator noise at large K.

bf16 has 7 mantissa bits vs fp16's 10, so K-reductions of ~14K elements
(the ``medium E=8`` prefill shape uses K=14336) can produce a handful of
outliers per ~2M outputs that exceed the fp16-calibrated ``7e-2`` bound
by up to ~1.3x (observed: max abs diff ~0.090). This shows up
stochastically across seeds on every quantized path -- int8-sym / fp8 /
DPAS mainloops most consistently, but int4/int2 as well when a rare
outlier lands past the bound -- so we widen for all quant callers on
bf16 and leave fp16 (which absorbs the noise in its wider mantissa) at
the tight bound.
"""Return tolerances loosened for accumulator noise at large K.

Long K-reductions (the ``medium E=8`` prefill shape uses K=14336) can
produce a handful of outliers per ~2M outputs that exceed the tight
fp16-calibrated bounds by up to ~1.3x (observed: max abs diff ~0.090).
Because the XPU kernel does not guarantee a deterministic reduction
order, these outliers appear stochastically from run to run even with a
pinned RNG seed, so a fixed seed alone cannot make the assertion robust.

This shows up on every quantized path -- int8-sym / fp8 / DPAS mainloops
most consistently, but int4/int2 as well (notably int4-sym + fp16, which
intermittently crossed the tight bound). We therefore apply a ``1e-1``
tolerance floor for both fp16 and bf16 quant callers. The reference and
kernel share the same dequantized weights, so this floor still catches
real matmul/dequant bugs while absorbing accumulator-order noise.
"""
if dtype is torch.bfloat16:
if dtype in (torch.bfloat16, torch.float16):
return dict(rtol=max(base["rtol"], 1e-1), atol=max(base["atol"], 1e-1))
return base

Expand Down
Loading