Skip to content

Ragged prefill wrapper - #203

Open
NSagan271 wants to merge 7 commits into
mainfrom
feat/ragged-flashinfer-wrapper
Open

Ragged prefill wrapper#203
NSagan271 wants to merge 7 commits into
mainfrom
feat/ragged-flashinfer-wrapper

Conversation

@NSagan271

@NSagan271 NSagan271 commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Addresses an issue found during the review of #150: neither engine has support for a ragged attention flashinfer wrapper (needed to cuda-graph ragged attention), meaning that the encoder submodule had to do all of the plumbing for flashinfer ragged attention planing itself.

This PR adds an engine-provided AttentionState, which is analogous to the BatchedCacheManager, except it only has functions plan and run, and is not tied to a static KV cache (e.g., for one-time encoding attention). Submodules declare whether they need ragged attention support via a new BaseSubmodule method get_ragged_attention_config. Right now, only the stateless engine, its corresponding cuda graph runner, and the piecewise cudagraph runner can provide and AttentionState, but it would be simple to migrate the KV cache engine as well.

How was it tested?

A lot of unit tests from Claude.

Migrated BAGEL ViT encoder, benchmarked T2I on coriander and checked outputs were correct + that throughput increased slightly with cuda graphs.

Checklist

  • ruff check . passes
  • Added or updated tests / docs where relevant

NSagan271 and others added 5 commits August 2, 2026 23:51
Covers both stateless runners end-to-end: a graph captured once per bucket,
re-planned before each replay against a different varlen layout with the
segment count padded out by zero-length segments. Checked against a
per-segment SDPA reference at head_dim=72 so the head-dim padding is in the
loop too.

Also pins the contract edges: capture-fns that predate ragged attention must
not receive static_attn, a bucket that captured ragged attention must reject
a replay with no cu_seqlens rather than replay a stale plan, and a config
without max_segments_per_request skips the capture instead of failing it.

Docs get the two capture bounds, the segment-vs-request distinction, and the
plan-outside/run-inside rule with the seam each runner provides.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@NSagan271 NSagan271 changed the title [Draft] ragged prefill wrapper Ragged prefill wrapper Aug 3, 2026
@NSagan271
NSagan271 requested a review from t-avil August 3, 2026 06:52

@t-avil t-avil left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Might be worth filing a ticket for the KVcache support.

Was able to integrate #150 (Qwen-omni) on top of this; benchmarking the integrated version on local basically shows no degradations. I will wait for this pr to merge; then will rebase #150

@NSagan271
NSagan271 marked this pull request as ready for review August 4, 2026 17:38
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.

2 participants