Repository navigation
ggml-cuda: honor view_offs in cpy data pointer - #22913
Closed
dusterbloom wants to merge 1 commit into
Closed
dusterbloom wants to merge 1 commit into
dusterbloom wants to merge 1 commit into
Conversation
ggml_cuda_cpy() was using src->data raw, ignoring view_offs. For a
destination tensor created via ggml_view_3d at non-zero offset (e.g.,
the per-chunk SWA KV cache write at offset cache_k->nb[1]*kv_start),
the kernel wrote to the wrong location, silently overwriting earlier
chunks' data.
Add a small ggml_cuda_cpy_data() helper that resolves view_src + view_offs
correctly, and use it for both src0 and src1 pointers. For non-view
tensors view_offs == 0 so behavior is unchanged.
Symptom this fixes: multi-chunk Gemma4 prefill produced silently corrupted
KV cache state, causing argmax to return token 0 (or NaN propagation +
SIGSEGV on TQ3_0). Diagnosed by stashing/reverting and confirming chunk-1
writes were landing at the wrong offset.
Co-discovered with the OpenAI Codex assistant ("codex:rescue" handoff).
Closed
5 of 6 tasks
|
Hi @dusterbloom, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
Contributor
|
Create an issue with a reproduction first |
Contributor
|
The logic here is fundamentally wrong. Don't just submit hallucinated "fixes". |
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
ggml_cuda_cpy()was usingsrc->dataraw, ignoringview_offs. For a destination tensor created viaggml_view_3dat non-zero offset (e.g., a per-chunk SWA KV cache write at offsetcache_k->nb[1] * kv_start), the kernel wrote to the wrong location, silently overwriting earlier chunks' data.This patch adds a small
ggml_cuda_cpy_data()helper that resolvesview_src + view_offscorrectly, and uses it for bothsrc0andsrc1pointers. For non-view tensorsview_offs == 0so behavior is unchanged.Symptom this fixes
Multi-chunk Gemma4 prefill produced silently corrupted KV cache state, causing argmax to return token 0 (or NaN propagation + SIGSEGV on TQ3_0). Diagnosed by stashing/reverting and confirming chunk-1 writes were landing at the wrong offset.
Diff scope
ggml/src/ggml-cuda/cpy.cu— 6 lines added, 2 removed (one new helper + two call-site swaps)Applies cleanly on current
master.Test plan
masterview_offs == 0preserves the old code path)This is a generic bugfix surfaced by long-context prefill with chunked attention; happy to add a regression test if you have a preferred place for one.