Skip to content

[Vulkan] Add the off-graph flat KV cache and update_and_attend op - #22036

Open
kiymetakdemir wants to merge 1 commit into
pytorch:mainfrom
kiymetakdemir:vulkan-offgraph-kv-cache
Open

[Vulkan] Add the off-graph flat KV cache and update_and_attend op#22036
kiymetakdemir wants to merge 1 commit into
pytorch:mainfrom
kiymetakdemir:vulkan-offgraph-kv-cache

Conversation

@kiymetakdemir

@kiymetakdemir kiymetakdemir commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Adds the off-graph KV cache to the Vulkan backend, behind the neutral kvcache::update_and_attend op. The cache is runtime state the host installs before the graph is built; it owns one buffer pool per layer for K and one for V, and the op function wraps them using the external-storage path. Pools are buffers.

Added the missing shader variants — [texture3d, buffer] for the SDPA shaders and [buffer, texture3d] for the cache update so a buffer pool works inside the default texture-storage graph.

sdpa_impl asserted scale was None and then hardcoded 1/sqrt(head_dim). The op contract makes scale a required float, so it now uses the supplied value when there is one.

Files

  • backends/vulkan/runtime/graph/VulkanCache.h — graph-facing interface: pool shape, dtype, layer count, pool buffers.
  • backends/vulkan/runtime/graph/VulkanSequenceCache.h — the byte layer; allocates pools at construction from the global context. Flat layers only.
  • backends/vulkan/runtime/graph/ComputeGraph.h — the installed cache, set before the graph is built.
  • backends/vulkan/runtime/graph/ops/impl/SDPA.cppupdate_and_attend_impl, and scale in sdpa_impl.
  • backends/vulkan/runtime/graph/ops/glsl/sdpa_*.{glsl,yaml} — the missing storage-type variants.
  • backends/vulkan/test/op_tests/sdpa_test.cppOFFGRAPH mode.

Testing

vulkan_sdpa_testOFFGRAPH runs through the existing driver, so it covers all four configurations and both storage types: prefill, single-token decode, mid-sequence chunks, four GQA ratios and four head dims, each step compared against the ATen reference.

cc @SS-JIA @manuelcandales @digantdesai @cbilgin

@kiymetakdemir kiymetakdemir self-assigned this Aug 21, 2026
@kiymetakdemir
kiymetakdemir requested a review from SS-JIA as a code owner August 21, 2026 21:24
@pytorch-bot pytorch-bot Bot added the module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/ label Aug 21, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22036

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 6 Unrelated Failures

As of commit 275e70d with merge base 2c88f57 (image):

NEW FAILURE - The following job has failed:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 21, 2026
@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant