support deepseekv3.2-piecewise-cuda-graph - #18094
Conversation
Summary of ChangesHello @BJWang-ant, 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 significantly enhances support for DeepSeekV3.2 models by integrating them with the piecewise CUDA graph compilation framework. The core objective is to optimize the model's attention and Mixture-of-Experts (MoE) layers for efficient execution on GPUs. This involves adapting data handling, introducing new custom operations for graph compatibility, and refining conditional execution logic to ensure high performance and stability within the CUDA graph environment. 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for deepseekv3.2-piecewise-cuda-graph. The changes primarily involve making the model compatible with torch.compile and piecewise CUDA graph execution. This is achieved by replacing dynamic control flow with torch.cond, wrapping model components in custom operators, and adjusting data types and operations for compilation.
Overall, the changes are in the right direction. I've found a critical typo that needs to be fixed and some opportunities for code cleanup and refactoring to improve maintainability. Please see my detailed comments.
| for layer in self.model.model.layers: | ||
| if hasattr(layer, "self_attn"): | ||
| if hasattr(layer.self_attn, "attn"): | ||
| self.attention_layers.append(layer.self_attn.attn) | ||
| elif hasattr(layer.self_attn, "attn_mqa"): | ||
| # For DeepSeek model | ||
| self.attention_layers.append(layer.self_attn.attn_mqa) | ||
| elif hasattr(layer.self_attn, "indexer "): |
There was a problem hiding this comment.
There appears to be a typo in the attribute name check. It's "indexer " with a trailing space, which will likely cause hasattr to fail and prevent indexer_layers from being collected correctly. It should be "indexer".
| elif hasattr(layer.self_attn, "indexer "): | |
| elif hasattr(layer.self_attn, "indexer"): |
| # due to piecewise-cudagraph,so move | ||
| # if self.qkv_latent_func is not None: | ||
| # attn_inputs = AttentionInputs( | ||
| # hidden_states, forward_batch, self.qkv_latent_func | ||
| # ) | ||
| # get_attn_tp_context().set_attn_inputs(attn_inputs) |
| @@ -743,7 +743,7 @@ def biased_grouped_topk_gpu( | |||
| experts_per_group = ( | |||
| num_experts // num_expert_group if num_expert_group else num_experts | |||
| ) | |||
|
|
|||
| fused_topk_deepseek = None | |||
There was a problem hiding this comment.
The line fused_topk_deepseek = None unconditionally disables the fused_topk_deepseek optimization path below, making the following if block dead code. If this is a permanent change, please remove this line and the unreachable if block. If this is temporary, please add a TODO comment explaining why it's disabled and when it might be re-enabled.
| # if get_moe_a2a_backend().is_deepep() or get_moe_a2a_backend().is_mooncake(): | ||
| # # TODO(yuwei): fix the compilation errors for MOE A2A backend | ||
| # log_info_on_rank0( | ||
| # logger, | ||
| # "Disable piecewise CUDA graph due to existing compilation errors", | ||
| # ) | ||
| # return False |
| if ( | ||
| forward_batch.forward_mode.is_extend() | ||
| and get_forward_context() is not None | ||
| ): | ||
| topk_indices = torch.empty( | ||
| (hidden_states.shape[0], 2048), | ||
| dtype=torch.int32, | ||
| device=hidden_states.device, | ||
| ) | ||
| nas_indexer_forward_cus( | ||
| layer_id=self.layer_id, | ||
| hidden_states=hidden_states, | ||
| q_lora=q_lora, | ||
| positions=positions, | ||
| return_indices=True, | ||
| output=topk_indices, | ||
| ) | ||
| else: | ||
| topk_indices = self.indexer( | ||
| x=hidden_states, | ||
| q_lora=q_lora, | ||
| positions=positions, | ||
| forward_batch=forward_batch, | ||
| layer_id=self.layer_id, | ||
| ) |
|
Hi @BJWang-ant are you still working on this issue ? |
yes, I am working it.Most of the work on PCG has been completed, and currently, some tests on accuracy and performance are being carried out normally. |
|
@BJWang-ant Hi are u still working on it? we may collaborate on this since the support for nsa is needed now |
yes, I am working on it. I can first push some code up. Under this commit, it can currently be run through. However, in the PD separation mode, there are still issues with the accuracy. Currently, I'm still trying to identify the cause of the accuracy problem and haven't come up with any good solutions yet. |
2ae08bf to
46101c7
Compare
|
@BJWang-ant Let's support it on non-pd scenario firstly. Also if you are in sgl slack let's dm on it. |
In the non-padding scenario, the accuracy has been achieved. |
OK.I contact you |
46101c7 to
cfdf170
Compare
I have rebased the code onto the latest commit of the repository.Perhaps you could work together to look into the issue of accuracy. |
c7c7048 to
60c6574
Compare
|
I attempted to perform PD separation using a non-DP-attention method, but still encountered mismatches. Moreover, in this case, the non-PCG also showed mismatches. prefill: |
|
@BJWang-ant I see you are using Could you try remove |
|
@BJWang-ant Hello, I thikn this feature is working in main, it's covered by #23351 |




Motivation
Modifications
support deepseekv3.2-piecewise-cuda-graph
Accuracy Tests
Benchmarking and Profiling
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci