Repository navigation
fix(compile): make the int4pack cast path a traceable custom op (#5110) - #5139
Merged
Merged
Conversation
The casting int4pack product ran through a `torch.compiler.disable`d Python helper, so dynamo broke on every BF16 or biased FP16 CPU layer while TorchFusedLinear/TorchAtenLinear and the two AWQ variants declared INDUCTOR. BF16 is the CPU AUTO dtype for those kernels, so the default configuration never reached the declared level. - torch_fused: the casting product is now `gptqmodel::int4pack_mm_cast`, a custom op with a FakeTensor impl. Same eager math (cast operands, call `_weight_int4pack_mm_for_cpu`, cast result), but the casts live inside the op, so #4068 no longer forces a graph break. All four int4pack kernels now trace with 0 graph breaks for fp16/bf16 x biased/bias-free, at identical output bytes. - gguf: restore base EAGER (the measured CUDA ceiling, as its own comment documents) and keep CPU at INDUCTOR via SUPPORTS_COMPILE_LEVEL_BY_DEVICE. - tests/kernels/compile_probe.skip_without_measurable_device: only CUDAGRAPH and a capture claim need a CUDA device; INDUCTOR lowers on CPU, so CPU-built cases now run on CPU-only runners. `device_type` selects the per-device declaration. - tests: the AWQ level test passes its build device, and the CPU level test parametrizes the int4pack kernels over the full dtype/bias matrix (the fetch of #5110) instead of only fp16 bias-free. - docs/kernel-compile-matrix.md: regenerated. Verified on GB10 (sm_121, aarch64, torch 2.11.0+cu130): - tests/kernels/test_kernel_compile_levels_quant.py + _awq.py: 19 passed, 19 skipped (the three tests red since #5070 now pass). - tests/kernels/test_kernel_compile_levels_cpu.py -k "int4pack": 16 passed. - tests/kernels/test_kernel_compile_protocol.py: 63 passed. - torch-fused/ATen/AWQ oracle byte-identity vs the previous helper, and the Paro/ATen concurrency, asym-qzeros and dispatch-contract suites stay green.
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 #5110. The int4pack CPU kernels declared
INDUCTORbut only reached it for an fp16, bias-free layer: BF16 (their CPU AUTO dtype) and every biased layer paid a graph break per quantized linear.GGUFTorchLinearalso over-claimed its CUDA level.What Changed
torch_fused: the casting int4pack product is nowgptqmodel::int4pack_mm_cast, a custom op with a FakeTensor implementation. Eager math is unchanged (cast the operands, call_weight_int4pack_mm_for_cpu, cast the result); the casts now live inside the op, so inductor never has to lower the extern GEMM on a separate Pointwise layout ([BUG] Follow-up on #4060/#4062: model.optimize() TypeError on all CPU AUTO kernels, torch.compile int4pack LoweringException for fp16+bias (regression) and bf16, max_memory still ignored with device="cuda:0" #4068)._cpu_int4pack_mm_caststays as a thin compatibility wrapper for callers that resolved the old name.gguf: baseSUPPORTS_COMPILE_LEVELback toEAGER(the measured CUDA ceiling, as its own comment documents) withSUPPORTS_COMPILE_LEVEL_BY_DEVICE = {"cpu": INDUCTOR}.tests/kernels/compile_probe.skip_without_measurable_device: onlyCUDAGRAPHand a capture claim need a CUDA device.INDUCTORlowers on CPU, so a CPU-built case now runs on a CPU-only runner instead of turning into a skip. Newdevice_typeargument reads the per-device declaration.tests/kernels/test_kernel_compile_levels_awq.py:Caserecords the build device and the skip/declared level use it.tests/kernels/test_kernel_compile_levels_cpu.py: new parametrized test over the full int4pack matrix (GPTQ/AWQ x fp16/bf16 x biased/bias-free) — the coverage gap in the issue.docs/kernel-compile-matrix.md: regenerated.No API or behavior change to the math: the casting product returns byte-identical output to the previous helper in every dtype/bias case. Follow-up (out of scope):
ParoLinearstill declares CPUINDUCTORwhile its CPU forward does not trace on this host — that was already red before this change and is a separate issue.Tests
Host: one NVIDIA GB10 (sm_121, aarch64), torch 2.11.0+cu130, transformers 5.17.0. The remaining failures in
test_kernel_compile_levels_cpu.py(NF12, QQQ cold-trace, embeddings, Paro) are identical on unmodifiedorigin/mainon this host (verified against a detached worktree) and are unrelated to this change. The default-deviceGGUFTorchLinearlevel was measured on CUDA; the CPU override was measured here.Kernel Accuracy Requirements
_cpu_int4pack_mmoutput istorch.equalto the pre-change helper for GPTQ/AWQ x fp16/bf16 x biased/bias-free (dtype included: FP32 product for biased, input dtype otherwise).