[bugfix] Restore attn_tp_rank/size reset in DeepseekV2AttentionMLA when CP enabled#19495
[bugfix] Restore attn_tp_rank/size reset in DeepseekV2AttentionMLA when CP enabled#19495huangzhilin-hzl wants to merge 1 commit intosgl-project:mainfrom
Conversation
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 resolves a critical precision bug affecting the DeepseekV2AttentionMLA model. It reintroduces specific variable initializations that were previously removed, ensuring the correct calculation of local attention heads when prefill optimization with tensor parallelism is enabled. This fix is essential for maintaining the model's accuracy. 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. Changelog
Activity
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 restores the reset of attn_tp_rank and attn_tp_size in DeepseekV2AttentionMLA when context parallelism is enabled. This is a correct bug fix that addresses an issue where num_local_heads was calculated incorrectly, leading to precision problems. The change is small, targeted, and looks good.
|
Can you explain why the accuracy issue only happens on PD + CP cases, and how this fix help with PD? |
Hi @Fridge003 , the issue fixed in the single-node scenario rather than in the PD scenario . When CP is active, each rank must have complete attention heads (attn_tp_size = 1). However, if attn_cp_size is not explicitly provided in the launch arguments and falls back to the default value of 1, it leads to an incorrect computation of attn_tp_size. https://github.com/sgl-project/sglang/blob/main/python/sglang/srt/layers/dp_attention.py#L230 |
Is it right actually? I think after refactoring you can use DP2 ATTN_CP2 ATTN_TP2 configuration for example. I also noticed accuracy problems after refactoring, but they are more likely that when CP is enabled, but without passing the The easiest way to see problems is by running prefill separately and seeing that the first token is always completely random. But since adding of |
Agree. The simplest fix is to explicitly set attn_cp_size. |
Motivation
ref #19483
PR #17213 removed the reset of attn_tp_rank and attn_tp_size when nsa_enable_prefill_cp and use_nsa are True, causing incorrect num_local_heads calculation in DeepseekV2AttentionMLA. Restore the reset to fix ds32 model precision issue.
Modifications
Accuracy Tests
GPU: H20-141GB
pr before
after
case2 Round robin splitting
pr before
after
Benchmarking and Profiling
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci