Skip to content

fix(exllamav2): serialize the cold native q-matrix rebuild; #4184 review dispositions - #4361

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4184-review-findings
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4184-review-findings

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4184

Disposition

Every finding in the issue body is listed below. I verified each against
current origin/main (4818ae7c2) before acting.

# Finding Disposition Evidence
1 GGUF K-quants never use llama.cpp's quantizer; fallback fits min/max and uses the unrounded fp32 super-scale DEFERRED Still present: nn_modules/qlinear/gguf.py:869 tries gguf-py, then _fallback_gguf_quantize (:655), then _ggml_native_quantize (:704); _quantize_k_subblocks (:477) still has no make_qkx2_quants search. Fixing it means implementing the ggml search and re-qualifying K-quant MSE/bytes; not a minor change. The issue's MSE numbers were not re-measured here.
2 ExllamaV2Linear._ensure_q_handle has no lock; concurrent first forwards build and leak native q-matrices FIXED Added _Q_HANDLE_REBUILD_LOCK and a double-checked cold rebuild in nn_modules/qlinear/exllamav2.py; clear_weight_cache takes the same lock. Regression: tests/test_kernel_dispatch_caching.py::test_exllamav2_concurrent_first_forward_builds_one_handle (8 threads, one native build; fails pre-fix).
3 W4A-NVFP4 keeps an expanded weight copy (_weight_b) next to the INT4 qweight ALREADY-FIXED-UPSTREAM #3492 (41f7ba845) removed the dense E4M3 _weight_e4m3 cache. The remaining _weight_both is two packed E2M1 planes (0.5 B/weight each, 1 B/weight total), an alternate packed layout explicitly allowed by AGENTS.md, not a dense expansion. The issue's _weight_b name/lines are stale.
4 VPTQ enable_norm=True, norm_dim=0 uses H instead of D·H·D for error feedback ALREADY-FIXED-UPSTREAM #4327 (82ab6f1e8) builds pass_hessian = H * D * D^T when enable_norm and norm_dim == 0, and passes it to both _vptq_pass calls (quantization/vptq.py).
5 HIP include staging is recopied outside the cross-process build lock DEFERRED Still present: _stage_hip_sources copies at utils/cpp.py:1236 (copytree ~:1304, :1332), while _load computes build_root() at :1996 before taking _cross_process_build_lock at :2000; loadable_without_build (:1688) also stages outside it. A correct fix needs the fingerprint/staging under the lock in both paths, or an atomic staging protocol; naive nesting risks flock re-entrancy deadlock.
6 ROCm quant-BLAS serialisation blocks up to 1800 s, then proceeds on the wrong backend; still env-driven DEFERRED Still present: _QUANT_BLAS_GUARD_WAIT_SECONDS = 1800.0 (utils/rocm.py:301) and GPTQMODEL_ROCM_QUANT_BLAS / ROCBLAS_USE_HIPBLASLT (:120, :129). The wait-then-warn fallback is the deliberate #4123 tradeoff; migrating the env switches to config is a separate behavior change (AGENTS.md).
7 Wider eager fallback masks compiler-frame errors ALREADY-FIXED-UPSTREAM #4327 (82ab6f1e8) narrowed _is_compiler_failure (utils/torch.py) to compiler-owned RuntimeError or dynamo's guard AssertionError; other compiler-frame errors propagate.
8 lm_head=True on a tied model under offload_to_disk=True crashes with a meta-tensor copy instead of the tied-head refusal ALREADY-FIXED-UPSTREAM #4327 (82ab6f1e8) added _config_declares_tied_embeddings and a _tied_weights_keys check to _lm_head_is_tied (looper/module_looper.py), so the explicit refusal fires even when the checkpoint stores lm_head.weight.
9 Text-only calibration of a model with a second layer stack (vision tower, MTP) raises DEFERRED Still present: looper/stage_inputs_capture.py:568 raises when a declared branch is not reached, and _auto_detect_module_tree (models/loader.py:1671) still returns every stack. Deciding which branches a modality can exercise is model-definition/calibration policy, not a minor fix. Static path confirmed; the model-specific repro was not re-run.
10 GPTQ scales narrowed fp16 → bf16 on load and republished by save_pretrained ALREADY-FIXED-UPSTREAM #4327 (82ab6f1e8) restores scales from the checkpoint dtype for every BaseQuantLinear in utils/model.py (AWQ also keeps bias).
11a Saved meta publishes the local offload_to_disk_path ALREADY-FIXED-UPSTREAM #4327 (82ab6f1e8) removed offload_to_disk_path from meta_payload in quantization/config.py; legacy checkpoints still read it.
11b Index total_size counts file bytes including headers ALREADY-FIXED-UPSTREAM #4327 (82ab6f1e8) sums entry.num_bytes in streaming_state_dict_to_shards (utils/model.py).
11c max_shard_size="4GB" is parsed as GiB ALREADY-FIXED-UPSTREAM #4327 (82ab6f1e8) made _parse_max_shard_size treat KB/MB/GB as decimal and KiB/MiB/GiB as binary (bare K/M/G keeps the historical binary meaning).
12 _uniform_column_group lru_cache returns one CUDA tensor filled on the creating thread's stream ALREADY-FIXED-UPSTREAM #4327 (82ab6f1e8) added _uniform_column_group_stream and keys the cache by the current CUDA stream (quantization/gptq.py).

Change

Only finding 2 was still an actionable small bug. The diff adds a module-level
_Q_HANDLE_REBUILD_LOCK and a double-checked fast path to
ExllamaV2Linear._ensure_q_handle; clear_weight_cache takes the same lock.
Steady-state forwards keep the existing lock-free fast path.

The regression test starts eight threads behind a barrier against a fake layer
whose ext_make_q_matrix sleeps; it asserts exactly one native build and one
shared handle. It fails on the pre-fix code (more than one build) and passes
with the fix.

Verification

  • ruff check gptqmodel docs/eora tests setup.py -> All checks passed!
  • pytest tests/test_kernel_dispatch_caching.py -q -> 20 passed
  • pytest tests/test_kernel_dispatch_caching.py tests/test_kernel_audit_regressions.py tests/test_exllamav2_jit.py -q -> 108 passed
  • Pre-fix check: the new test fails with assert len(made) == 1.
  • CPU-only; no GPU used.

Residual risk

  • AwqExllamaV2Linear._ensure_q_handle (qlinear/exllamav2_awq.py) has the
    same unlocked cold-rebuild pattern. It is outside the issue's finding (which
    names ExllamaV2Linear) and its rebuild also repacks the AWQ tensors, so it
    deserves its own lock and test. Not changed here to keep the diff scoped.
  • The deferred findings above are unchanged by this PR.

Eight free-threaded workers forwarding after clear_weight_cache() each entered _ensure_q_handle's slow path and built their own native q-matrix; seven leaked. Add a module-level rebuild lock with a double-checked fast path, and take the same lock in clear_weight_cache so a release cannot race a publish. Steady-state forwards keep the lock-free fast path.

This is the only finding from #4184 that is still an actionable small bug on current main; the others were already fixed by #4327/#3492 or need larger work and are deferred in the PR disposition table.
@Qubitium
Qubitium merged commit f77d24d into main Nov 16, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/issue-4184-review-findings branch November 16, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Minor findings from a full-repo review (7.11.0 @ 6c3421c)

1 participant