Repository navigation
fix(exllamav2): serialize the cold native q-matrix rebuild; #4184 review dispositions - #4361
Merged
Merged
Conversation
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.
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 #4184
Disposition
Every finding in the issue body is listed below. I verified each against
current
origin/main(4818ae7c2) before acting.nn_modules/qlinear/gguf.py:869tries gguf-py, then_fallback_gguf_quantize(:655), then_ggml_native_quantize(:704);_quantize_k_subblocks(:477) still has nomake_qkx2_quantssearch. 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.ExllamaV2Linear._ensure_q_handlehas no lock; concurrent first forwards build and leak native q-matrices_Q_HANDLE_REBUILD_LOCKand a double-checked cold rebuild innn_modules/qlinear/exllamav2.py;clear_weight_cachetakes 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)._weight_b) next to the INT4 qweight41f7ba845) removed the dense E4M3_weight_e4m3cache. The remaining_weight_bothis 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_bname/lines are stale.enable_norm=True, norm_dim=0uses H instead of D·H·D for error feedback82ab6f1e8) buildspass_hessian = H * D * D^Twhenenable_normandnorm_dim == 0, and passes it to both_vptq_passcalls (quantization/vptq.py)._stage_hip_sourcescopies atutils/cpp.py:1236(copytree ~:1304,:1332), while_loadcomputesbuild_root()at:1996before taking_cross_process_build_lockat: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._QUANT_BLAS_GUARD_WAIT_SECONDS = 1800.0(utils/rocm.py:301) andGPTQMODEL_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).82ab6f1e8) narrowed_is_compiler_failure(utils/torch.py) to compiler-ownedRuntimeErroror dynamo's guardAssertionError; other compiler-frame errors propagate.lm_head=Trueon a tied model underoffload_to_disk=Truecrashes with a meta-tensor copy instead of the tied-head refusal82ab6f1e8) added_config_declares_tied_embeddingsand a_tied_weights_keyscheck to_lm_head_is_tied(looper/module_looper.py), so the explicit refusal fires even when the checkpoint storeslm_head.weight.looper/stage_inputs_capture.py:568raises 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.save_pretrained82ab6f1e8) restoresscalesfrom the checkpoint dtype for everyBaseQuantLinearinutils/model.py(AWQ also keepsbias).metapublishes the localoffload_to_disk_path82ab6f1e8) removedoffload_to_disk_pathfrommeta_payloadinquantization/config.py; legacy checkpoints still read it.total_sizecounts file bytes including headers82ab6f1e8) sumsentry.num_bytesinstreaming_state_dict_to_shards(utils/model.py).max_shard_size="4GB"is parsed as GiB82ab6f1e8) made_parse_max_shard_sizetreatKB/MB/GBas decimal andKiB/MiB/GiBas binary (bareK/M/Gkeeps the historical binary meaning)._uniform_column_grouplru_cachereturns one CUDA tensor filled on the creating thread's stream82ab6f1e8) added_uniform_column_group_streamand 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_LOCKand a double-checked fast path toExllamaV2Linear._ensure_q_handle;clear_weight_cachetakes 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_matrixsleeps; it asserts exactly one native build and oneshared 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 passedpytest tests/test_kernel_dispatch_caching.py tests/test_kernel_audit_regressions.py tests/test_exllamav2_jit.py -q-> 108 passedassert len(made) == 1.Residual risk
AwqExllamaV2Linear._ensure_q_handle(qlinear/exllamav2_awq.py) has thesame unlocked cold-rebuild pattern. It is outside the issue's finding (which
names
ExllamaV2Linear) and its rebuild also repacks the AWQ tensors, so itdeserves its own lock and test. Not changed here to keep the diff scoped.