-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[BugFix] replace the input_to_float8 used in dsv2 #11612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Liu-congo <[email protected]>
Summary of ChangesHello @Liu-congo, 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 provides a targeted fix for a persistent CI failure in the Highlights
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.
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 addresses a bug related to per_tensor_quant_mla_fp8 with newer versions of cublas by conditionally creating a new tensor instead of using a BumpAllocator. The changes look correct and are consistent with the problem description.
I've identified some code duplication that could be refactored to improve maintainability. Please see my detailed comments below.
| q_nope_val, q_nope_scale = per_tensor_quant_mla_fp8( | ||
| q_nope.transpose(0, 1), | ||
| ( | ||
| torch.zeros((1,), dtype=torch.float32, device=q_nope.device) | ||
| if _is_cublas_ge_129 | ||
| else zero_allocator.allocate(1) | ||
| ), | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block of code for quantization is duplicated in forward_absorb_core (lines 1726-1733). To improve maintainability and reduce code duplication, consider extracting this logic into a helper method within the DeepseekV2AttentionMLA class.
For example, you could create a method like this:
def _quantize_for_bmm_fp8(self, x: torch.Tensor, zero_allocator: BumpAllocator):
return per_tensor_quant_mla_fp8(
x.transpose(0, 1),
(
torch.zeros((1,), dtype=torch.float32, device=x.device)
if _is_cublas_ge_129
else zero_allocator.allocate(1)
),
)Then you can replace the duplicated blocks with:
q_nope_val, q_nope_scale = self._quantize_for_bmm_fp8(q_nope, zero_allocator)
and
attn_output_val, attn_output_scale = self._quantize_for_bmm_fp8(attn_output, zero_allocator)
respectively.
| attn_output_val, attn_output_scale = per_tensor_quant_mla_fp8( | ||
| attn_output.transpose(0, 1), | ||
| ( | ||
| torch.zeros((1,), dtype=torch.float32, device=attn_output.device) | ||
| if _is_cublas_ge_129 | ||
| else zero_allocator.allocate(1) | ||
| ), | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@Fridge003 hello, could you please help to review the pr? many thanks |
Motivation
this pr is a follow-up for #11272 and #11360
in previous pr, i fix the ci failure using input_to_float8, after some further exploration, i find that the failure is caused by the improvement in #5549
the function was first proposed in #5370 ,
in it's raw implementation:it create a "x_s = torch.zeros((1,), dtype=torch.float32, device=x.device)" when being called. x_s is the scaling factor for the input matrix, also the B_scale in bmm_fp8
then in #5549, it introduce a bumpallocator to allocate buffer beforehand to enhance throughput, however it caused the ci failure in test/srt/test_mla_fp8 under cublas12.9
Changes
the lastest fix(#11360) for #11272 is adding version check for cublas12.9, and replace the per_tensor_quant_mla_fp8 with input_to_float8 if needed
now, i deprecated the input_to_float8 function. Substitute the 'zero_allocator.allocate(1)' with 'torch.zeros((1,), dtype=torch.float32, device=x.device)'.
i think the root cause of #11272 lies in cublas, but i'm not quite familiar with that : (, waiting for help to solve the issue throughly.
Minimal Script to reproduce the issue in #11272
the following script can reproduce the issue easily.
a core thing is that if the loop body executes only once, the bmm_fp8 function can work normally, however when it executes more than once, it would throw exception 'RuntimeError: bmm_fp8_internal_cublaslt failed: the requested functionality is not supported'. So far, i think it might have something to do with the pointer of q_nope_scale.
Tests
Checklist