Skip to content

fix(rocm): pin every Hessian builder and serialize mixed BLAS scopes (#4123) - #4141

Merged
Qubitium merged 4 commits into
mainfrom
fix/issue-4123-hessian-determinism
Nov 15, 2026
Merged

Qubitium merged 4 commits into
mainfrom
fix/issue-4123-hessian-determinism

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

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 by inverse_hessian), so QQQ
accumulated 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 same
class. docs/rocm-default-environment.md, docs/rocm-rdna4.md and the
_needs_deterministic_hessian docstring 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.

Item Root cause Fix
1 (medium) the gate was 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)
2 (low) the refcount had no target: a non-Hessian run did not enter the guard at all, so a GPTQ run flipped the process-wide backend under a concurrent AWQ run (gptqmodel/utils/rocm.py:290-296) every run pins its target for the whole run; a run that needs the other backend waits on _QUANT_BLAS_GUARD_COND (gptqmodel/utils/rocm.py:372) instead of flipping it
3 (low) _warn_if_blas_is_not_reproducible warned only for hipblaslt/cublaslt (gptqmodel/utils/rocm.py:151) warn for every spelling in 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 fast
Loading

Fail-before / pass-after

Item 1: the Hessian gate

Same expression, origin/main worktree (13ee428f2) vs this branch:

PYTHONPATH=<tree> python -c "
from types import SimpleNamespace
from gptqmodel.models.base import _needs_deterministic_hessian
from gptqmodel.models.quantization_run_plan import ProcessorStep
for s in ('GPTQ','QQQ','VPTQ','MACAQ','EXL3','FP8_GSQ','AWQ','PARO','WEIGHT_ONLY'):
    print(s, _needs_deterministic_hessian(SimpleNamespace(processors=(getattr(ProcessorStep, s),))))
"
Step before after
GPTQ True True
QQQ False True
VPTQ False True
MACaQ False True
EXL3 False True
FP8_GSQ False True
AWQ / PARO / WEIGHT_ONLY False False

Cross-process, Qwen2.5-0.5B-Instruct, separate processes, every state_dict
tensor hashed, >= 4 runs unless noted:

Method Config Runs before after
QQQ 16 samples 4 490 / 627 (3 distinct checkpoints) 0 / 627
QQQ 32 samples 2 490 / 627 0 / 627
GPTQ 16 samples 4 0 / 795 0 / 963
EXL3 layer 0 4 5-7 / 312 0 / 312
MACaQ 8 samples 4 0 / 795 0 / 795
VPTQ layer 0 4 12-14 / 305 11-12 / 305 (see limitation)

Backend counter on QQQ's add_batch (32 samples, 5376 calls):
Cublaslt before, Cublas (rocBLAS) after.

The GPTQ row's tensor count grows to 963 after merging current main, which
adds the qzeros_format scalar to the checkpoint (#4138); the four merged-tree
runs 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):

Interleaving AWQ vs serial AWQ GPTQ vs serial GPTQ
before, GPTQ starts 5 s in 319 / 627 0 / 795
before, GPTQ starts 25 s in 0 / 627 0 / 795
after, GPTQ starts 5 s in 0 / 627 0 / 795
after, GPTQ starts 25 s in 0 / 627 0 / 795

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

pytest -q tests/test_rocm_quant_tuning.py -k "opt_out or unknown_spelling"
-> 5 passed, 29 deselected

Before: no test existed and ""/0/off/default skipped the pin silently.
After: all four spellings log
"ROCm quantization will not pin rocBLAS (...)", and an unrecognised value
still falls back to rocBLAS without a warning.

Tests

HIP_VISIBLE_DEVICES=0 pytest -q tests/test_rocm_quant_blas.py tests/test_rocm_quant_tuning.py \
  tests/test_rocm_default_env.py tests/test_concurrency_guards.py \
  tests/test_hip_jit_source_staging.py tests/test_awq_triton_scheduler.py
-> 115 passed in 105.28s

tests/test_rocm_default_env.py::test_quantization_is_reproducible_across_processes
now parametrises gptq and qqq (two separate processes each).

CUDA cross-check (mocked suites, GPU-1892aea4):

CUDA_VISIBLE_DEVICES=GPU-1892aea4-cc09-827c-b9a5-93d4eef7f5ae pytest -q \
  tests/test_rocm_quant_blas.py tests/test_rocm_quant_tuning.py \
  tests/test_concurrency_guards.py tests/test_hip_jit_source_staging.py
-> 77 passed

ruff check gptqmodel docs/eora tests setup.py -> All checks passed!

Hardware

  • ROCm: gfx1201 (R9700), HIP_VISIBLE_DEVICES=0, Torch 2.16.0.dev+rocm10.1,
    Python 3.14t.
  • CUDA cross-check: RTX 4090 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 speed
    claim (see below).
  • docs/concurrency.md: documents _QUANT_BLAS_GUARD_TARGET and the
    serialization rule.

The "plausible" items from the issue

  • split-K=1 speed claim was too broad. It wins at M >= 16 with
    K = 2048/4096, but at small M with large K it is 1.2-1.8x slower at
    kernel 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.
  • Stale staged include root: real defect. _stage_hip_sources copied an
    in-checkout include root only if not external.exists(), while
    _cache_fingerprint hashes the staged copy, so a header edit was invisible
    and a stale binary could be reused. Fixed in gptqmodel/utils/cpp.py (refresh
    every 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_batch GEMMs run on Cublas), but its k-means centroid update uses
index_add_ (gptqmodel/quantization/vptq.py:159-162), whose
duplicate-index accumulation is atomic on this stack: five repeats of a bare
index_add_ with duplicate indices produced five distinct results. That is
independent of the BLAS backend and predates #4105 (before: 12-14 differing).
It needs a deterministic segment-sum and is out of scope here.

GPTQModel Bot and others added 4 commits November 15, 2026 11:39
…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.
…ts (#4123)

Current main adds a 0-dim `qzeros_format` scalar to the checkpoint (#4138),
which the cross-process child script could not `view(torch.uint8)`. Flatten
before the view so the scalar is hashed too, and record the merged-tree
confirmation (GPTQ 0/963, QQQ 0/627 over four runs each).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant