Repository navigation
perf(awq): drop redundant entry NaN scan - #3402
Merged
Merged
Conversation
9 tasks done
Qubitium
added a commit
that referenced
this pull request
Dec 1, 2026
…6633) `test_awq_pseudo_quantize_nan_guard_uses_one_host_read` (#3402) has been red whenever it runs without an earlier symmetric pseudo-quantize call in the same process, for example alone, with -k, or next to an unrelated test. It counted 4 scalar reads instead of 1. Cause: #6002 added `_awq_symmetric_scale_limit`, an lru_cached helper that steps the per-dtype limit down with `bool(torch.isfinite(...))` and returns `float(limit)`. That is three `_local_scalar_dense` reads, but only on the first call per `(decode_dtype, factor)` in a process. So the "one host read per pseudo-quantize" contract held or failed depending on whether an earlier test had already warmed this process-global cache. In the full file it passed, which is why the failure looked flaky. The reads are on CPU constants, so no GPU stream sync and no measurable runtime cost; the defect is that the contract depended on cache state, against #6002's own "no host read" claim. Fix at the cache owner: compute the limit branch-free (two `torch.where` step-down rounds in place of the `bool()` loop) and cache the 0-d CPU tensor instead of a Python float. Build it with inference mode disabled, so the cached tensor is not an inference tensor for later autograd-enabled callers. The value is unchanged: every decode dtype (fp16/bf16/fp32) x factor 1..255 gives the same limit, and `torch.where` against fp16/bf16/fp32 scales is bit-identical on CPU and CUDA. A tiny Granite hybrid sym AWQ quantize saves bit-identical tensors before and after in bf16 and fp16. The regression now clears the cache before counting and counts a cold and a warm call, so it no longer depends on test order. Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pseudo_quantize_tensorscanned the full weight tensor for NaN on entry, then scanned both scales and dequantized weights on exit. The exit guard already catches NaN inw(and infinities propagate to NaN through the scale arithmetic), so the entry reduction is redundant.Validation on AMD Instinct MI355X (gfx950, Torch 2.13.0+rocm10.0.0):
tests/test_awq_weight_mean.pyNaN-guard tests: 2 passed; the host-read test now asserts exactly one scalar read.tests/test_awq_clip_consistency.py: 4 passed.