Repository navigation
llama: fix k-pool scatter data race on shared sequences - #29994
Merged
ServeurpersoCom merged 3 commits intoOct 6, 2026
Merged
Conversation
With shared cells every pool is re-pooled, and since the pooled keys are always scattered, the pools a seq_cp shares between sequences wrote the same rep row from several scatter entries, a data race on the CPU backend. Mark each rep once: the sharing sequences read the same row through pool_cells.
The recurrent state is always copied whole whatever the range, and a k-pool cell shared by a partial copy could carry two pool groupings with a single pooled row. Every caller copies whole sequences, so reject partial ranges instead of supporting them.
am17an
reviewed
Oct 5, 2026
am17an
left a comment
Contributor
There was a problem hiding this comment.
we should try and remove this cache_safe logic. It's just not intuitive in any way.
Contributor
Author
I'm going it in a 3rd commit. Look like the assertion in the second commit make cache_safe obsolete! |
With whole-sequence seq_cp, sequences sharing cells share their pools too, so the pooled row of a shared rep is valid for all of them. Mark each rep once in every ubatch instead of re-pooling everything while cells are shared, which removes the sharing scan and the stale-all workarounds in seq_rm, state_read and state_drop. seq_cp now only stales the destination.
Contributor
Author
|
Pushed: cache_safe, the sharing scan and the stale-all workarounds in seq_rm, state_read and state_drop are gone, each rep is pooled once per ubatch and seq_cp only stales the destination. Shared vs unshared decode match after seq_cp (CPU and CUDA), TSan clean on glm5-next and qwen4exp. |
am17an
approved these changes
Oct 6, 2026
ggerganov
approved these changes
Oct 6, 2026
3 of 5 tasks
gagallo7
pushed a commit
to tetherto/qvac-fabric-llm.cpp
that referenced
this pull request
Oct 14, 2026
* llama: re-pool each shared k-pool rep once With shared cells every pool is re-pooled, and since the pooled keys are always scattered, the pools a seq_cp shares between sequences wrote the same rep row from several scatter entries, a data race on the CPU backend. Mark each rep once: the sharing sequences read the same row through pool_cells. * llama: assert whole-sequence seq_cp in the hybrid idx memory The recurrent state is always copied whole whatever the range, and a k-pool cell shared by a partial copy could carry two pool groupings with a single pooled row. Every caller copies whole sequences, so reject partial ranges instead of supporting them. * llama: drop the k-pool cache_safe mode With whole-sequence seq_cp, sequences sharing cells share their pools too, so the pooled row of a shared rep is valid for all of them. Mark each rep once in every ubatch instead of re-pooling everything while cells are shared, which removes the sharing scan and the stale-all workarounds in seq_rm, state_read and state_drop. seq_cp now only stales the destination. (cherry picked from commit 43fe9c6) [ dropped qwen4exp.cpp, comment-only. ] Assisted-by: Claude Opus 5.5
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Oct 24, 2026
… on shared sequences
auRose94
pushed a commit
to auRose94/llama.cpp
that referenced
this pull request
Oct 28, 2026
* llama: re-pool each shared k-pool rep once With shared cells every pool is re-pooled, and since the pooled keys are always scattered, the pools a seq_cp shares between sequences wrote the same rep row from several scatter entries, a data race on the CPU backend. Mark each rep once: the sharing sequences read the same row through pool_cells. * llama: assert whole-sequence seq_cp in the hybrid idx memory The recurrent state is always copied whole whatever the range, and a k-pool cell shared by a partial copy could carry two pool groupings with a single pooled row. Every caller copies whole sequences, so reject partial ranges instead of supporting them. * llama: drop the k-pool cache_safe mode With whole-sequence seq_cp, sequences sharing cells share their pools too, so the pooled row of a shared rep is valid for all of them. Mark each rep once in every ubatch instead of re-pooling everything while cells are shared, which removes the sharing scan and the stale-all workarounds in seq_rm, state_read and state_drop. seq_cp now only stales the destination.
1 task
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.
Overview
The k-pool models write their pooled keys back even when sequences share cells after a seq_cp, so a shared pool was written twice from different threads, which TSan flags in test_shared_seq_reserve.
First commit re-pools each shared pool once, second commit asserts that seq_cp copies whole sequences, since a partial copy cannot work with shared pools.
TSan is clean on glm5-next and qwen4exp.
Additional information
Follow-up #29958
Requirements