Skip to content

WebGPU: Add indirect dispatch for flash attention graph capture#29236

Draft
feich-ms wants to merge 1 commit into
mainfrom
user/feich/gemma4_webgpu_gc_support
Draft

WebGPU: Add indirect dispatch for flash attention graph capture#29236
feich-ms wants to merge 1 commit into
mainfrom
user/feich/gemma4_webgpu_gc_support

Conversation

@feich-ms

Copy link
Copy Markdown
Contributor

Summary

  • Adds PrepareIndirectDispatchProgram to compute dispatch group sizes on GPU from seqlen_k when total_sequence_length is unavailable on CPU
  • Extends indirect dispatch to kv_empty layers (shared KV layers where total_sequence_length_=0 would cause dispatch(0) crashes)
  • Enables graph capture for models with dynamic sequence lengths (e.g., Gemma4), achieving ~25% decode throughput improvement on WebGPU

Changes

  • flash_attention.cc: New PrepareIndirectDispatchProgram::GenerateShaderCode, expanded use_seqlen_k and use_indirect_dispatch conditions, added indirect buffer preparation for kv_empty path
  • flash_attention.h: Added PrepareIndirectDispatchProgram class declaration

Test plan

  • Verified with Gemma4 INT4 model: ~95-105 tok/s with GC=ON vs ~75 tok/s with GC=OFF
  • Tested multiple prompts (short/long) with graph capture enabled — no crashes, correct output
  • Verified warmup (capture run) followed by replay produces consistent results

🤖 Generated with Claude Code

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant