Repository navigation
fix(qqq): allocate the split-K lock array per forward call (#4665) - #4717
Merged
Merged
Conversation
`qqq_gemm.cu` spins on and resets the counters in its `workspace` argument, so one lock array per `QQQLinear` let two streams serving the same module increment and reset each other's counters; the kernel never completed and the device had to be reset. The per-call reduce scratch from #4626 covered only `C`, and the docs' "stream-safe by construction" claim did not hold for this second writable buffer. `QQQLinear._split_k_locks(device)` allocates a zeroed `ceil(out_features / 64) * max_par` INT32 array for each forward, matching EXL3's per-call locks (#4645). The registered `workspace` buffer stays only so existing checkpoints keep loading; the kernel no longer reads it. Tests: `tests/kernels/test_qqq_workspace.py::test_forward_allocates_a_fresh_lock_array_per_call` fails on unmodified main (both calls receive the same tensor) and asserts two distinct zeroed arrays of the kernel's size. QQQ suites: 280 passed, 65 skipped, 1 pre-existing `test_qqq_export_scale` tolerance failure also present on main. The CUDA concurrency repro needs two GPUs and is not runnable here.
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.
Summary
Fixes #4665.
qqq_gemm.cuuses itsworkspaceargument as the split-K barrier: each CTA spins inbarrier_acquire, increments a per-tile counter, and resets it inbarrier_release. The array was one buffer perQQQLinear, so two streams serving the same module (always the same layers) incremented and reset each other's counters; the kernel never completed and the device sat at 100% until the process was killed. #4626 madeCper-call, but the docs' "stream-safe by construction" claim did not cover this second writable buffer.Change
QQQLinear._split_k_locks(device)allocates a zeroedceil(out_features / 64) * max_parINT32 array for each forward and passes it tomul. This matches EXL3'sexl3_gemm, which allocates its locks per call (#4645). The registeredworkspacebuffer is kept only so existing checkpoints keep loading; the kernel no longer reads it. The array is a few hundred int32 slots, so the per-call allocation is negligible next to the kernel call.docs/kernel-scratch-lifecycle.mdgains a "QQQ split-K lock array" section.workspacebufferTests
tests/kernels/test_qqq_workspace.py::test_forward_allocates_a_fresh_lock_array_per_call(new): callsQQQLinear.forwardtwice with the kernel intercepted and asserts the twoworkspacearguments are distinct objects, neither is the module buffer, and both are zeroed INT32 arrays of_workspace_numel(out_features, max_par). Fails on unmodifiedmain(both calls receive the same tensor).QQQ suites (
test_qqq_workspace,test_qlinear_hierarchy,test_inference_numeric_range,test_qqq_jit,test_qqq_uncaptured_fallback_4468,test_qqq_export_scale): 280 passed, 65 skipped, 1 pre-existingtest_qqq_export_scaletolerance failure also present onmain.ruff checkclean.Not verified here: the two-stream CUDA deadlock repro needs two GPUs on this CPU-only host; the test asserts the aliasing property that caused it.
Resolves #4665.