[ET-VK] Fix embedding_q4gsw out-of-bounds access with dynamic shapes#18584
Merged
[ET-VK] Fix embedding_q4gsw out-of-bounds access with dynamic shapes#18584
Conversation
The embedding_q4gsw shader used push constants for num_indices, out_height, and embed_dim that were captured at graph build time and never updated when input tensors were dynamically resized. This caused out-of-bounds GPU memory reads when the actual input was smaller than the initial allocation, resulting in VK_ERROR_DEVICE_LOST on Mali GPUs. The fix derives all shape-dependent values (embed_dim, out_height, num_indices) from the output tensor's sizes UBO, which is automatically updated on resize. Only truly constant values (group_size, is_linear_weight) remain as push constants. Root cause: With a 7-token input on a graph built for 256 tokens, the local workgroup rounding created an extra thread (y=7) that passed the stale bounds check (7 >= 256 == false) and read past the 7-element indices buffer. Differential Revision: [D98642319](https://our.internmc.facebook.com/intern/diff/D98642319/) ghstack-source-id: 359350851 Pull Request resolved: #18558
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18584
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 137 PendingAs of commit 8b709dd with merge base 24751f1 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
SS-JIA
approved these changes
Mar 30, 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.
This PR was created by the merge bot to help merge the original PR into the main branch.
ghstack PR number: #18558 by @SS-JIA
^ Please use this as the source of truth for the PR details, comments, and reviews
ghstack PR base: https://github.com/pytorch/executorch/tree/gh/SS-JIA/513/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/513/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/main
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/513/orig
Differential Revision: D98642319
@diff-train-skip-merge