-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix one bug in the grouped-gemm triton kernel #6772
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 change modifies
scale_a_valueto be loaded using per-token indexing (m_range_start + offs_am[:, None]). This implies that thescale_atensor (which originates fromself.w13_input_scaleorself.w2_input_scaleinlayer.py) is expected to be a 1D tensor containing per-token scale factors.However, there are a few concerns:
scale_ais actually a smaller, per-expert scale tensor (as suggested by its calculation inEPMoE.forwardatlayer.py#L262-L268, where it's derived fromtorch.max(hidden_states)and has shape(num_experts_per_partition,)), then indexing it with global token indices (m_range_start + offs_am) could lead to out-of-bounds memory access, which is a critical issue.a(input to this kernel) must have been quantized using corresponding per-token scales.ais pre-quantized to FP8 bypre_reorder_triton_kernel(as suggested bygateup_inputdtype inlayer.py#L252-L259), thenpre_reorder_triton_kernelmust use per-token scales. However, its current implementation (kernels.py#L163-L173) appears to use per-expert scales (tl.load(scale_a + expert_id_cur_rank)).ais not pre-quantized (e.g., it's bf16/fp16), then this kernel performs the quantization ofain its main loop (aroundkernels.py#L593-L603in the full file). The samescale_a_value(now per-token) would be used for quantizingaand later for dequantizing theaccumulator. This part would be consistent ifscale_ais indeed per-token.Could you clarify the structure of the
scale_atensor in this specific scenario (use_fp8_w8a8 and not (group_k > 0 and group_n > 0)) and ensure that it is compatible with per-token indexing? Ifscale_ais indeed intended to be per-token, the upstream code responsible for computingw13_input_scale/w2_input_scaleand its usage inpre_reorder_triton_kernelmight need adjustments to ensure consistency.