Skip to content

[Fix] Record the WAR read-done event in-graph to cover replay-time metadata reads - #31686

Closed
hnyls2002 wants to merge 4 commits into
mainfrom
lsyin/trtllm-read-done
Closed

hnyls2002 wants to merge 4 commits into
mainfrom
lsyin/trtllm-read-done

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

trtllm_mha's fused in-graph metadata kernel re-reads the live req_to_token / full->SWA mapping on every graph replay -- after the WAR fastpath's pre-replay read-done event was recorded -- so scheduler-side writes could overwrite them mid-replay. Record the read-done event as an external-event node inside the captured graph at the snapshot-completion point (for backends with a no-op in-graph hook the node sits at the graph head, preserving today's semantics), with a new backend capability falling back to post-replay recording where in-graph capture is unavailable.


CI States

Latest PR Test (Base): 🚫 Run #29707770973
Latest PR Test (Extra): ❌ Run #29707770880

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces an in-graph WAR-barrier read-done event mechanism for CUDA graphs. This allows backends whose captured metadata kernels index live shared buffers on every replay (such as trtllm_mha) to record the event inside the graph right after the metadata hook, ensuring correct synchronization. It adds the in_graph_metadata_reads_shared_buffers property across attention backends and updates DecodeCudaGraphRunner and EagleDraftExtendCudaGraphRunner to plant and manage this in-graph event. The review feedback suggests catching AttributeError in addition to TypeError when initializing the WAR-barrier read-done event to prevent potential crashes in environments where device_module does not have an Event attribute.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread python/sglang/srt/model_executor/runner/decode_cuda_graph_runner.py Outdated
@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

war_policy = self._war_read_done_policy(
self.draft_extend_attn_backend, forward_batch.forward_mode
)
if war_policy == "pre_replay":

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.

nit: maybe we could introduce a WarReadDonePolicy enum to avoid literal string

@hnyls2002 hnyls2002 closed this Aug 17, 2026
@hnyls2002
hnyls2002 deleted the lsyin/trtllm-read-done branch August 17, 2026 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants