Skip to content

[ExecuTorch][WebGPU] SDPA test suite: replay + dynamic input_pos + in-graph KV cache#20087

Merged
meta-codesync[bot] merged 17 commits into
gh/JulianCloudNTH/20/basefrom
gh/JulianCloudNTH/20/head
Jun 12, 2026
Merged

[ExecuTorch][WebGPU] SDPA test suite: replay + dynamic input_pos + in-graph KV cache#20087
meta-codesync[bot] merged 17 commits into
gh/JulianCloudNTH/20/basefrom
gh/JulianCloudNTH/20/head

Conversation

@JulianCloudNTH

@JulianCloudNTH JulianCloudNTH commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Adds the WebGPU SDPA test coverage as its own diff, stacked on the SDPA op (which already carries the dynamic-input_pos consumption) and the SymInt mechanism below it: multi-step prefill->mt->decode replay, runtime-dynamic input_pos (autoregressive decode), and an in-graph mutable KV cache, each compared against a torch F.scaled_dot_product_attention golden.

  • test/ops/sdpa/test_sdpa.py: ReplaySeq/REPLAY_SEQS + per-step replay export/golden; DynamicSdpaModule + export_dynamic_decode (one .pte, input_pos supplied at runtime as a SymInt); DecodeCacheModule + export_incache_decode (KV cache as register_buffer mutable buffers, so the cache persists in-graph and forward() feeds only the new token + input_pos).
  • test/test_webgpu_native.cpp: test_sdpa_replay, test_sdpa_dynamic_decode (+ negative control: a pinned input_pos diverges), test_sdpa_incache_decode (+ static control: a fresh Module per step diverges, proving in-graph accumulation is real), test_symint_roundtrip, test_resize_hook; shared per-element tolerance sdpa_within_tol (abs 1e-4 OR rel 1e-3).
  • test/test_build_webgpu.sh: export the replay / dynamic / in-graph-cache models for the native test.
    Authored with assistance from Claude.

@exported-using-ghexport

Differential Revision: D107595144

Differential Revision: D107595144

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jun 6, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

⏳ 17 Pending, 1 Unrelated Failure

As of commit a8ed610 with merge base 5526971 (image):

BROKEN TRUNK - The following job 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.

@github-actions

github-actions Bot commented Jun 6, 2026

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.

@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 Jun 6, 2026
@JulianCloudNTH JulianCloudNTH reopened this Jun 9, 2026
[ghstack-poisoned]
JulianCloudNTH added a commit that referenced this pull request Jun 9, 2026
…-graph KV cache

Pull Request resolved: #20087

Adds the WebGPU SDPA test coverage as its own diff, stacked on the SDPA op (which already carries the dynamic-`input_pos` consumption) and the SymInt mechanism below it: multi-step prefill->mt->decode replay, runtime-dynamic `input_pos` (autoregressive decode), and an in-graph mutable KV cache, each compared against a torch `F.scaled_dot_product_attention` golden.

- `test/ops/sdpa/test_sdpa.py`: `ReplaySeq`/`REPLAY_SEQS` + per-step replay export/golden; `DynamicSdpaModule` + `export_dynamic_decode` (one `.pte`, `input_pos` supplied at runtime as a SymInt); `DecodeCacheModule` + `export_incache_decode` (KV cache as `register_buffer` mutable buffers, so the cache persists in-graph and forward() feeds only the new token + `input_pos`).
- `test/test_webgpu_native.cpp`: `test_sdpa_replay`, `test_sdpa_dynamic_decode` (+ negative control: a pinned `input_pos` diverges), `test_sdpa_incache_decode` (+ static control: a fresh Module per step diverges, proving in-graph accumulation is real), `test_symint_roundtrip`, `test_resize_hook`; shared per-element tolerance `sdpa_within_tol` (abs 1e-4 OR rel 1e-3).
- `test/test_build_webgpu.sh`: export the replay / dynamic / in-graph-cache models for the native test.
ghstack-source-id: 391352764
@exported-using-ghexport

Differential Revision: [D107595144](https://our.internmc.facebook.com/intern/diff/D107595144/)
[ghstack-poisoned]
JulianCloudNTH added a commit that referenced this pull request Jun 9, 2026
…-graph KV cache

Pull Request resolved: #20087

Adds the WebGPU SDPA test coverage as its own diff, stacked on the SDPA op (which already carries the dynamic-`input_pos` consumption) and the SymInt mechanism below it: multi-step prefill->mt->decode replay, runtime-dynamic `input_pos` (autoregressive decode), and an in-graph mutable KV cache, each compared against a torch `F.scaled_dot_product_attention` golden.

- `test/ops/sdpa/test_sdpa.py`: `ReplaySeq`/`REPLAY_SEQS` + per-step replay export/golden; `DynamicSdpaModule` + `export_dynamic_decode` (one `.pte`, `input_pos` supplied at runtime as a SymInt); `DecodeCacheModule` + `export_incache_decode` (KV cache as `register_buffer` mutable buffers, so the cache persists in-graph and forward() feeds only the new token + `input_pos`).
- `test/test_webgpu_native.cpp`: `test_sdpa_replay`, `test_sdpa_dynamic_decode` (+ negative control: a pinned `input_pos` diverges), `test_sdpa_incache_decode` (+ static control: a fresh Module per step diverges, proving in-graph accumulation is real), `test_symint_roundtrip`, `test_resize_hook`; shared per-element tolerance `sdpa_within_tol` (abs 1e-4 OR rel 1e-3).
- `test/test_build_webgpu.sh`: export the replay / dynamic / in-graph-cache models for the native test.
ghstack-source-id: 391352764
@exported-using-ghexport

Differential Revision: [D107595144](https://our.internmc.facebook.com/intern/diff/D107595144/)
[ghstack-poisoned]
JulianCloudNTH added a commit that referenced this pull request Jun 9, 2026
…-graph KV cache

Pull Request resolved: #20087

Adds the WebGPU SDPA test coverage as its own diff, stacked on the SDPA op (which already carries the dynamic-`input_pos` consumption) and the SymInt mechanism below it: multi-step prefill->mt->decode replay, runtime-dynamic `input_pos` (autoregressive decode), and an in-graph mutable KV cache, each compared against a torch `F.scaled_dot_product_attention` golden.

- `test/ops/sdpa/test_sdpa.py`: `ReplaySeq`/`REPLAY_SEQS` + per-step replay export/golden; `DynamicSdpaModule` + `export_dynamic_decode` (one `.pte`, `input_pos` supplied at runtime as a SymInt); `DecodeCacheModule` + `export_incache_decode` (KV cache as `register_buffer` mutable buffers, so the cache persists in-graph and forward() feeds only the new token + `input_pos`).
- `test/test_webgpu_native.cpp`: `test_sdpa_replay`, `test_sdpa_dynamic_decode` (+ negative control: a pinned `input_pos` diverges), `test_sdpa_incache_decode` (+ static control: a fresh Module per step diverges, proving in-graph accumulation is real), `test_symint_roundtrip`, `test_resize_hook`; shared per-element tolerance `sdpa_within_tol` (abs 1e-4 OR rel 1e-3).
- `test/test_build_webgpu.sh`: export the replay / dynamic / in-graph-cache models for the native test.
ghstack-source-id: 391373155
@exported-using-ghexport

Differential Revision: [D107595144](https://our.internmc.facebook.com/intern/diff/D107595144/)
[ghstack-poisoned]
JulianCloudNTH added a commit that referenced this pull request Jun 9, 2026
…-graph KV cache

Pull Request resolved: #20087

Adds the WebGPU SDPA test coverage as its own diff, stacked on the SDPA op (which already carries the dynamic-`input_pos` consumption) and the SymInt mechanism below it: multi-step prefill->mt->decode replay, runtime-dynamic `input_pos` (autoregressive decode), and an in-graph mutable KV cache, each compared against a torch `F.scaled_dot_product_attention` golden.

- `test/ops/sdpa/test_sdpa.py`: `ReplaySeq`/`REPLAY_SEQS` + per-step replay export/golden; `DynamicSdpaModule` + `export_dynamic_decode` (one `.pte`, `input_pos` supplied at runtime as a SymInt); `DecodeCacheModule` + `export_incache_decode` (KV cache as `register_buffer` mutable buffers, so the cache persists in-graph and forward() feeds only the new token + `input_pos`).
- `test/test_webgpu_native.cpp`: `test_sdpa_replay`, `test_sdpa_dynamic_decode` (+ negative control: a pinned `input_pos` diverges), `test_sdpa_incache_decode` (+ static control: a fresh Module per step diverges, proving in-graph accumulation is real), `test_symint_roundtrip`, `test_resize_hook`; shared per-element tolerance `sdpa_within_tol` (abs 1e-4 OR rel 1e-3).
- `test/test_build_webgpu.sh`: export the replay / dynamic / in-graph-cache models for the native test.
ghstack-source-id: 391378806
@exported-using-ghexport

Differential Revision: [D107595144](https://our.internmc.facebook.com/intern/diff/D107595144/)
[ghstack-poisoned]
JulianCloudNTH added a commit that referenced this pull request Jun 9, 2026
…-graph KV cache

Pull Request resolved: #20087

Adds the WebGPU SDPA test coverage as its own diff, stacked on the SDPA op (which already carries the dynamic-`input_pos` consumption) and the SymInt mechanism below it: multi-step prefill->mt->decode replay, runtime-dynamic `input_pos` (autoregressive decode), and an in-graph mutable KV cache, each compared against a torch `F.scaled_dot_product_attention` golden.

- `test/ops/sdpa/test_sdpa.py`: `ReplaySeq`/`REPLAY_SEQS` + per-step replay export/golden; `DynamicSdpaModule` + `export_dynamic_decode` (one `.pte`, `input_pos` supplied at runtime as a SymInt); `DecodeCacheModule` + `export_incache_decode` (KV cache as `register_buffer` mutable buffers, so the cache persists in-graph and forward() feeds only the new token + `input_pos`).
- `test/test_webgpu_native.cpp`: `test_sdpa_replay`, `test_sdpa_dynamic_decode` (+ negative control: a pinned `input_pos` diverges), `test_sdpa_incache_decode` (+ static control: a fresh Module per step diverges, proving in-graph accumulation is real), `test_symint_roundtrip`, `test_resize_hook`; shared per-element tolerance `sdpa_within_tol` (abs 1e-4 OR rel 1e-3).
- `test/test_build_webgpu.sh`: export the replay / dynamic / in-graph-cache models for the native test.
ghstack-source-id: 391378806
@exported-using-ghexport

Differential Revision: [D107595144](https://our.internmc.facebook.com/intern/diff/D107595144/)
[ghstack-poisoned]
JulianCloudNTH added a commit that referenced this pull request Jun 9, 2026
…-graph KV cache

Pull Request resolved: #20087

Adds the WebGPU SDPA test coverage as its own diff, stacked on the SDPA op (which already carries the dynamic-`input_pos` consumption) and the SymInt mechanism below it: multi-step prefill->mt->decode replay, runtime-dynamic `input_pos` (autoregressive decode), and an in-graph mutable KV cache, each compared against a torch `F.scaled_dot_product_attention` golden.

- `test/ops/sdpa/test_sdpa.py`: `ReplaySeq`/`REPLAY_SEQS` + per-step replay export/golden; `DynamicSdpaModule` + `export_dynamic_decode` (one `.pte`, `input_pos` supplied at runtime as a SymInt); `DecodeCacheModule` + `export_incache_decode` (KV cache as `register_buffer` mutable buffers, so the cache persists in-graph and forward() feeds only the new token + `input_pos`).
- `test/test_webgpu_native.cpp`: `test_sdpa_replay`, `test_sdpa_dynamic_decode` (+ negative control: a pinned `input_pos` diverges), `test_sdpa_incache_decode` (+ static control: a fresh Module per step diverges, proving in-graph accumulation is real), `test_symint_roundtrip`, `test_resize_hook`; shared per-element tolerance `sdpa_within_tol` (abs 1e-4 OR rel 1e-3).
- `test/test_build_webgpu.sh`: export the replay / dynamic / in-graph-cache models for the native test.
Authored with assistance from Claude.

ghstack-source-id: 391549550
@exported-using-ghexport

Differential Revision: [D107595144](https://our.internmc.facebook.com/intern/diff/D107595144/)
[ghstack-poisoned]
JulianCloudNTH added a commit that referenced this pull request Jun 9, 2026
…-graph KV cache

Pull Request resolved: #20087

Adds the WebGPU SDPA test coverage as its own diff, stacked on the SDPA op (which already carries the dynamic-`input_pos` consumption) and the SymInt mechanism below it: multi-step prefill->mt->decode replay, runtime-dynamic `input_pos` (autoregressive decode), and an in-graph mutable KV cache, each compared against a torch `F.scaled_dot_product_attention` golden.

- `test/ops/sdpa/test_sdpa.py`: `ReplaySeq`/`REPLAY_SEQS` + per-step replay export/golden; `DynamicSdpaModule` + `export_dynamic_decode` (one `.pte`, `input_pos` supplied at runtime as a SymInt); `DecodeCacheModule` + `export_incache_decode` (KV cache as `register_buffer` mutable buffers, so the cache persists in-graph and forward() feeds only the new token + `input_pos`).
- `test/test_webgpu_native.cpp`: `test_sdpa_replay`, `test_sdpa_dynamic_decode` (+ negative control: a pinned `input_pos` diverges), `test_sdpa_incache_decode` (+ static control: a fresh Module per step diverges, proving in-graph accumulation is real), `test_symint_roundtrip`, `test_resize_hook`; shared per-element tolerance `sdpa_within_tol` (abs 1e-4 OR rel 1e-3).
- `test/test_build_webgpu.sh`: export the replay / dynamic / in-graph-cache models for the native test.
Authored with assistance from Claude.

ghstack-source-id: 391549550
@exported-using-ghexport

Differential Revision: [D107595144](https://our.internmc.facebook.com/intern/diff/D107595144/)
[ghstack-poisoned]
JulianCloudNTH added a commit that referenced this pull request Jun 9, 2026
…-graph KV cache

Pull Request resolved: #20087

Adds the WebGPU SDPA test coverage as its own diff, stacked on the SDPA op (which already carries the dynamic-`input_pos` consumption) and the SymInt mechanism below it: multi-step prefill->mt->decode replay, runtime-dynamic `input_pos` (autoregressive decode), and an in-graph mutable KV cache, each compared against a torch `F.scaled_dot_product_attention` golden.

- `test/ops/sdpa/test_sdpa.py`: `ReplaySeq`/`REPLAY_SEQS` + per-step replay export/golden; `DynamicSdpaModule` + `export_dynamic_decode` (one `.pte`, `input_pos` supplied at runtime as a SymInt); `DecodeCacheModule` + `export_incache_decode` (KV cache as `register_buffer` mutable buffers, so the cache persists in-graph and forward() feeds only the new token + `input_pos`).
- `test/test_webgpu_native.cpp`: `test_sdpa_replay`, `test_sdpa_dynamic_decode` (+ negative control: a pinned `input_pos` diverges), `test_sdpa_incache_decode` (+ static control: a fresh Module per step diverges, proving in-graph accumulation is real), `test_symint_roundtrip`, `test_resize_hook`; shared per-element tolerance `sdpa_within_tol` (abs 1e-4 OR rel 1e-3).
- `test/test_build_webgpu.sh`: export the replay / dynamic / in-graph-cache models for the native test.
Authored with assistance from Claude.

ghstack-source-id: 391626190
@exported-using-ghexport

Differential Revision: [D107595144](https://our.internmc.facebook.com/intern/diff/D107595144/)
[ghstack-poisoned]
JulianCloudNTH added a commit that referenced this pull request Jun 9, 2026
…-graph KV cache

Pull Request resolved: #20087

Adds the WebGPU SDPA test coverage as its own diff, stacked on the SDPA op (which already carries the dynamic-`input_pos` consumption) and the SymInt mechanism below it: multi-step prefill->mt->decode replay, runtime-dynamic `input_pos` (autoregressive decode), and an in-graph mutable KV cache, each compared against a torch `F.scaled_dot_product_attention` golden.

- `test/ops/sdpa/test_sdpa.py`: `ReplaySeq`/`REPLAY_SEQS` + per-step replay export/golden; `DynamicSdpaModule` + `export_dynamic_decode` (one `.pte`, `input_pos` supplied at runtime as a SymInt); `DecodeCacheModule` + `export_incache_decode` (KV cache as `register_buffer` mutable buffers, so the cache persists in-graph and forward() feeds only the new token + `input_pos`).
- `test/test_webgpu_native.cpp`: `test_sdpa_replay`, `test_sdpa_dynamic_decode` (+ negative control: a pinned `input_pos` diverges), `test_sdpa_incache_decode` (+ static control: a fresh Module per step diverges, proving in-graph accumulation is real), `test_symint_roundtrip`, `test_resize_hook`; shared per-element tolerance `sdpa_within_tol` (abs 1e-4 OR rel 1e-3).
- `test/test_build_webgpu.sh`: export the replay / dynamic / in-graph-cache models for the native test.
Authored with assistance from Claude.

ghstack-source-id: 391637443
@exported-using-ghexport

Differential Revision: [D107595144](https://our.internmc.facebook.com/intern/diff/D107595144/)
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]

@SS-JIA SS-JIA left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

[ghstack-poisoned]
JulianCloudNTH added a commit that referenced this pull request Jun 12, 2026
…-graph KV cache

Pull Request resolved: #20087

Adds the WebGPU SDPA test coverage as its own diff, stacked on the SDPA op (which already carries the dynamic-`input_pos` consumption) and the SymInt mechanism below it: multi-step prefill->mt->decode replay, runtime-dynamic `input_pos` (autoregressive decode), and an in-graph mutable KV cache, each compared against a torch `F.scaled_dot_product_attention` golden.

- `test/ops/sdpa/test_sdpa.py`: `ReplaySeq`/`REPLAY_SEQS` + per-step replay export/golden; `DynamicSdpaModule` + `export_dynamic_decode` (one `.pte`, `input_pos` supplied at runtime as a SymInt); `DecodeCacheModule` + `export_incache_decode` (KV cache as `register_buffer` mutable buffers, so the cache persists in-graph and forward() feeds only the new token + `input_pos`).
- `test/test_webgpu_native.cpp`: `test_sdpa_replay`, `test_sdpa_dynamic_decode` (+ negative control: a pinned `input_pos` diverges), `test_sdpa_incache_decode` (+ static control: a fresh Module per step diverges, proving in-graph accumulation is real), `test_symint_roundtrip`, `test_resize_hook`; shared per-element tolerance `sdpa_within_tol` (abs 1e-4 OR rel 1e-3).
- `test/test_build_webgpu.sh`: export the replay / dynamic / in-graph-cache models for the native test.
Authored with assistance from Claude.

ghstack-source-id: 393014582
@exported-using-ghexport

Differential Revision: [D107595144](https://our.internmc.facebook.com/intern/diff/D107595144/)
@meta-codesync meta-codesync Bot merged commit 58963cf into gh/JulianCloudNTH/20/base Jun 12, 2026
177 of 180 checks passed
@meta-codesync meta-codesync Bot deleted the gh/JulianCloudNTH/20/head branch June 12, 2026 23:45
@meta-codesync meta-codesync Bot temporarily deployed to cherry-pick-bot June 12, 2026 23:45 Inactive
JulianCloudNTH added a commit that referenced this pull request Jun 13, 2026
…-graph KV cache

Pull Request resolved: #20087

Adds the WebGPU SDPA test coverage as its own diff, stacked on the SDPA op (which already carries the dynamic-`input_pos` consumption) and the SymInt mechanism below it: multi-step prefill->mt->decode replay, runtime-dynamic `input_pos` (autoregressive decode), and an in-graph mutable KV cache, each compared against a torch `F.scaled_dot_product_attention` golden.

- `test/ops/sdpa/test_sdpa.py`: `ReplaySeq`/`REPLAY_SEQS` + per-step replay export/golden; `DynamicSdpaModule` + `export_dynamic_decode` (one `.pte`, `input_pos` supplied at runtime as a SymInt); `DecodeCacheModule` + `export_incache_decode` (KV cache as `register_buffer` mutable buffers, so the cache persists in-graph and forward() feeds only the new token + `input_pos`).
- `test/test_webgpu_native.cpp`: `test_sdpa_replay`, `test_sdpa_dynamic_decode` (+ negative control: a pinned `input_pos` diverges), `test_sdpa_incache_decode` (+ static control: a fresh Module per step diverges, proving in-graph accumulation is real), `test_symint_roundtrip`, `test_resize_hook`; shared per-element tolerance `sdpa_within_tol` (abs 1e-4 OR rel 1e-3).
- `test/test_build_webgpu.sh`: export the replay / dynamic / in-graph-cache models for the native test.
Authored with assistance from Claude.

ghstack-source-id: 393014582
@exported-using-ghexport

Differential Revision: [D107595144](https://our.internmc.facebook.com/intern/diff/D107595144/)
JulianCloudNTH added a commit that referenced this pull request Jun 13, 2026
…-graph KV cache (#20260)

This PR was created by the merge bot to help merge the original PR into
the main branch.
ghstack PR number: #20087 by
@JulianCloudNTH
^ 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/JulianCloudNTH/20/base
ghstack PR head:
https://github.com/pytorch/executorch/tree/gh/JulianCloudNTH/20/head
Merge bot PR base:
https://github.com/pytorch/executorch/tree/gh/JulianCloudNTH/19/orig
Merge bot PR head:
https://github.com/pytorch/executorch/tree/gh/JulianCloudNTH/20/orig

@diff-train-skip-merge

---------

Co-authored-by: Julian Ng-Thow-Hing <juliannth@meta.com>
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. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants