fix the case where the buffer for past_state == present_state#28753
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a WebGPU/Dawn validation issue that occurs when past_state and present_state alias the same underlying buffer, which previously caused the same buffer to be bound twice with incompatible access modes (RO input + RW output). The fix avoids dual-binding by re-routing reads to the output binding (when safe) and, for causal conv, splitting state update into a follow-up dispatch when in-place aliasing is detected.
Changes:
- LinearAttention: when
past_statealiasespresent_state, stop bindinginitial_stateas an input and instead read the initial state frompresent_statein the shader. - CausalConvWithState: when
conv_statealiasespresent_state, skip writingpresent_statein the main convolution shader and run a second shader dispatch to update state in-place. - Extend shader template parameters / cache hints to account for the new aliasing modes and generated shader variants.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/contrib_ops/webgpu/bert/linear_attention.wgsl.template | Adds a template-controlled path to load the initial state from present_state when buffers alias. |
| onnxruntime/contrib_ops/webgpu/bert/linear_attention.h | Extends LinearAttentionProgram to carry the aliasing flag into shader generation. |
| onnxruntime/contrib_ops/webgpu/bert/linear_attention.cc | Detects aliasing, adjusts bindings, and adds the new template parameter and cache hint component. |
| onnxruntime/contrib_ops/webgpu/bert/causal_conv_with_state.wgsl.template | Wraps present_state writes with a template flag so it can be disabled when aliasing would cause RO/RW dual-bind. |
| onnxruntime/contrib_ops/webgpu/bert/causal_conv_with_state.h | Adds an output_present_state flag to the main program and introduces a dedicated update-state program. |
| onnxruntime/contrib_ops/webgpu/bert/causal_conv_with_state.cc | Detects aliasing, conditionally omits present_state output binding, and runs a second dispatch to update state when needed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
apsonawane
approved these changes
Jun 2, 2026
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.
in the case we pass the same buffer for past_state and present_state, dawn complains about the buffer bound as input/RO and the same buffer being bound as output/RW.