Repository navigation
fix(cuda): add portable QQQ bias before output rounding - #3662
Merged
Merged
Conversation
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.
Summary
Add portable QQQ bias to the FP32 scaled accumulator before the output cast. The old path cast the accumulator to FP16/BF16 first, so a finite biased result could become
inf. This is a local numerical ordering change inQQQTorchLinear.forward; dispatch and persistent weight storage are unchanged.Before and after
qqq.py:722-727cast the FP32 scaled result to the activation dtype, then added biasThe mechanism and measurements are in CUDA quantized linear epilogue, already linked from the README. A flow diagram is unnecessary here because the change only reorders one numerical epilogue inside one function.
Validation
NVIDIA GB10 (SM 12.1), PyTorch 2.15.0+cu132:
inf; the corrected output is65024.PYTHON_GIL=1 pytest -q tests/test_qqq_cpu.py tests/test_qqq_jit.py tests/kernels/test_inference_numeric_range.py -k 'qqq and not native_qqq_small_activation_scale and not test_qqq_forward_uses_jit_kernel and not test_qqq_forward_raises_runtime_error_when_jit_ops_missing': 28 passed, 52 skipped. The skipped cases require native extensions or CPU instructions unavailable here. The three excluded native CUDA tests cannot build because CUDA_HOME is unset.ruff checkandgit diff --checkpassed.Full-module resident FP16 timing: five warmups, median of seven sets of 20 CUDA-event timed calls, 1024 input and output features. Peak is allocator delta including temporary weight and library scratch.
Native QQQ has a separate FP16 output contract and was outside this portable-path change.