Repository navigation
fix(rocm): pin every Hessian builder and serialize mixed BLAS scopes (#4123) - #4141
Merged
Merged
Conversation
…4123) #4105 scoped the deterministic rocBLAS pin to `ProcessorStep.GPTQ`, which dropped QQQ (it builds an X^T X Hessian in `add_batch`) and the other Hessian builders. QQQ then accumulated on hipBLASLt and four runs produced three distinct checkpoints differing in 490/627 tensors. - base: gate on a `_HESSIAN_PROCESSOR_STEPS` set (GPTQ, QQQ, VPTQ, MACaQ, EXL3, FP8_GSQ) instead of `ProcessorStep.GPTQ`, and always enter the guard: Hessian builders pin rocBLAS, AWQ/ParoQuant/RTN pin hipBLASLt. - rocm: carry a `_QUANT_BLAS_GUARD_TARGET` on the refcounted guard and make a mixed-backend run wait for the active one instead of flipping the process-global backend mid-run (AWQ vs serial was 319/627 differing). - rocm: warn for the opt-out spellings (""/0/off/default) too, not only the two opt-ins. - cpp: refresh the staged in-checkout include root every call, because the cache fingerprint hashes the staged copy, so a stale stage hid header edits. - docs: correct "AWQ/RTN/QQQ have no Hessian", add the per-method determinism/concurrency tables, and scope the split-K=1 speed claim.
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 #4123
Root cause
#4105 scoped the deterministic rocBLAS pin with
ProcessorStep.GPTQ in run_plan.processors(gptqmodel/models/base.py:145).QQQ builds a Hessian too (
quantization/qqq.py:635,existing.addmm_(inp, inp.t()), consumed byinverse_hessian), so QQQaccumulated on hipBLASLt and lost the cross-process reproducibility #4079
bought. VPTQ (
quantization/vptq.py:283), MACaQ(
quantization/macaq.py:668), EXL3 (it reuses GPTQ's capture,looper/exllamav3_processor.py:192) and calibrated FP8 GSQ(
quantization/gsq_calibration.py:56,values.T @ values) are in the sameclass.
docs/rocm-default-environment.md,docs/rocm-rdna4.mdand the_needs_deterministic_hessiandocstring all claimed the opposite("AWQ/RTN/QQQ have no Hessian"); README only links the ROCm guide and carries
no such claim, so it needed no correction.
ProcessorStep.GPTQ, not "this run has a Hessian builder"_HESSIAN_PROCESSOR_STEPS(gptqmodel/models/base.py:148) and_needs_deterministic_hessian(gptqmodel/models/base.py:158); the call site always enters the guard (gptqmodel/models/base.py:2213)gptqmodel/utils/rocm.py:290-296)_QUANT_BLAS_GUARD_COND(gptqmodel/utils/rocm.py:372) instead of flipping it_warn_if_blas_is_not_reproduciblewarned only forhipblaslt/cublaslt(gptqmodel/utils/rocm.py:151)QUANT_BLAS_BACKEND_DISABLED("",0,off,default,hipblaslt,cublaslt)The pin itself is unchanged: Hessian builders run on rocBLAS, everything else on
hipBLASLt. Only the gate and the mixed-backend coordination changed.
Control flow
flowchart TD A["GPTQModel.quantize"] --> B{"_needs_deterministic_hessian"} B -- "yes: GPTQ, QQQ, VPTQ, MACaQ, EXL3, FP8 GSQ" --> C["want rocBLAS"] B -- "no: AWQ, ParoQuant, RTN" --> D["want hipBLASLt"] C --> E{"another run holds the other backend?"} D --> E E -- "yes" --> F["wait for it to finish"] F --> E E -- "no" --> G["refcount + 1, pin want for the whole run"] G --> H["calibration forward, Hessian GEMMs, inversion"] H --> I["refcount - 1, last exit restores the caller backend"] classDef pin fill:#e3f2fd,stroke:#1565c0,color:#000 classDef fast fill:#e8f5e9,stroke:#2e7d32,color:#000 class C,G,H pin class D fastFail-before / pass-after
Item 1: the Hessian gate
Same expression,
origin/mainworktree (13ee428f2) vs this branch:Cross-process, Qwen2.5-0.5B-Instruct, separate processes, every
state_dicttensor hashed,
>= 4runs unless noted:Backend counter on QQQ's
add_batch(32 samples, 5376 calls):Cublasltbefore,Cublas(rocBLAS) after.The GPTQ row's tensor count grows to 963 after merging current
main, whichadds the
qzeros_formatscalar to the checkpoint (#4138); the four merged-treeruns are 0 differing out of 963, and QQQ is 0 out of 627 there.
End-to-end QQQ time is essentially unchanged on this host because its Hessian
GEMM is fp32, where rocBLAS is the faster backend: 14.2 s / 15.5 s before vs
14.2 s / 16.3 s after (32 samples).
Item 2: concurrent mixed-method quantize
Two threads, AWQ first, GPTQ started 5 s / 25 s later, 16 samples
(
/tmp/n4123/concurrency.py):The 5 s case is the defect: AWQ ran its first layers on hipBLASLt and the rest
on rocBLAS once GPTQ entered. With the target wait, GPTQ blocks until AWQ
finishes, so AWQ's checkpoint matches a serial run.
Item 3: opt-out warning
Before: no test existed and
""/0/off/defaultskipped the pin silently.After: all four spellings log
"ROCm quantization will not pin rocBLAS (...)", and an unrecognised valuestill falls back to rocBLAS without a warning.
Tests
tests/test_rocm_default_env.py::test_quantization_is_reproducible_across_processesnow parametrises
gptqandqqq(two separate processes each).CUDA cross-check (mocked suites,
GPU-1892aea4):ruff check gptqmodel docs/eora tests setup.py->All checks passed!Hardware
HIP_VISIBLE_DEVICES=0, Torch 2.16.0.dev+rocm10.1,Python 3.14t.
GPU-1892aea4-cc09-827c-b9a5-93d4eef7f5ae(mocked suites only; the ROCm-only behaviour is not claimed for CUDA).
Docs
docs/rocm-default-environment.md: corrected "AWQ/RTN/QQQ have no Hessian",added the Hessian-builder table, the exclusive-guard flow, the per-method
determinism table, the concurrency table, the QQQ time cost, and the opt-out
warning spellings.
docs/rocm-rdna4.md: same scoping correction; scoped the AWQ split-K=1 speedclaim (see below).
docs/concurrency.md: documents_QUANT_BLAS_GUARD_TARGETand theserialization rule.
The "plausible" items from the issue
M >= 16withK = 2048/4096, but at smallMwith largeKit is 1.2-1.8x slower atkernel level:
(N,K,M)= (2048,8192,1) 152.9 vs 84.5 us, (2048,8192,8)153.2 vs 88.1 us, (4096,14336,1) 228.7 vs 155.5 us, (4096,14336,16) 210.3 vs
176.3 us. End-to-end greedy decode is unchanged (37.0 vs 36.6 tok/s, 48
tokens, Qwen2.5-0.5B-AWQ), so split-K=1 is a determinism fix, not a decode
speedup. Docs corrected.
_stage_hip_sourcescopied anin-checkout include root only
if not external.exists(), while_cache_fingerprinthashes the staged copy, so a header edit was invisibleand a stale binary could be reused. Fixed in
gptqmodel/utils/cpp.py(refreshevery call) with a regression test in
tests/test_hip_jit_source_staging.py.Remaining limitation
VPTQ still differs 11-12/305 across processes. The pin is applied (its
add_batchGEMMs run onCublas), but its k-means centroid update usesindex_add_(gptqmodel/quantization/vptq.py:159-162), whoseduplicate-index accumulation is atomic on this stack: five repeats of a bare
index_add_with duplicate indices produced five distinct results. That isindependent of the BLAS backend and predates #4105 (before: 12-14 differing).
It needs a deterministic segment-sum and is out of scope here.