Skip to content

Add split-K mid-M SDPA Triton kernel for EAGLE-3 target_verify at long context#20344

Draft
digantdesai wants to merge 1 commit into
gh/digantdesai/62/headfrom
gh/digantdesai/63/head
Draft

Add split-K mid-M SDPA Triton kernel for EAGLE-3 target_verify at long context#20344
digantdesai wants to merge 1 commit into
gh/digantdesai/62/headfrom
gh/digantdesai/63/head

Conversation

@digantdesai

Copy link
Copy Markdown
Contributor

EAGLE-3 verify is a target forward over M = chain+1 query rows. On gemma4-31B's
full-attention (global) layers the standard SDPA scans the whole max_seq_len KV
buffer on a (B, H) grid -- one CTA per head looping the key range serially -- so
at long context the verify attention is occupancy-starved and grows ~linearly
with context, dominating the round and turning speculative decoding into a net
loss; the M query rows otherwise ride along for free on the same K/V read.

This adds a length-bounded split-K mid-M SDPA path for that case. The Triton
kernel (backends/cuda/triton/kernels/sdpa_midm.py) bounds the key range to the
valid length and partitions it across CTAs with a split-K online-softmax plus
cross-split reduce (the flash-decoding trick), with sdpa.py-style guards for
tiles a row's causal mask empties. Gemma4_31B gains opt-in dispatch
(set_midm_sdpa): full-attention layers route verify windows with M in
[2, MIDM_MAX_M] through the kernel, while sliding-window, prefill, decode, and
other models stay on F.sdpa. The valid KV length reaches the kernel as the
length of a new target_verify kv_window input (a backed SymInt); export wires it
up behind --no-midm-sdpa and the runner feeds it each round. Verify global
attention then stays ~flat with context instead of growing.

Because kv_window's shape changes every round, target_verify can no longer be
captured as a CUDA graph, so the runner's --cuda_graph now defaults off.

Lossless: byte-identical to baseline greedy except rare near-tie argmax flips
(M=chain+1 verify vs M=1 decode FP non-associativity; the same prompts flip
without this kernel). Unit coverage in backends/cuda/tests/test_sdpa_midm.py.
Benchmarks need the 31B checkpoints + A100 + a long-context export, so they run
out of CI and are not kept in this message.

Authored with assistance from Claude Code.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 3 New Failures, 1 Cancelled Job, 1 Unrelated Failure, 5 Unclassified Failures

As of commit 37fc965 with merge base dc55469 (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

CANCELLED JOB - The following job was cancelled. Please retry:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant