mirror of
https://github.com/kvcache-ai/Mooncake.git
synced 2026-11-05 01:17:55 +00:00
[GH-ISSUE #2087] [Question]: Does Mooncake EP currently support CUDA Graph at all? #571
Labels
No labels
ascend
auto-closed
bug
bug
CI/Build
Common
documentation
enhancement
feature request
good first issue
help wanted
high priority
MetaX
nightly-failure
pull-request
PyTorch Backend
question
RFC
Roadmap
stale
Store
Tests
Transfer Engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/Mooncake#571
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Socratesa on GitHub (May 12, 2026).
Original GitHub issue: https://github.com/kvcache-ai/Mooncake/issues/2087
Originally assigned to: @UNIDY2002 on GitHub.
Bug Report
I've been studying the Mooncake EP source code and plan to integrate it into a custom MoE inference engine. I have a question about CUDA Graph compatibility.
Looking at mooncake_ep_buffer.cpp, each dispatch() / combine() call allocates temporary tensors like packed_recv_x, packed_recv_src_info, packed_recv_count via torch::empty() (L248-L259), and in async mode creates CUDA Events for cross-stream synchronization (L306 EventHandle(launch_stream)).
I also noticed that the Python-level EventOverlap class has already introduced extra_tensors as a workaround, with comments noting:
stream recording will be incompatible with CUDA graph we use extra tensors to simulate PyTorch tensor record_stream, may be useful with CUDA graph
A few questions:
Before submitting...
@UNIDY2002 commented on GitHub (May 13, 2026):
Hi @Socratesa, thanks for the detailed analysis. Mooncake EP does work with CUDA graph — this is the primary production path in SGLang and has been tested. Your concerns are valid but depend on which flags are used.
Regarding each point:
torch::empty()allocations: PyTorch patches the CUDA caching allocator duringtorch.cuda.graph()capture to use the graph's private memory pool. Since decode has a fixed token count, the allocation sizes are consistent across replays.CUDA Events for cross-stream synchronization: This only happens when
return_recv_hook=False, wheredispatch()/combine()use a separatecomm_streamand callstream_wait()(which involvescudaEventRecord+cudaStreamWaitEvent). Whenreturn_recv_hook=True,launch_stream = compute_stream(the same stream being captured), and no cross-stream synchronization occurs.extra_tensors: Your understanding is correct — it serves the same purpose asrecord_stream()and happens to be compatible with CUDA graph since it doesn't rely on the stream recording mechanism.The key is using the right flags. For CUDA graph capture, you should set:
return_recv_hook=True— keeps all kernel launches on the compute stream (the one being captured)async_finish=False— required whenreturn_recv_hook=True(enforced by an assert in the C++ code)@github-actions[bot] commented on GitHub (Aug 12, 2026):
This issue has had no activity for 90 days and will be closed in 7 days if there is no further activity. Please comment or react if it should stay open.
@github-actions[bot] commented on GitHub (Aug 19, 2026):
Closing due to 3 months of inactivity. If this is still relevant, please comment and we can reopen.