Repository navigation
Description
Audit of main @ ad0525c on 4× AMD Radeon AI PRO R9700 (RDNA4, gfx1201), torch 2.16.0.dev+rocm10.1, free-threaded CPython 3.14.
1. import gptqmodel enables expandable_segments on ROCm, and on this stack that silently corrupts GPU results (high)
gptqmodel/_alloc_conf.py:26-30 sets DEFAULT_ALLOC_CONF = "expandable_segments:True,max_split_size_mb:256,garbage_collection_threshold:0.7", and gptqmodel/__init__.py applies it unconditionally through apply_default_alloc_conf(), with no ROCm check. On torch+rocm10.1 / gfx1201, expandable_segments:True combined with torch.cuda.empty_cache() on large tensors makes ordinary torch ops return wrong values, or sometimes raise hipErrorIllegalAddress. GPTQModel calls torch_empty_cache about 50 times during quantize and load, so every ROCm user runs into this by default.
Pure torch, no gptqmodel: a 2097152×16 matmul, recomputed on the GPU and compared, with empty_cache between 3 reps. The bad-row count should be 0:
PYTORCH_ALLOC_CONF=expandable_segments:False bad rows 0
PYTORCH_ALLOC_CONF=expandable_segments:True bad rows 4,522,900
the same script with only `import gptqmodel` added (its default alloc conf) bad rows 655,360
... with PYTORCH_ALLOC_CONF=expandable_segments:False exported bad rows 0
the same pattern without empty_cache clean
Without empty_cache the pattern is clean, so the trigger is VMM segment release/remap. In GPTQModel this first showed up as "wrong rows" from the tt_blockfloat_hip linear (1e5–1e6 bad rows, fp32/fp16/bf16 alike), as NaN or 10× perplexity in end-to-end ROCm quantization, and as MEMORY_FAULT in dequant kernels. All of these went away with expandable_segments:False. The root cause is in the ROCm/torch platform, but GPTQModel is what turns it on. Fix: don't add expandable_segments when torch.version.hip is set, at least for ROCm ≥ 10 / gfx12 until the platform is fixed. Add a ROCm CI check that runs this pattern under the default config.
2. Five HIP JIT loaders write hipify output into the source tree (medium)
Torch hipifies sources next to the originals, and these loaders pass checkout paths directly. .gitignore:228-229 (gptqmodel_ext/**/*_hip.*, gptqmodel_ext/**/*.hip) hides the generated files from git status.
| loader | files written into gptqmodel_ext/ |
|---|---|
utils/allspark_hip.py:40 _sources |
allspark_hip/allspark_hip.hip, allspark_torch_hip_hip.cpp |
utils/hadamard.py:31 _hadamard_sources |
hadamard/hadamard_hip.cpp, fast_hadamard_transform_hip.hip, fast_hadamard_transform_common_hip.h |
quantization/gptq_cuda.py:17 |
gptq_block/gptq_block.hip |
exllamav3/ext.py:75 |
23 files (bindings_hip.cpp, hgemm.hip, quant/*.hip, comp_units/*.hip, *_hip.cuh) |
utils/paroquant.py:317 |
paroquant/rotation.hip |
A read-only site-packages install therefore can't build these extensions, and a shared install gets modified at runtime. nf12_hip.py and tt_blockfloat_hip.py already do the right thing: they copy sources into <build_root>/_src first, and the nf12_hip.py:_sources docstring describes exactly this failure. Fix: move that staging helper into TorchOpsJitExtension and use it for every HIP build.
3. ParoQuantTritonLinear crashes on strided activations: #4047 (for #4042) missed this class (medium, not HIP-specific)
#4047 added .contiguous() in ParoLinear.forward (paroquant.py:~593), but ParoQuantTritonLinear overrides forward. At nn_modules/qlinear/paroquant_triton.py:221 it passes x.reshape(-1, K) (still a strided view) to _rotate_inputs, and the fused rotation op rejects it (gptqmodel_ext/paroquant/rotation.cu:1018). Batched generate() decode feeds hidden_states[:, -1:, :], so BACKEND.PAROQUANT_TRITON fails at bs>1:
ParoLinear strided OK (max diff vs contiguous 0.0)
ParoQuantTritonLinear strided FAIL: RuntimeError: ParoQuant rotation tensors must be contiguous.
All 132 other Triton/Torch ParoQuant cases passed (2-D, 3-D, M 1-129, fp16/bf16). Fix: x_flat = x.reshape(-1, x.shape[-1]).contiguous(). Also parametrize test_paroquant_cuda_forward_packs_a_strided_activation (tests/kernels/test_paroquant.py:535) over ParoQuantTritonLinear.
4. bitsandbytes 4-bit on ROCm silently drops autograd for M >= 16 (low-medium)
nn_modules/qlinear/bitsandbytes.py:893-911: the Triton dispatch (triton_backend.should_use(...), on by default only on ROCm) has no requires_grad check, and bitsandbytes_triton.matmul_4bit is a raw Triton launch. The other paths in the same class (CPU packed :647, int8 dense :987) and the GPTQ fused gate do fall back when x.requires_grad:
rows=15 y.requires_grad=True grad_fn=MatMul4BitBackward |dx|=51.5
rows=16 y.requires_grad=False grad_fn=None |dx|=None
The class is SUPPORTS_TRAINING=False, so this affects grad-through-input use (adapters, attribution). GGUFTritonKernel behaves the same way while its parent GGUFTorchLinear declares SUPPORTS_TRAINING=True (not HIP-specific). Fix: add not (torch.is_grad_enabled() and x.requires_grad) to the Triton dispatch condition, in both places.
Checked, clean on gfx1201
- Triton/Torch kernels vs an fp64 oracle (thousands of cases; M 1–1024, K/N 896–27648, bits 2/3/4/8, every group size, sym/asym, desc_act, bias, fp16/bf16, strided and 3-D inputs, torch.compile):
- GPTQ
TorchLinear, including the ROCm GEMV/fused GEMM paths; - AWQ Triton GEMM/GEMV and AWQ Torch;
- GGUF Triton (Q1_0/Q4_K/Q5_K/Q6_K);
- bitsandbytes nf4/fp4 and 8-bit;
- ParoQuant Triton decode/prefill;
- QQQ Triton
dynamic_quant, which is bit-exact.
- GPTQ
- End-to-end with AUTO: ROCm PPL matches CUDA within 0.07 (Llama-1B GPTQ 28.90 vs 28.97, AWQ 20.85 vs 20.84).
- Native HIP:
- NF12 encode/decode is byte- and bit-exact, including inf/nan/denormal/±0. The NF12 linear is within bf16 rounding at M 0–1000, M×N > 2³¹ and on side streams.
- AllSpark HIP is within 4e-3.
- tt_blockfloat quant/dequant is bit-exact.
- Hadamard is correct for widths 2–32768.
- GSQ HIPRTC (wave32) matches eager to about 1e-6.
- exllamav3 and paroquant build and load.
- 788 pytest cases passed.
- Gates: QQQ native, AWQ native GEMM/GEMV, VPTQ, ExLlamaV2, W4AFP8, W4A-NVFP4, Marlin, Machete and TritonV2 all fail fast on gfx1201 with a clear error. The ExLlamaV2 GPTQ message suggests
BACKEND.TORCH, but the member isGPTQ_TORCH. - Generate: AUTO, static cache and torch.compile generation are correct for both GPTQ and AWQ.
Plausible, not verified (single visible GPU)
- GSQ
_hip_launchloads one module per device but never sets the current device beforehipModuleLaunchKernel. - The bnb Triton
matmul_4bit/dequantize_4bitlaunch without atorch.cuda.device(x.device)guard (same class as the GGUF multi-GPU fix in fix(kernels): pack strided inputs, bind devices, widen offsets, handle M=0 (#4042) #4047). - GSQ kernels index with
int(j*n+i), which overflows for rows×cols > 429M, e.g. a large lm_head.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 14, 2026
Addendum to item 1: the obvious workaround is overridden as well.
alloc_conf_configured()only looks atALLOC_CONF_ENV_VARS = ("PYTORCH_ALLOC_CONF", "PYTORCH_CUDA_ALLOC_CONF")(gptqmodel/_alloc_conf.py:35). ROCm torch also readsPYTORCH_HIP_ALLOC_CONF. If a user sets only the HIP variable, GPTQModel treats the allocator as unconfigured and writesPYTORCH_ALLOC_CONF, which torch reads first. The user'sexpandable_segments/max_split_size_mb/garbage_collection_thresholdare then replaced without a warning. Thebackend:key still survives.So a ROCm user who applies
PYTORCH_HIP_ALLOC_CONF=expandable_segments:Falseto avoid item 1 gets expandable segments re-enabled. Fix: addPYTORCH_HIP_ALLOC_CONFtoALLOC_CONF_ENV_VARS, and add a unit test that sets only that variable and assertsapply_default_alloc_conf()is a no-op. Until this is fixed, the workaround is to exportPYTORCH_ALLOC_CONF=expandable_segments:False.Also seen with the default (
:True) conf on gfx1201, likely the same corruption: same-seed GPTQ quantize differs in ~335/794 tensors from run to run (serial, GIL on);HSA_STATUS_ERROR_MEMORY_FAULTindequant_kerneland garbageg_idx(min=max=558702850) over repeated load/forward/del cycles.Qubitium commentedon Nov 14, 2026
More evidence for item 1, from end-to-end ROCm runs (R9700 gfx1201; each row compares the default alloc conf with
expandable_segments:False):expandable_segments:Falseimport gptqmodellinalg.cholesky ... leading minor of order 1 not PD(qqq.py:817)hipErrorIllegalAddress, then the process hangsPlain HF without
import gptqmodelwas 6/6 clean. With:False, every method matched CUDA PPL (rtn/gptaq/fp8/nf12/gguf/exl3 4-bit within 0.1). ROCm↔CPU and CUDA→ROCm checkpoints also load with matching outputs.fix(rocm): stop enabling expandable_segments and make quantization re…
fix(dispatch): repair CPU optimize/compile, max_memory and HIP/autogr…
Qubitium commentedon Nov 15, 2026
Resolved by #4079 (item 1:
import gptqmodelno longer enablesexpandable_segmentson ROCm, and installsROCBLAS_USE_HIPBLASLT=0; both defer to a caller-provided value) and #4082 (items 2-4: HIP JIT sources staged out of the source tree,ParoQuantTritonLinearcontiguous activations, bitsandbytes Triton autograd gate).fix(rocm): scope the deterministic BLAS pin and stage HIP sources (#4092
fix(rocm): stop pinning max_split_size_mb in the allocator default (#…