Repository navigation
fix(rocm): install deterministic ROCm env defaults (#4072, #4075) - #4079
Merged
Merged
Conversation
…producible ROCm 10.1/gfx1201 corrupts ordinary Torch results when expandable_segments:True is combined with torch.cuda.empty_cache(), which GPT-QModel calls throughout quantization. Install a ROCm allocator default without expandable_segments and keep the CUDA default unchanged. rocBLAS also forwards its GEMMs to hipBLASLt, which selects a different kernel per process for the same shape; identical GPTQ runs then save different checkpoints (334/795 tensors on Qwen2.5-0.5B). Export ROCBLAS_USE_HIPBLASLT=0 at import so rocBLAS stays deterministic. Both defaults defer to any caller-provided value, including the HIP-only PYTORCH_HIP_ALLOC_CONF alias. Fixes #4075 Part of #4072 (item 1)
This was referenced Nov 15, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 15, 2026
) (#4105) * fix(rocm): stage HIP sources, make AWQ split-K deterministic, scope the BLAS pin (#4092) ROCm follow-ups to #4072/#4075 after #4079/#4082: - HIP JIT builds stage sources by default for every extension, including include roots inside the checkout, and refuse to hipify a tracked source in place. A CUDA-only extension can no longer overwrite the hand-written tt_blockfloat_hip sources; tt_blockfloat_cuda.prewarm()/_ops() are gated by supported(). - The AWQ Triton generic fused plan uses split_k_iters=1 on RDNA4 and whenever deterministic algorithms are enabled, removing the tl.atomic_add split-K reduction that made repeats differ. The exact-shape RDNA4 rules were already split-K=1. - The deterministic rocBLAS override is scoped to run plans that build a Hessian (ProcessorStep.GPTQ). AWQ/RTN/QQQ keep hipBLASLt, which is 8-14x faster for their fp16/bf16 GEMMs. The GPTQ family keeps the override for its calibration forward and replay because those activations feed the Hessian; pinning only the X^T X GEMM regressed Qwen2.5-0.5B to 332/795 differing tensors. The switch is reference counted for concurrent workers. - The hipBLASLt opt-in logs a warning once and the docs record that it gives up cross-process reproducibility. Cross-process determinism after the change: GPTQ 0/483 and AWQ 0/371 on Llama-3.2-1B (128 samples), and the Qwen2.5-0.5B test at 0/795. * docs(rocm): record the post-#4094-merge measurements (#4092) Re-measured on the reconciled tree (origin/main d7a41a1, gfx1201): - F.linear TFLOPS rocBLAS -> hipBLASLt: 9.5 -> 139.0 (bf16 4096x4096x14336), 10.2 -> 119.8 (fp16 512x2048x8192), 0.5 -> 7.3 (bf16 16x896x4864), 20.5 vs 16.3 (fp32 8192x4096 X^T X; rocBLAS wins). - Cross-process determinism: GPTQ 0/483, AWQ 0/371 (Llama-3.2-1B, 128 samples). End-to-end 58.1/61.4 s (GPTQ) and 50.7/45.5 s (AWQ). - Opt-in evidence is now a 4-run sample for GPTQMODEL_ROCM_QUANT_BLAS=hipblaslt: 222/483 differing between the two kernel-selection groups, 0 within a group; ROCBLAS_USE_HIPBLASLT=1 stays at 224/483.
This was referenced Nov 15, 2026
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 #4075
Part of #4072 (item 1)
TL;DR
import gptqmodelnow installs two ROCm-only process defaults that both defer to a caller-provided value:PYTORCH_ALLOC_CONFwithoutexpandable_segments, andROCBLAS_USE_HIPBLASLT=0. The first stops a VMM bug from silently corrupting Torch results afterempty_cache(); the second makes GPTQ quantization reproducible across processes. CUDA behaviour is unchanged. Net: 3 code files (1 new), 2 test files (1 new), 2 docs pages (1 new), plusREADME.md.1. The problem
Old flow (
main@39b62765e):flowchart TD A["import gptqmodel"] --> B["apply_default_alloc_conf"] B --> C{"caller set PYTORCH_ALLOC_CONF or PYTORCH_CUDA_ALLOC_CONF"} C -- "no" --> D["install expandable_segments:True on every build"] C -- "yes" --> E["preserve caller value"] D --> F["first BLAS call"] E --> F F --> G["rocBLAS forwards GEMMs to hipBLASLt"] G --> H["hipBLASLt picks a kernel per process"] classDef fail fill:#ffe0e0,stroke:#c62828,color:#000 class D,H failgptqmodel/_alloc_conf.py:26-30, applied unconditionally atgptqmodel/__init__.py:29expandable_segments:True+torch.cuda.empty_cache()releases/remaps VMM segments on ROCm 10.1/gfx1201 and subsequent Torch ops read wrong data or raisehipErrorIllegalAddressMT64x64x16vsMT256x128x8(or split-K) per process; the first divergence istorch.cholesky_inverse(L, out=L)atquantization/gptq.py:1828, and GPTQ rounding amplifies it into different checkpoints2. The new flow
flowchart TD A["import gptqmodel"] --> B["_alloc_conf.apply_default_alloc_conf"] B --> C{"running_on_rocm"} C -- "no" --> D["CUDA default with expandable_segments"] C -- "yes" --> E{"caller set PYTORCH_ALLOC_CONF, PYTORCH_CUDA_ALLOC_CONF or PYTORCH_HIP_ALLOC_CONF"} D --> F["_rocm_env.apply_default_rocm_blas_env"] E -- "yes" --> G["preserve caller value"] E -- "no" --> H["ROCm default without expandable_segments"] G --> F H --> F F --> I{"running_on_rocm and caller did not set ROCBLAS_USE_HIPBLASLT"} I -- "yes" --> J["set ROCBLAS_USE_HIPBLASLT=0"] I -- "no" --> K["leave it untouched"] classDef fail fill:#ffe0e0,stroke:#c62828,color:#000 class G,K failgptqmodel/_rocm_env.py(new):running_on_rocm()andapply_default_rocm_blas_env(). Presence ofROCBLAS_USE_HIPBLASLTis honoured verbatim (including1and"").gptqmodel/_alloc_conf.py:default_alloc_conf()returnsROCM_DEFAULT_ALLOC_CONF(max_split_size_mb:256,garbage_collection_threshold:0.7) on HIP and the historicalDEFAULT_ALLOC_CONFotherwise;alloc_conf_env_vars()also treatsPYTORCH_HIP_ALLOC_CONFas caller configuration on ROCm.gptqmodel/__init__.py: applies both beforegptqmodel.utils, i.e. before the allocator or any BLAS call exists.docs/rocm-default-environment.md(new) keeps the diagrams and contracts;docs/rocm-rdna4.mdno longer claims rocBLAS is selected when it actually forwarded to hipBLASLt. Both are linked fromREADME.md.3. Failure / ambiguity contract
PYTORCH_HIP_ALLOC_CONF)ROCBLAS_USE_HIPBLASLTto1,0or""ROCBLAS_USE_HIPBLASLTnever writtenimport gptqmodel4. Before / after
Hardware: AMD Radeon AI PRO R9700 (
gfx1201, HIP 7.16.26385, torch 2.16.0.dev+rocm10.1).empty_cache()between 3 repsmainmainworktree,expandable_segments:Falseto isolate #4075)ROCBLAS_USE_HIPBLASLT=1on this branchimport gptqmodelon CUDAexpandable_segments:True,..., no BLAS varThe allocator repro is intermittent by nature; the deterministic regression guard is that the installed default contains no
expandable_segmentsand that the child process observes it.5. Tests
New
tests/test_rocm_default_env.py:expandable_segments; ROCm default drops it; caller values (all three names) preserved;1/0/""preserved, non-ROCm untouched;import gptqmodelinstalls both defaults, the issue's matmul repro returns 0 bad rows;HF_HUB_OFFLINE=1), asserts each child observedROCBLAS_USE_HIPBLASLT=0and all 795 tensor hashes match.Commands and results:
Branch was merged with
origin/main(39b62765e) before the final run; it was already up to date.6. Reviewer notes / limitations
import gptqmodelcannot be corrected; this is the same constraint the allocator default already has and is documented.GPTQMODEL_*switch is added; these are platform variables with caller precedence, like the existing allocator default.