Repository navigation
fix(kernels): add bias to the FP32 accumulator for Machete/AWQ-Machete/QQQ (#5725) - #5952
Merged
Merged
Conversation
CodeQL flagged the module alias import and the symbol import of the same module. Keep the module aliases (the tests patch ``machete_mm`` on them) and reach the classes through the aliases.
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
Fixes #5725
QQQ and Machete (GPTQ and AWQ) compute in FP32 but narrow the accumulator to
the activation dtype in the epilogue, and both Python wrappers then added the
layer bias to that narrowed tensor. A pre-bias partial sum above 65504 became
infeven when the biased result is finite, and every other row was roundedtwice. The contract is now: add the bias once to the complete reduction, then
round once.
What Changed
gptqmodel_ext/qqq/qqq_gemm.{cu,h},qqq.cpp)Marlintakes a trailingconst float* bias(nullptr = no bias).write_resultstages the FP32 dequantized values in theexisting shared reorder buffer (2x the fp16 layout, aliasing the A-stage
scratch after a
__syncthreads), then the final write loop adds theper-column bias and performs the only
float2_to_half2cast.global_reduceaccumulates INT32 partials exactlyand
write_resultruns once, after the reduce, only for the last block.qqq_cuda(..., const void* bias, ...); hostqqq_gemm(...)gains atrailing
std::optional<torch::Tensor>and validates FP32 / numel ==prob_n/ contiguous.qqq_gemm(..., int max_par=8, Tensor? bias=None) -> ().gptqmodel/utils/qqq.py,gptqmodel/nn_modules/qlinear/qqq.py)qqq_gemm/mulgain a trailingbias=None.QQQLinear.forwardpassesself._kernel_bias(A.device); the old post-hoc(D.float() + bias).to(dtype)block is removed._kernel_biasreturns an FP32, 1-D, contiguous launch operand; thecheckpoint
self.biaskeeps its stored dtype and order.gptqmodel_ext/machete/generate.py)TypeConfigloops emit bothout=a(unchanged 16-bit image)and
out=DataType.f32. Generated: dispatch entries 8 -> 16 (8 f32-out),kernel impls 72 -> 144 (72 f32-out).
machete.py,machete_awq.py)out_type, no copy).out_type=torch.float32, then compute(out + bias.float()).to(activation_dtype): one rounding after the biasjoins the complete reduction.
tests/kernels/test_qqq_machete_wide_bias_5725.py(10 tests): 4 GPUQQQ tests driving the real
QQQLinear.forward, 6 CPU Machete tests pinningthe launch contract for GPTQ and AWQ in fp16/bf16.
biasargument.Out of scope: no checkpoint layout change, no new kernel schedules, no change
to the bias-free fast path.
Tests
Red on base
5a155e1f7(identical test file, pristine checkout of that commit):git checkout 5a155e1f7 python -m pytest tests/kernels/test_qqq_machete_wide_bias_5725.py -q # 7 failed, 3 passedtest_qqq_bias_joins_the_fp32_accumulator_before_the_output_cast: 1024/1024non-finite (
inf) before.test_qqq_bias_is_not_double_rounded_through_the_activation_dtype:1.0before,
1.0009765625after.test_qqq_kernel_bias_operand_is_fp32_and_contiguous:AttributeError(
_kernel_biasabsent on base).out_typecases:KeyError: 'out_type'(the bias path neverrequested the fp32 image).
Measured Impact
GPU: 8x A100-class (sm_80), torch 2.15.0+cu132, CUDA 13.3, QQQ JIT kernel.
inf(1024/1024 non-finite)51680.0(0/1024 non-finite)1.01.0009765625Machete native accuracy is not measured here: the generated kernels are
SM90a-only and this host is sm_80. The generated FP32-out variants compile for
sm_90a (above), and the Python launch contract is covered on CPU; native SM90
accuracy remains unverified in this PR.
Performance: the bias-free path is unchanged (same call, same image dtype, no
extra copy). A biased layer now pays one FP32 epilogue image plus one
add+cast. A quick 4096x4096 (rows=64) bench was too noisy to publish; no
performance claim is made.
Model Support / Module Plan
Not applicable: no model definitions, aliases, or
MODEL_MAPentries change.Logic Flow Documentation
Not applicable: no control-flow or resolution mechanism changes; the bias now
joins an existing reduction before its existing cast.
Review Requirements
Kernel Accuracy Requirements
independent Torch FP32 oracle, or the reason it is not applicable is
documented (Machete native: SM90a-only, unverified here).
dependencies, architecture restrictions and unqualified formats; skips
are not validation.
Notes
execution. A sm_90a runner should confirm the fp32 epilogue path end-to-end
before relying on it.
self.biaskeeps its stored dtype.layers allocate nothing extra.