Fix CUDA stream race in CuteDSL MoE when CUDA graphs are disabled#2840
Fix CUDA stream race in CuteDSL MoE when CUDA graphs are disabled#2840leejnau wants to merge 1 commit intoflashinfer-ai:mainfrom
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can validate your CodeRabbit configuration file in your editor.If your editor has YAML language server, you can enable auto-completion and validation by adding |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a potential CUDA stream race condition within the CuteDSL MoE wrapper when CUDA graphs are disabled. The core change involves making the use of asynchronous Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request effectively addresses the CUDA stream race condition in CuteDSL MoE when CUDA graphs are disabled. The changes correctly gate the creation and usage of async memset resources (auxiliary stream and events) to only occur when CUDA graphs are enabled and pre-allocated buffers are utilized. This prevents unnecessary resource allocation and potential race conditions in non-graph scenarios, aligning with the stated objective of the pull request. The modifications to both the CuteDslMoEWrapper and the functional API _cute_dsl_fused_moe_nvfp4_impl are consistent and logical, ensuring that async memset is only employed when an auxiliary stream is available and intended for use. The added comments enhance code clarity regarding these conditional behaviors.
📌 Description
Gate async memset on CUDA graph mode in the CuteDSL MoE wrapper. When CUDA graphs are enabled, the same pre-allocated moe_output buffer is reused on every graph replay, so zeroing it on a dedicated per-instance auxiliary stream overlaps with GEMM1 and hides the cost. When CUDA graphs are disabled, buffers are allocated dynamically each call and don't need async zeroing — a synchronous .zero_() on the main stream is sufficient and avoids a race condition where multiple MoE layers would share the module-level singleton stream from _get_cuda_graph_resources().
The fix moves stream and event creation from _allocate_buffers() into the if use_cuda_graph: block of init, so non-graph wrappers never create CUDA stream resources they don't need. The functional API (_cute_dsl_fused_moe_nvfp4_impl) is similarly updated to only use async memset when the caller provides an explicit auxiliary stream.
🔍 Related Issues
feat: cuteDSL fp4 moe for better DSR1 performance.
chore: cute dsl nvfp4 moe clean up
CuteDSL MoE fix redundant output buffer zeroing
🚀 Pull Request Checklist
Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.
✅ Pre-commit Checks
pre-commitby runningpip install pre-commit(or used your preferred method).pre-commit install.pre-commit run --all-filesand fixed any reported issues.🧪 Tests
unittest, etc.).Reviewer Notes