Skip to content

test(cpu): pin the #4181 int4pack dispatch and dequantize contracts - #4428

Merged
Qubitium merged 1 commit into
mainfrom
fix/cpu-kernel-constraints
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/cpu-kernel-constraints

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Closes #4181 (coverage; the product fixes already landed).

Status of the four findings

I verified each against current main rather than re-landing anything:

# Finding Current state
1 TorchAtenLinear/TorchFusedLinear declared SUPPORTS_OUT_FEATURES_DIVISIBLE_BY=[1], so AUTO accepted odd widths and transform_cpu's zero_codes.reshape(self.scales.shape) failed Fixed — TorchAtenLinear declares [16] (the ATen CPU packer requires N % 16 == 0; N=8 raises expect N to be dividable by 16). TorchFusedLinear keeps [8] for XPU plus a CPU-only 16 check
2 group_size == in_features (512/512, 1024/1024) escaped validation and the aten op rejected it Fixed — AUTO no longer selects Aten/Fused for those shapes
3 dequantize_model built nn.Parameter(module.bias) with bias=None → shape-[0] bias, and hard-coded fp16 Fixed — bias is conditional and the dtype comes from the shared resolve_dequantize_dtype() (#4370)
4 AUTO on CPU must fall through to TorchLinear Fixed — pinned by the new tests

Landed by c9fb1ed (#4326) and 266a448 (#4370). The issue text's suggested [8] is looser than the real constraint; [16] is correct.

What this PR adds

tests/test_cpu_kernel_constraints_4181.py (CPU-only, 7 tests) so the class of bug cannot return:

  1. odd out_features (8 and 100) → per-module AUTO selection is TorchLinear, forward produces finite (2, N) output;
  2. group_size == in_features (512/512, 1024/1024) → per-module AUTO fallback never selects TorchAtenLinear/TorchFusedLinear;
  3. dequantize_model for all three kernels on a bias-less layer → bias is None, BF16 weight preserved (not hard-coded FP16), working forward.

Verification

  • New file → 7 passed.
  • With tests/kernels/test_selection.py, tests/test_cpu_int4pack_dispatch_contracts.py, tests/test_cpu_torch_avx512*.py → 168 passed, 123 skipped.
  • Pre-fix (2bc2f63, parent of c9fb1ed, with only the new test file copied in) → 6 failed, 1 passed: odd widths 8/100, gs==K 512/1024, and the Aten/Fused bias cases; TorchLinear passed because torch.py was already correct.
  • ruff check → clean.

Residual risk

  • Tests-only PR: there was no production code left to change for this issue.
  • The gs == in_features case builds the available CPU AUTO candidate set explicitly because the model-wide pass cannot know in_features; it exercises the real per-module fallback path.
  • Pre-fix evidence used 2bc2f63 (parent of the landed fix) rather than the issue's 6c3421c; the relevant declarations are identical.
  • No AVX512-capable host here; that case permits AVX512 as the fallback and only forbids Aten/Fused.

Add CPU-only regression coverage for the four #4181 failure modes: odd
out_features (8 and 100) must fall through AUTO to TorchLinear and forward,
group_size == in_features (512/512 and 1024/1024) must not select the Aten or
Fused CPU int4pack kernels, and dequantize_model must keep bias=None (not a
shape-[0] parameter) and preserve BF16 weights with a working forward for
TorchLinear, TorchAtenLinear, and TorchFusedLinear.

The production fixes are already on main (c9fb1ed for the dispatch contracts
and dequantize bias, 266a448/#4370 for the shared dequantize dtype helper);
this commit pins them with tests that fail at 2bc2f63. The ATen CPU packer
really requires N % 16 == 0, so the existing [16] declaration is kept rather
than the issue's suggested [8].
@Qubitium
Qubitium merged commit 810edf3 into main Nov 16, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/cpu-kernel-constraints branch November 16, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] AUTO on CPU selects TorchAtenLinear / TorchFusedLinear for shapes the int4pack op rejects; their dequantize_model breaks bias-less layers

1 participant