Repository navigation
fix(awq): pack and load GEMV_FAST/LLM_AWQ on ROCm with the portable reader - #5176
Merged
Merged
Conversation
) #4753 gave FORMAT.GEMV_FAST and FORMAT.LLM_AWQ portable Torch readers, but only for a CPU-only host: on ROCm every path refused before calibration. AUTO raised "No valid quant linear", BACKEND.AWQ_TORCH rejected DEVICE.ROCM ("only supports cpu"), and BACKEND.AWQ_GEMV_TRITON does not declare either format, so the documented format/platform combination could not be produced at all. Resolve the pack backend from the device family: awq_gemv_fast_pack_backend() returns BACKEND.AWQ_GEMV_FAST on NVIDIA and BACKEND.AWQ_TORCH wherever the extension cannot build (CPU, ROCm). Both portable readers now declare DEVICE.CPU/CUDA/ROCM and are reached by the per-family portable fallback in select_quant_linear, which is now keyed on the target families instead of "CPU only" (PORTABLE_FALLBACK; the GEMV reader keeps its CPU-only declaration). The readers move the packed words to the input device inside forward() rather than rewriting module state, so an AUTO reload of a saved checkpoint works on ROCm without an explicit backend and keeps only packed INT16/FP16 storage. An AUTO CUDA load still selects the native kernel, and the GEMV-on-ROCm refusal now names only FORMAT.GEMV and the readers that do apply. Fixes #5109
Qubitium
marked this pull request as ready for review
November 18, 2026 08:18
This was referenced Nov 18, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 18, 2026
…#5201) (#5217) `docs/generate-cpu-offload-autograd.md` cited `gptqmodel/models/base.py:3939` for `generate`. Three merges after #5165 repaired it, #5176 and #5182 moved `def generate` to 3948, outside `LINE_WINDOW`, so `test_docs_contract_refs.py::test_contract_reference_resolves` was red on `main`. Cite the symbol instead, as the test's own header already recommends for a file that moves often. The registry keeps one `SYMBOL_CITATION` entry instead of the line-anchored duplicate. Also convert the remaining guarded `base.py:359` citation (`_quantize_summary_counts`) and add `test_models_base_citations_use_the_symbol_form`, which rejects any future line-numbered citation into `models/base.py` in the registry. That file grows with nearly every fix PR, so a line citation drifts within a couple of merges.
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.
Fixes #5109
Summary
FORMAT.GEMV_FASTandFORMAT.LLM_AWQcan now be quantized, run in-session and reloaded on ROCm. Before this change every backend refused them on a HIP host, so a documented format/platform combination was unusable.What Changed
awq_gemv_fast_pack_backend()resolves the AUTO pack backend from the device family:BACKEND.AWQ_GEMV_FASTon NVIDIA,BACKEND.AWQ_TORCHwhere the native extension cannot build (CPU and ROCm).BaseQModel.quantize()uses it instead of hardcodingAWQ_TORCHfor CPU andAWQ_GEMV_FASTotherwise.AwqGEMVFastTorchLinear/LLMAwqTorchLineardeclareDEVICE.CPU,DEVICE.CUDAandDEVICE.ROCM. Their forward moves the packed words to the input device per call instead of rewriting module state, so a partially placed or offloaded layer never materializes a dense weight on the wrong device.select_quant_linear()'s portable fallback is now keyed on the resolved target families (_portable_fallback,PORTABLE_FALLBACK) rather than "CPU only". A reader is eligible only when it declares every target family, so the CPU-onlyAwqGEMVTorchLinearstill never serves ROCm; the pre-existingPORTABLE_CPU_FALLBACKspelling keeps working._reject_native_awq_gemv_on_rocm()now refuses onlyFORMAT.GEMV(which has the portable Triton reader, needing an explicitAWQ_GEMV_TRITON).GEMV_FAST/LLM_AWQare no longer rejected before selection, andAWQ_GEMV_ROCM_UNSUPPORTEDno longer claims those formats are unreadable.AwqGEMVFastLinear/LLMAwqLinear. The portable readers keepSUPPORTS_FORMATSpriority0, so they are never AUTO-selected where a native kernel exists.rocm-rdna4.md(backend row and the GEMV-family AUTO resolution page),quantization-guide.md,in-session-model-after-offload.md,kernel-compile-matrix.md, and the AWQ extension error text.Logic flow
Old flow (ROCm), with the failure paths this fixes:
flowchart TD A["quantize(GEMV_FAST/LLM_AWQ, backend=AUTO) on ROCm"] --> B["preferred_backend = BACKEND.AWQ_GEMV_FAST"] B --> C["select_quant_linear: native class is CUDA-only"] C --> D["AUTO: no candidate, no CPU-only fallback for ROCM"] D --> E["ValueError: No valid quant linear"] A2["explicit BACKEND.AWQ_TORCH"] --> F["AwqGEMVFastTorchLinear.SUPPORTS_DEVICES = [CPU]"] F --> G["ValueError: only supports cpu ... does not run on ROCm"] A3["explicit BACKEND.AWQ_GEMV_TRITON"] --> H["no kernel declares GEMV_FAST/LLM_AWQ"] H --> I["ValueError: Unsupported backend"] style E fill:#f8d7da,stroke:#b02a37,stroke-width:2px style G fill:#f8d7da,stroke:#b02a37,stroke-width:2px style I fill:#f8d7da,stroke:#b02a37,stroke-width:2pxNew flow:
flowchart TD A["quantize(GEMV_FAST/LLM_AWQ, backend=AUTO)"] --> B{"awq_gemv_fast_pack_backend"} B -- "cuda, not HIP" --> C["BACKEND.AWQ_GEMV_FAST -> AwqGEMVFastLinear / LLMAwqLinear"] B -- "cpu or IS_ROCM" --> D["BACKEND.AWQ_TORCH -> AwqGEMVFastTorchLinear / LLMAwqTorchLinear"] D --> E["pack, in-session forward, save"] E --> F["AUTO reload: no native candidate for ROCM"] F --> G{"_portable_fallback<br/>declares every target family?"} G -- "yes" --> H["portable reader; packed buffers moved per forward"] G -- "no" --> I["No valid quant linear"] C --> J["AUTO CUDA load keeps the native kernel"] style I fill:#f8d7da,stroke:#b02a37,stroke-width:2pxFORMAT.GEMVis unchanged: AUTO quantize resolvesAWQ_GEMV_TRITON, an AUTO load still raises the actionableAWQ_GEMV_ROCM_UNSUPPORTEDand reloading needs an explicitBACKEND.AWQ_GEMV_TRITON.Tests
Red/green evidence for the new nodes (fix stashed, same tree):
End-to-end on a HIP host, Qwen2.5-0.5B-Instruct, 32 calibration texts,
AWQConfig(bits=4, group_size=128):FORMAT.GEMV_FASTAwqGEMVFastTorchLinearAwqGEMVFastTorchLinearmax 0)max 0.195,mean 0.02(FP16 kernel-order drift)FORMAT.LLM_AWQLLMAwqTorchLinearLLMAwqTorchLinearmax 0)max 0.195,mean 0.02(same drift)The same CPU-vs-GPU drift is measured for the
FORMAT.GEMMcontrol on the same host (max 0.230,mean 0.02), so it is the host's arithmetic order, not the new layout. No dense weight buffer (FP32 or otherwise, atin_features * out_featureselements) exists after load or after repeated forwards.Torch-oracle coverage: the portable forward is asserted against the independent fake-quant oracle in
test_awq_gemv_fast_portable_reader_moves_packed_storage_per_callandtest_rehome_switches_native_gemv_fast_module_to_cpu_reader(rtol=1e-3, atol=1e-2).Magnitude/packed-storage:
AwqGEMVFastTorchLinear/LLMAwqTorchLinearkeepSUPPORTS_COMPILE_LEVEL = INDUCTOR; the measured probe on CPU and HIP builds iseager=True graph_breaks=0 dynamo/aot_eager/inductor=Truewith output matching eager. Eager CUDA-graph capture is not claimed.Pre-existing, unrelated (fails identically on a pristine
origin/mainworktree,tests/kernels/test_kernel_compile_levels_cpu.py):test_cpu_kernel_reaches_declared_cpu_level[TorchLinear],test_torch_quant_embeddings_reaches_declared_cpu_level[whole_table].Model Support / Module Plan
Not applicable: no model type, alias, definition, module plan or fusion eligibility change.
tests/module_tree/test_fusion_kernel_backends.pyonly updates the exclusion reason text for the two portable readers.AWQ onboarding safety
Not applicable: no new model/definition and no AWQ grouping, search, replay or folding change. The two layouts keep their existing packing, scales and offsets; only backend resolution and device declarations changed.
Logic Flow Documentation
awq_gemv_fast_pack_backend,_portable_fallback,PORTABLE_FALLBACK,AwqGEMVFastTorchLinear).docs/rocm-rdna4.md(AWQ GEMV-family AUTO resolution) anddocs/in-session-model-after-offload.mdrepeat the diagrams;README.mdalready links both.Review Requirements
awq_gemv_pack_backendis the sibling pattern).FORMAT.GEMVbehavior,AwqGEMVTorchLinearCPU-only declaration and the pre-existingPORTABLE_CPU_FALLBACKspelling are all unchanged and covered.Kernel Accuracy Requirements
ROCM_KERNELSintests/test_rocm_kernel_contracts.py, which still runs every registered kernel's declaration audit.Notes
GEMV_FASTlayout. This change makes the format usable, not fast;FORMAT.GEMMremains the recommended decode/prefill layout.docs/quantization-guide.mdpreviously said aGEMV_FASTcheckpoint could only be produced on CPU or CUDA; it now documents CPU, CUDA and ROCm.