Repository navigation
Description
ROCm follow-up to #4072 and #4075, after #4079/#4082. Tested on main @ a15e6bf, AMD Radeon AI PRO R9700 (gfx1201), ROCm 10.1, torch 2.16 dev, using the defaults import gptqmodel now sets (max_split_size_mb:256,garbage_collection_threshold:0.7, ROCBLAS_USE_HIPBLASLT=0).
1. #4072 item 2 still incomplete: on ROCm, loading a CUDA-only JIT extension hipifies into the source tree and overwrites tracked hand-written HIP sources (medium)
HIP source staging is opt-in (utils/cpp.py:1152, stage_hip_sources: bool = False), and only the 5 loaders named in #4072 opt in. load() never refuses a CUDA-only extension on HIP. hipify also rewrites cuda to hip in output paths, which has two consequences:
tt_blockfloat_cuda/tt_blockfloat_cuda.cuandtt_blockfloat_cuda/tt_blockfloat_cuda_torch.cppare written onto the trackedtt_blockfloat_hip/tt_blockfloat_hip.hipandtt_blockfloat_hip/tt_blockfloat_hip_torch.cpp.- The machete load hipifies every header under its include roots: 102 files across
gptqmodel_ext, including the trackedtt_blockfloat_hip/tt_blockfloat_hip.h.
Other extensions also write into the tree: exllamav2 creates a new exllamav2/hip/ tree, and awq, qqq, marlin, swordfish, vptq and allspark (CUDA) write *.hip files.
after tt_blockfloat_cuda.prewarm() on ROCm (git status of the checkout):
M gptqmodel_ext/tt_blockfloat_hip/tt_blockfloat_hip.h # "// !!! This is a file automatically generated by hipify!!!"
M gptqmodel_ext/tt_blockfloat_hip/tt_blockfloat_hip.hip # now the hipified *CUDA* kernel ("CUDA emulation kernels")
M gptqmodel_ext/tt_blockfloat_hip/tt_blockfloat_hip_torch.cpp
3 files changed, 1223 insertions(+), 1618 deletions(-)
next tt_blockfloat_hip build -> fatal error: 'tt_blockfloat_cuda.h' file not found
-> gptqmodel logs only "INFO ... JIT compilation failed; using fallback path" and silently runs the slower torch fallback
The native tt_blockfloat HIP kernel is lost for good in that install, and a read-only install fails outright. AUTO selection and gptqmodel.extension.load() are gated. The reachable entry points are a direct prewarm() / _EXTENSION.load() (utils/tt_blockfloat_cuda.py:134-137, _ops() at :164, no ROCm guard) or a test that doesn't skip on HIP.
Fix:
- Stage sources by default for every extension built on ROCm, or add
supports_hip=Falsesoload()returns False before hipify runs. - Guard
tt_blockfloat_cuda.prewarm()/_ops()withsupported(). - Extend
tests/test_hip_jit_source_staging.pybeyond the 5 opted-in loaders, e.g. assertgit statusis clean after loading every registered extension on HIP.
2. The AWQ Triton GEMM that AUTO selects on ROCm is nondeterministic, even with torch.use_deterministic_algorithms(True) (low-medium)
quantization/awq/modules/triton/scheduler.py:61-67 (legacy_plan: 32/32/32 tiles, split_k=8) is the fall-through for every shape not among the 8 exact _VERIFIED_RDNA4_FP16_RULES. That covers most real shapes, e.g. all Llama-1B projections at M 7–128. The fp32 split-K reduction uses tl.atomic_add (gemm.py:252-255), so the summation order changes from run to run. The scheduler's comment says repeated forwards are bit-identical, but that only holds for the table shapes.
fp16, deterministic algorithms on, 20 repeats:
N=2048 K=2048 M=64 split8 distinct=20/20 185us | split1 distinct=1/20 43us
N=4096 K=4096 M=32 split8 19/20 243us | split1 1/20 68us
N=8192 K=2048 M=16 split8 9/20 353us | split1 1/20 111us (max diff ~2e-3 on |y|~10)
AWQ-Llama-3.2-1B-g128-gemm (AwqGEMMTritonLinear), 4 processes: logits differ 4/4 at B1/B4 x M1/M7/M64; identical with split_k=1
On CUDA, AUTO picks the native AWQ extension, so ROCm is where this kernel is the default. Fix: default the fused plan to split_k=1 on RDNA4, and whenever deterministic algorithms are enabled. Here that is both deterministic and 1.0–4.3× faster.
3. #4079: forcing rocBLAS with ROCBLAS_USE_HIPBLASLT=0 during quantization makes fp16/bf16 GEMMs 8–14× slower and AWQ quantization 17–37% slower, with no determinism gain for AWQ (low, performance)
utils/rocm.py:240 (quant_blas_backend) forces rocBLAS for the whole quantize phase, and _rocm_env.py now sets ROCBLAS_USE_HIPBLASLT=0. rocBLAS has no fast fp16/bf16 kernels for gfx1201.
F.linear throughput in TFLOPS:
| Shape | dtype | =0 (now the default) |
=1 |
|---|---|---|---|
| 4096×4096×14336 | bf16 | 9.4 | 128 |
| 512×2048×8192 | fp16 | 10.0 | 102.5 |
| 16×896×4864 | bf16 | 0.35 | 8.0 |
| 8192×4096 XᵀX | fp32 | 19.9 | 8.6 |
Quantize time on Llama-3.2-1B, 128 samples, two runs per config:
| Config | AWQ time (s) | AWQ tensors differing between runs | GPTQ time (s) |
|---|---|---|---|
| default | 128 / 124 | 0 / 370 | 61 / 56 |
ROCBLAS_USE_HIPBLASLT=1 |
104 / 114 | 0 / 370 | 60 / 61 |
GPTQMODEL_ROCM_QUANT_BLAS=hipblaslt |
92 / 91 | 0 / 370 | 58 / 55 |
fp32 XᵀX is equal or faster with =0. Fix: keep ROCBLAS_USE_HIPBLASLT=0 for the rocsolver/Hessian path, which is where determinism matters, but don't force rocBLAS for the fp16/bf16 forward/replay GEMMs. For example, scope quant_blas_backend to the Hessian/linalg phase, or skip it for methods without a Hessian such as AWQ.
4. #4075 fix incomplete: the documented GPTQMODEL_ROCM_QUANT_BLAS=hipblaslt opt-in still gives non-reproducible GPTQ checkpoints (low)
With the opt-in set, torch's direct hipBLASLt path diverges across processes from layer 0. Two GPTQ runs on Llama-3.2-1B differ in 224/482 tensors (qweight and scales), against 0/482 with the default. ROCBLAS_USE_HIPBLASLT=1 also gives 224/482. Standalone hipBLASLt GEMMs are reproducible, so the divergence depends on process history (kernel selection). docs/rocm-default-environment.md doesn't say the opt-in gives up reproducibility. Fix: document it, or warn when the opt-in is set.
Checked, no defect found
- Env defaults: user-set
PYTORCH_HIP_ALLOC_CONF,PYTORCH_CUDA_ALLOC_CONF(also with CUDA initialized first), andROCBLAS_USE_HIPBLASLT''/1are honored. With CUDA initialized before import, the runtime setter still applies the non-expandable conf. Spawned children inherit the values. - Cross-process determinism (default env): gptq4, gptq4 desc_act, awq4, rtn4, qqq4 and gptaq4 on Qwen2.5-0.5B, and gptq4 and awq4 on Llama-1B (128 samples), give 0 differing tensors. Inference logits (HF fp16/bf16, GPTQ TorchLinear) are identical across 4 processes.
- [BUG][ROCm] Default expandable_segments alloc conf silently corrupts GPU results on ROCm 10.1/gfx1201; HIP JIT loaders write hipify output into source tree; ParoQuantTritonLinear strided crash (#4047 incomplete); bnb Triton drops autograd at M>=16 #4072 item 1 (memory corruption): under the new defaults, the round-6 load/forward/del cycles (12 iterations, GIL on and off) show no
HSA_STATUS_ERROR_MEMORY_FAULTand no corrupt g_idx. - [BUG][ROCm] Default expandable_segments alloc conf silently corrupts GPU results on ROCm 10.1/gfx1201; HIP JIT loaders write hipify output into source tree; ParoQuantTritonLinear strided crash (#4047 incomplete); bnb Triton drops autograd at M>=16 #4072 items 3 and 4: the ParoQuant strided tests pass, and the bnb/GGUF grad, staging and env tests pass (94 passed, 3 skipped).
- Staged HIP extensions: all 7 (allspark_hip, hadamard, gptq_block, paroquant, nf12_hip, tt_blockfloat_hip, exllamav3) build into the extensions dir and write nothing into the checkout.
Plausible, not verified
cpp.py build_root() restages _src with copytree outside _cross_process_build_lock. Every load(), even a cache hit, rewrites the staged sources while another process may be compiling from them. Three racing forced rebuilds all succeeded, so this wasn't reproduced.
🤖 Generated with Claude Code
Activity
Merge origin/main into fix/issue-4092-rocm
docs(rocm): record the post-#4094-merge measurements (#4092)
fix(rocm): scope the deterministic BLAS pin and stage HIP sources (#4092