Skip to content

vulkan: fix missing view-alias dependencies in ggml_vk_graph_optimize - #27812

Merged
0cc4m merged 3 commits into
ggml-org:masterfrom
Eric-A-Stalee:vulkan-optimizer-missing-deps
Aug 28, 2026
Merged

vulkan: fix missing view-alias dependencies in ggml_vk_graph_optimize#27812
0cc4m merged 3 commits into
ggml-org:masterfrom
Eric-A-Stalee:vulkan-optimizer-missing-deps

Conversation

@Eric-A-Stalee

Copy link
Copy Markdown
Contributor

Overview

Fixes #27805

is_src_of in ggml_vk_graph_optimize checks whether one node depends on another before the optimizer reorders them. It knows two cases: a node depends on its direct inputs, and two views of the same tensor share memory. It misses a third case: a node that reads or writes memory through one view depends on a node that writes or reads the same memory through a different view. The optimizer can then run those two nodes in the wrong order.

Result: wrong tokens at temperature 0, a different answer on every server start, and speculative-decoding acceptance numbers that mean nothing. Nothing is written to the log.

Found with the DFlash 2 verify graph from #27342, which does not touch ggml-vulkan.cpp. Any model that keeps state in views is exposed (Qwen3.8's recurrent state where I encountered it). AMD and NVIDIA Vulkan affected; CUDA on the same NVIDIA GPU is not.

Fix: compare the underlying tensor (view_src) on both sides of the check, in addition to the existing tests.

Additional information

Verified 12/12 fresh runs match the no-speculation output on RTX 5000 (Vulkan) and RX 7800 XT, where the unpatched build gave 4 distinct outputs and 0/12 matches. Plain and MTP output unchanged.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES. The investigation, instrumentation and reproducer scripts were AI-assisted (Claude Fable 5 & GPT 5.6 Sol); the diff was validated by me on my own hardware (NVIDIA and AMD) and I wrote this PR.

is_src_of doesn't treat two views of one tensor as dependent, so the optimizer reorders nodes across aliased reads and writes. 

Result: silently wrong tokens under greedy decoding, different output on every server start, and invalid speculative-decoding acceptance, with nothing logged.

Hits Qwen3.8's recurrent state (and any model with view-aliased state) on AMD and NVIDIA Vulkan.  CUDA is clean. 

Compare view_src bases on both sides.

Fixes ggml-org#27805
@Eric-A-Stalee
Eric-A-Stalee requested a review from a team as a code owner August 27, 2026 15:38
@github-actions github-actions Bot added Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning labels Aug 27, 2026
Comment thread ggml/src/ggml-vulkan/ggml-vulkan.cpp
Eric-A-Stalee and others added 2 commits August 28, 2026 12:53
Nodes whose op is NONE, RESHAPE, TRANSPOSE, VIEW or PERMUTE execute nothing, so aliasing through them is not a real dependency. The previous base comparison matched them anyway, which only costs the optimizer reordering freedom.

Co-authored-by: Jeff Bolz <jbolz@nvidia.com>
…c_of

Code will not compile without these changes.  
is_src_of has an empty capture list, so is_empty was not visible inside it, and is_empty took a non-const pointer, while is_src_of receives const ones. Other call sites pass non-const pointers, which still convert as usual.
@0cc4m
0cc4m merged commit b387ddf into ggml-org:master Aug 28, 2026
27 of 29 checks passed
jbooth pushed a commit to jbooth/llama.cpp that referenced this pull request Aug 30, 2026
…ggml-org#27812)

* vulkan: fix missing view-alias dependencies in ggml_vk_graph_optimize

is_src_of doesn't treat two views of one tensor as dependent, so the optimizer reorders nodes across aliased reads and writes. 

Result: silently wrong tokens under greedy decoding, different output on every server start, and invalid speculative-decoding acceptance, with nothing logged.

Hits Qwen3.8's recurrent state (and any model with view-aliased state) on AMD and NVIDIA Vulkan.  CUDA is clean. 

Compare view_src bases on both sides.

Fixes ggml-org#27805

* vulkan: don't treat view/no-op nodes as aliasing dependencies

Nodes whose op is NONE, RESHAPE, TRANSPOSE, VIEW or PERMUTE execute nothing, so aliasing through them is not a real dependency. The previous base comparison matched them anyway, which only costs the optimizer reordering freedom.

Co-authored-by: Jeff Bolz <jbolz@nvidia.com>

* vulkan: make the lambda parameter const and capture is_empty in is_src_of

Code will not compile without these changes.  
is_src_of has an empty capture list, so is_empty was not visible inside it, and is_empty took a non-const pointer, while is_src_of receives const ones. Other call sites pass non-const pointers, which still convert as usual.

---------

Co-authored-by: Jeff Bolz <jbolz@nvidia.com>
Nathanw1014 pushed a commit to Nathanw1014/llama.cpp that referenced this pull request Aug 31, 2026
…ggml-org#27812)

* vulkan: fix missing view-alias dependencies in ggml_vk_graph_optimize

is_src_of doesn't treat two views of one tensor as dependent, so the optimizer reorders nodes across aliased reads and writes.

Result: silently wrong tokens under greedy decoding, different output on every server start, and invalid speculative-decoding acceptance, with nothing logged.

Hits Qwen3.8's recurrent state (and any model with view-aliased state) on AMD and NVIDIA Vulkan.  CUDA is clean.

Compare view_src bases on both sides.

Fixes ggml-org#27805

* vulkan: don't treat view/no-op nodes as aliasing dependencies

Nodes whose op is NONE, RESHAPE, TRANSPOSE, VIEW or PERMUTE execute nothing, so aliasing through them is not a real dependency. The previous base comparison matched them anyway, which only costs the optimizer reordering freedom.

Co-authored-by: Jeff Bolz <jbolz@nvidia.com>

* vulkan: make the lambda parameter const and capture is_empty in is_src_of

Code will not compile without these changes.
is_src_of has an empty capture list, so is_empty was not visible inside it, and is_empty took a non-const pointer, while is_src_of receives const ones. Other call sites pass non-const pointers, which still convert as usual.

---------

Co-authored-by: Jeff Bolz <jbolz@nvidia.com>
(cherry picked from commit b387ddf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eval bug: Vulkan graph optimizer silently corrupts output for models with view-aliased state

3 participants