Skip to content

[BUG][ROCm] Follow-up on #4072/#4075: CUDA-only JIT loads hipify over tracked tt_blockfloat_hip sources, AWQ Triton split-K nondeterministic (AUTO on RDNA4), forced rocBLAS 8-14x slower fp16/bf16 GEMM, hipblaslt opt-in non-reproducible #4092

Closed

Description

@Qubitium

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.cu and tt_blockfloat_cuda/tt_blockfloat_cuda_torch.cpp are written onto the tracked tt_blockfloat_hip/tt_blockfloat_hip.hip and tt_blockfloat_hip/tt_blockfloat_hip_torch.cpp.
  • The machete load hipifies every header under its include roots: 102 files across gptqmodel_ext, including the tracked tt_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=False so load() returns False before hipify runs.
  • Guard tt_blockfloat_cuda.prewarm() / _ops() with supported().
  • Extend tests/test_hip_jit_source_staging.py beyond the 5 opted-in loaders, e.g. assert git status is 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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions