[GH-ISSUE #4] test_core.py ref_out and out Inconsistent accuracy #1

Closed
opened 2026-10-26 21:09:55 +00:00 by bsakaguchi · 10 comments
Owner

Originally created by @ttanzhiqiang on GitHub (Feb 26, 2025).
Original GitHub issue: https://github.com/deepseek-ai/DeepGEMM/issues/4

Image
Originally created by @ttanzhiqiang on GitHub (Feb 26, 2025). Original GitHub issue: https://github.com/deepseek-ai/DeepGEMM/issues/4 <img width="722" alt="Image" src="https://github.com/user-attachments/assets/22eb011c-c2d7-4ac9-b46c-d4f135fb42a6" />
Author
Owner

@LyricZhao commented on GitHub (Feb 26, 2025):

Can you print the diff (using the calc_diff function) of the two tensors? Normally the diff should be around 0.0007 (ref_out is computed with BF16, out is with FP8).

<!-- gh-comment-id:2684015961 --> @LyricZhao commented on GitHub (Feb 26, 2025): Can you print the diff (using the `calc_diff` function) of the two tensors? Normally the diff should be around 0.0007 (`ref_out` is computed with BF16, out is with FP8).
Author
Owner

@ttanzhiqiang commented on GitHub (Feb 26, 2025):

using the calc_diff function
Image

Does it mean that the output of the fp8 function is not one-to-one corresponding to the fp16 output, but focuses on the sum result? Is it because the loss calculation is the sum result, so this method is used?

<!-- gh-comment-id:2684026432 --> @ttanzhiqiang commented on GitHub (Feb 26, 2025): using the calc_diff function <img width="730" alt="Image" src="https://github.com/user-attachments/assets/450f3c6a-ebcd-4669-93b4-ea2c495014a1" /> Does it mean that the output of the fp8 function is not one-to-one corresponding to the fp16 output, but focuses on the sum result? Is it because the loss calculation is the sum result, so this method is used?
Author
Owner

@LyricZhao commented on GitHub (Feb 26, 2025):

Does it mean that the output of the fp8 function is not one-to-one corresponding to the fp16 output, but focuses on the sum result? Is it because the loss calculation is the sum result, so this method is used?

Yes. We normally use this diff function or MSE as precision reference. FP8 and BF16 naturally have numeric precision issues.

<!-- gh-comment-id:2684031633 --> @LyricZhao commented on GitHub (Feb 26, 2025): > Does it mean that the output of the fp8 function is not one-to-one corresponding to the fp16 output, but focuses on the sum result? Is it because the loss calculation is the sum result, so this method is used? Yes. We normally use this diff function or MSE as precision reference. FP8 and BF16 naturally have numeric precision issues.
Author
Owner

@ttanzhiqiang commented on GitHub (Feb 26, 2025):

That means that in inference, fp8 and fp16 outputs need to correspond one to one. Is it not possible to use this method and use sglang(https://github.com/sgl-project/sglang) solution instead?

<!-- gh-comment-id:2684047303 --> @ttanzhiqiang commented on GitHub (Feb 26, 2025): That means that in inference, fp8 and fp16 outputs need to correspond one to one. Is it not possible to use this method and use sglang(https://github.com/sgl-project/sglang) solution instead?
Author
Owner

@LyricZhao commented on GitHub (Feb 26, 2025):

For model inference, you do not need binary-level precision even if the model weights are BF16/FP16, but in such cases, this may lead to LLM benchmark accuracy drops (similar to model quantization). So it is totally doable to integrate into SGLang.

BTW, DeepSeek-V3 models are natively FP8 trained without such concerns. This repo mainly supports V3/R1, for some detailed customization, you may need extra efforts :)

<!-- gh-comment-id:2684062996 --> @LyricZhao commented on GitHub (Feb 26, 2025): For model inference, you do not need binary-level precision even if the model weights are BF16/FP16, but in such cases, this may lead to LLM benchmark accuracy drops (similar to model quantization). So it is totally doable to integrate into SGLang. BTW, DeepSeek-V3 models are natively FP8 trained without such concerns. This repo mainly supports V3/R1, for some detailed customization, you may need extra efforts :)
Author
Owner

@Maximilianxu commented on GitHub (Feb 26, 2025):

@LyricZhao I found that when per_group_size is smaller than 128, the output is wrong. The case is:

num_groups, m, n, k = 64, 64, 1024, 8192
<!-- gh-comment-id:2684076417 --> @Maximilianxu commented on GitHub (Feb 26, 2025): @LyricZhao I found that when `per_group_size` is smaller than 128, the output is wrong. The case is: ```Python num_groups, m, n, k = 64, 64, 1024, 8192 ```
Author
Owner

@ttanzhiqiang commented on GitHub (Feb 26, 2025):

@LyricZhao thanks for your reply

<!-- gh-comment-id:2684105399 --> @ttanzhiqiang commented on GitHub (Feb 26, 2025): @LyricZhao thanks for your reply
Author
Owner

@zheanxu commented on GitHub (Feb 26, 2025):

@Maximilianxu Please refer to the doc of m_grouped_gemm_fp8_fp8_bf16_nt_contiguous

link

On the M axis, inputs are grouped into several batches, of which batch sizes aligned to get_m_alignment_for_contiguous_layout() (128).

<!-- gh-comment-id:2684146011 --> @zheanxu commented on GitHub (Feb 26, 2025): @Maximilianxu Please refer to the doc of `m_grouped_gemm_fp8_fp8_bf16_nt_contiguous` [link](https://github.com/deepseek-ai/DeepGEMM/blob/main/deep_gemm/jit_kernels/m_grouped_gemm.py#L44) > On the M axis, inputs are grouped into several batches, of which batch sizes aligned to `get_m_alignment_for_contiguous_layout()` (128).
Author
Owner

@Maximilianxu commented on GitHub (Feb 26, 2025):

@Maximilianxu Please refer to the doc of m_grouped_gemm_fp8_fp8_bf16_nt_contiguous

link

On the M axis, inputs are grouped into several batches, of which batch sizes aligned to get_m_alignment_for_contiguous_layout() (128).

I didn't see the alignment requirements for the API with mask. But it still fails.

<!-- gh-comment-id:2684168909 --> @Maximilianxu commented on GitHub (Feb 26, 2025): > [@Maximilianxu](https://github.com/Maximilianxu) Please refer to the doc of `m_grouped_gemm_fp8_fp8_bf16_nt_contiguous` > > [link](https://github.com/deepseek-ai/DeepGEMM/blob/main/deep_gemm/jit_kernels/m_grouped_gemm.py#L44) > > > On the M axis, inputs are grouped into several batches, of which batch sizes aligned to `get_m_alignment_for_contiguous_layout()` (128). I didn't see the alignment requirements for the API with mask. But it still fails.
Author
Owner

@zheanxu commented on GitHub (Feb 26, 2025):

@Maximilianxu Thank you for your feedback! The problem occurs when expected_m exceeds m in the case of m=64. I'll submit a fix for this shortly.

<!-- gh-comment-id:2684302158 --> @zheanxu commented on GitHub (Feb 26, 2025): @Maximilianxu Thank you for your feedback! The problem occurs when `expected_m` exceeds `m` in the case of `m=64`. I'll submit a fix for this shortly.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepGEMM#1
No description provided.