Skip to content

fix(compile): make the int4pack cast path a traceable custom op (#5110) - #5139

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-5110-compile-levels
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-5110-compile-levels

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #5110. The int4pack CPU kernels declared INDUCTOR but 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. GGUFTorchLinear also over-claimed its CUDA level.

What Changed

  • torch_fused: the casting int4pack product is now gptqmodel::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_cast stays as a thin compatibility wrapper for callers that resolved the old name.
  • gguf: base SUPPORTS_COMPILE_LEVEL back to EAGER (the measured CUDA ceiling, as its own comment documents) with SUPPORTS_COMPILE_LEVEL_BY_DEVICE = {"cpu": INDUCTOR}.
  • tests/kernels/compile_probe.skip_without_measurable_device: only CUDAGRAPH and a capture claim need a CUDA device. INDUCTOR lowers on CPU, so a CPU-built case now runs on a CPU-only runner instead of turning into a skip. New device_type argument reads the per-device declaration.
  • tests/kernels/test_kernel_compile_levels_awq.py: Case records 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): ParoLinear still declares CPU INDUCTOR while its CPU forward does not trace on this host — that was already red before this change and is a separate issue.

Tests

# three tests red since #5070, now green
python -m pytest tests/kernels/test_kernel_compile_levels_quant.py tests/kernels/test_kernel_compile_levels_awq.py -q
# 19 passed, 19 skipped

python -m pytest tests/kernels/test_kernel_compile_levels_cpu.py -q -k int4pack_cpu_kernel
# 16 passed

python -m pytest tests/kernels/test_kernel_compile_protocol.py -q
# 63 passed, 153 skipped

python -m pytest tests/test_cpu_int4pack_dispatch_contracts.py tests/test_awq_torch_fused_mode_5018.py \
  tests/test_torch_fused_asym_qzeros.py tests/test_q4_torch_fused.py \
  tests/kernels/test_paro_cpu_lock_concurrency_4885.py -q
# 33 passed, 4 skipped

python -m pytest tests/kernels/test_compile_policy_levels_4984.py -q
# 2 passed, 1 skipped

ruff check gptqmodel tests/kernels
# All checks passed

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 unmodified origin/main on this host (verified against a detached worktree) and are unrelated to this change. The default-device GGUFTorchLinear level was measured on CUDA; the CPU override was measured here.

Kernel Accuracy Requirements

  • Accuracy/identity checked: _cpu_int4pack_mm output is torch.equal to the pre-change helper for GPTQ/AWQ x fp16/bf16 x biased/bias-free (dtype included: FP32 product for biased, input dtype otherwise).
  • No dense/expanded weight cache added; only the same packed buffers plus the transient cast inside the custom op.
  • Skips are reported, not counted as validation (19 skipped above are unavailable runtimes/host architectures).

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.
@Qubitium
Qubitium marked this pull request as ready for review November 18, 2026 06:00
@Qubitium
Qubitium merged commit 9ad11a8 into main Nov 18, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/issue-5110-compile-levels branch November 18, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant