Skip to content

fix(awq): portable CPU GEMV reader so quantize() completes in session (#4554) - #4599

Merged
Qubitium merged 1 commit into
mainfrom
fix/awq-gemv-insession-4554
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/awq-gemv-insession-4554

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #4554. After the #4426 rehome, QuantizeConfig(method="awq", format="gemv") always raised at the end of quantize() because no in-session kernel could run the packed GEMV layout on CPU — calibration was lost and the documented quantize→save flow crashed.

  • New AwqGEMVTorchLinear: portable CPU reader of the same packed GEMV qweight/qzeros/scales (FP32 dequant + wide matmul), priority 0, SUPPORTS_DEVICES=[CPU], marked PORTABLE_CPU_FALLBACK.
  • awq_gemv_pack_backend(device_type=...) resolves a CPU pack target to BACKEND.AWQ_TORCH; the default stays "cuda" so existing keyword callers are unaffected.
  • AUTO failure path in the importer validates/returns the declared portable fallback when no AUTO-eligible kernel exists for a CPU-only target (used by load, pack validation and rehome).
  • The remaining no-kernel error now tells the user to save and reload the checkpoint.

Validation

Reproduced both failures on CPU before the fix (pack-time does not support device: DEVICE.CPU, and the rehome No valid quant linear / cannot run on the final device cpu).

After:

QUANTIZE OK kernel: AwqGEMVTorchLinear
FORWARD OK logits: (1, 4, 64) finite: True
SAVED format: gemv
RELOAD kernel: AwqGEMVTorchLinear (AUTO and explicit BACKEND.AWQ_TORCH)
  • New tests/test_awq_gemv_insession_4554.py → 4 passed (CPU selection, rehome class switch, cross-layout numerics, full quantize→save→reload)
  • Targeted AWQ/rehome suite → 54 passed, 33 skipped (ROCm-only)
  • Selection/registry suite → 171 passed, 51 skipped
  • ruff check gptqmodel docs/eora tests setup.py clean

Residual: the CPU reader materializes an FP32 [K,N] weight per forward (correct but slow); GEMV_FAST/LLM_AWQ still have no CPU reader (out of scope); fallback selection is scoped to CPU-only targets.

Resolves #4554.

quantize(format=GEMV) packs every layer and leaves it on CPU, but no kernel
could read the GEMV layout there: the native class is CUDA-only and the Triton
reader needs an accelerator. rehome_quantized_kernel() therefore raised after
the whole calibration, losing the result and breaking the documented
quantize -> save flow (issue #4554).

Add AwqGEMVTorchLinear, a portable CPU reader of the same packed
qweight/qzeros/scales buffers. It is explicit-only (SUPPORTS_FORMATS priority
0) so accelerator AUTO order is unchanged, and select_quant_linear() reaches it
for a CPU-only target through PORTABLE_CPU_FALLBACK. awq_gemv_pack_backend()
now resolves device_type=cpu to BACKEND.AWQ_TORCH, so CPU quantization packs
and runs with it. The saved checkpoint keeps the requested GEMV format and
AUTO reload works on CPU.

Also clarify the remaining no-kernel error: save the model before reloading
the checkpoint.
@Qubitium
Qubitium merged commit fd8d524 into main Nov 17, 2026
9 checks passed
@Qubitium
Qubitium deleted the fix/awq-gemv-insession-4554 branch November 17, 2026 02:12
Qubitium added a commit that referenced this pull request Nov 17, 2026
…4736) (#4753)

* fix(awq): give FORMAT.GEMV_FAST and LLM_AWQ a CPU in-session reader (#4736)

quantize(format=GEMV_FAST / LLM_AWQ) packs every layer and leaves it on CPU,
but the only kernels for that interleaved layout are CUDA-only.
rehome_quantized_kernel() therefore raised "No valid quant linear" ->
RuntimeError after the whole calibration, before save() could run. #4599
fixed only FORMAT.GEMV.

Add AwqGEMVFastTorchLinear and LLMAwqTorchLinear, portable CPU readers of the
same packed INT16 qweight and FP16 scales/offset buffers. They reuse the
existing _dequantize_awq_gemv_fast layout inverse as a bounded per-forward
temporary. They are explicit-only (SUPPORTS_FORMATS priority 0), so the
accelerator AUTO order does not change, and select_quant_linear() reaches them
for a CPU target through PORTABLE_CPU_FALLBACK. LLMAwqTorchLinear stays an
LLMAwqLinear so layout-keyed consumers keep routing it as LLM_AWQ. A CPU-only
quantize host now packs these formats with BACKEND.AWQ_TORCH instead of
refusing before calibration.

The saved checkpoint keeps the requested format and its interleaved packing,
and AUTO reload on CPU selects the same reader.

* test(rocm): cover AwqGEMVTorchLinear in the audit inventory

The rebase onto main brings the new `AwqGEMVTorchLinear` CPU reader, which
main registers in `KERNELS`. This PR already owns the `OTHER_KERNELS`
inventory, so add it there; without it
`test_audit_covers_every_registered_kernel` reports the kernel as
unclassified (it fails the same way on unmodified main).

---------

Co-authored-by: Qubitium <[email protected]>
Qubitium added a commit that referenced this pull request Nov 17, 2026
Fix the test-side fallout of #4716, #4657, #4627 and #4508. Only entries
that fail on this sm_80 host (PG506) and whose stated reasoning reproduces
were changed; the rest are recorded with their outcome.

1. 8587f0b (#4716, native FP8 GEMM for a wide bias)
   - tests/kernels/test_fp8_kernel.py::test_fp8_default_forward_is_w8a16
     REPRODUCED on sm_80: 6 bf16 cases failed with 1-ulp (0.0078125) diffs
     against rtol/atol 2e-3. The oracle now narrows the decoded weight to
     the activation dtype, matching the native path; the bound is the
     half-ulp at unity (2^-9 ~= 2e-3). FIXED.
   - tests/test_fp8_bias_range.py::test_fp8_gpu_dequant_fallback_keeps_bias_wide
     REPRODUCED on sm_80 (fp16: actual 0.0 vs oracle 0.0078125). Renamed to
     test_fp8_gpu_native_gemm_keeps_bias_wide and rewritten for the #3737
     intent: finite output, FP32 bias, residual bounded by one activation-
     dtype ulp of |x.w|. FIXED.

2. bf5adeb (#4657, Marlin bias kept in checkpoint order)
   - tests/test_marlin_scratch_cuda.py 288/200 cases REPRODUCED on sm_80:
     8 failed with "b_bias.size(0) != size_n". scripts/marlin_scratch_fixture.py
     now passes layer._kernel_bias(a) (padded, tile-ordered FP32) instead of
     the checkpoint-order layer.bias. FIXED (8 failed -> 68 passed, 2 skipped).

3. 60376e9 (#4714, default placement in one capability group)
   - tests/test_tenstorrent_support.py already passes on current main: the
     monkeypatched _record accepts **kwargs (fixed upstream by 50f1752).
     ALREADY PASSES on sm_80.

4. 34672a7 (#4585, modules snapshot the kernel policy)
   - tests/kernels/test_bitsandbytes_rocm_triton.py triton cases SKIP on
     sm_80 (no tuned bitsandbytes tile for this family). DEFERRED: the
     stated failure cannot be reproduced here.

5. dfa180d (#4627, GGUF path chosen from static gates)
   - both tests REPRODUCED on sm_80 with AttributeError
     _benchmark_forward_runner. The removed timing hook is no longer patched;
     each test asserts the hook stays absent. FIXED.

6. fd8d524 (#4599, AwqGEMVTorchLinear CPU reader)
   - both kernel-registry contract tests already pass on current main
     (AwqGEMVTorchLinear is in EXCLUDED and the ROCm audit table; fixed
     upstream by ab151fe). ALREADY PASSES on sm_80.

7. d2a0508 (#4283, dense-module adapters)
   - tests/kernels/test_gptq.py::TestKernelOutput errors on sm_80 before the
     adapter path: this host's flash_attn_2_cuda has an undefined symbol, so
     the stated Lora assertion is never reached. DEFERRED: blocked by the
     pre-existing host flash_attn failure; the fix cannot be verified here.

8. f201837 (#4508, activation-quantization wording)
   - both tests REPRODUCED on sm_80. The refusal still fires; the regex now
     matches "activation quantized|activation scales". FIXED.

9. b225a43 (#4727, static-cache compile test)
   - ROCm-only failure. On sm_80 the CUDA leg runs and fails earlier on the
     host flash_attn symbol, so the ROCm gate cannot be reproduced.
     DEFERRED.

Test run (GPU 4):
  tests/kernels/test_fp8_kernel.py tests/test_fp8_bias_range.py
  tests/test_marlin_scratch_cuda.py tests/test_marlin_scratch_benchmark.py
  tests/kernels/test_gguf_cpp_activation_quantization.py
  tests/kernels/test_gguf_cpp_path_selection.py tests/test_auto_module_decoder.py
  => 254 passed, 35 skipped, 1 failed.
The single failure is the pre-existing sm_80
test_fp8_w8a8_forward_is_batch_invariant (native torch._scaled_mm needs
sm_89+); it fails identically on origin/main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants