Add FlashInfer provider for moe_quant_group_gemm across BF16, FP8, MXFP4, and NVFP4#1
Draft
Copilot wants to merge 5 commits into
Draft
Add FlashInfer provider for moe_quant_group_gemm across BF16, FP8, MXFP4, and NVFP4#1Copilot wants to merge 5 commits into
moe_quant_group_gemm across BF16, FP8, MXFP4, and NVFP4#1Copilot wants to merge 5 commits into
Conversation
Agent-Logs-Url: https://github.com/yupengzh-intel/ByteMLPerf/sessions/c103b54c-1dd7-414e-b1f6-b53aece4822e Co-authored-by: yupengzh-intel <[email protected]>
Agent-Logs-Url: https://github.com/yupengzh-intel/ByteMLPerf/sessions/c103b54c-1dd7-414e-b1f6-b53aece4822e Co-authored-by: yupengzh-intel <[email protected]>
Agent-Logs-Url: https://github.com/yupengzh-intel/ByteMLPerf/sessions/c103b54c-1dd7-414e-b1f6-b53aece4822e Co-authored-by: yupengzh-intel <[email protected]>
Agent-Logs-Url: https://github.com/yupengzh-intel/ByteMLPerf/sessions/c103b54c-1dd7-414e-b1f6-b53aece4822e Co-authored-by: yupengzh-intel <[email protected]>
Copilot
AI
changed the title
[WIP] Implement FlashInfer provider for moe_quant_group_gemm operation
Add FlashInfer provider for May 21, 2026
moe_quant_group_gemm across BF16, FP8, MXFP4, and NVFP4
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
moe_quant_group_gemmpreviously only had the base loop-based implementation that simulated grouped expert GEMM one expert at a time. This change adds a FlashInfer-backed provider that maps the existing MoE dispatch metadata onto single grouped kernel launches for BF16, FP8 per-tensor, FP8 block-scale, MXFP4, and NVFP4 variants.FlashInfer provider
projects/micro_perf/vendor_ops/GPU/ops/flashinfer/moe_quant_group_gemm.pyflashinfervendor implementation formoe_quant_group_gemmSupported dtype variants
flashinfer.grouped_mm_bf16flashinfer.grouped_mm_fp8(..., alpha=...)flashinfer.gemm.group_gemm_fp8_nt_groupwiseflashinfer.gemm.group_gemm_mxfp4_nt_groupwiseflashinfer.gemm.group_gemm_nvfp4_nt_groupwiseMoE routing integration
expert_dispatch_token_count/expert_dispatch_token_offsetfromget_moe_tokens_info()m_indptr/segment_offsetsdirectly from the existing expert dispatch layoutTensor metadata / allocation
Runtime dispatch
vendor_impl_run()Example dispatch shape mapping:
Original prompt
Overview
Implement a FlashInfer-based provider for the
moe_quant_group_gemmoperation in the xpu-perf benchmark framework. The implementation should support the following data types:flashinfer.grouped_mm_bf16flashinfer.grouped_mm_fp8with per-tensor alphaflashinfer.gemm.group_gemm_fp8_nt_groupwisewith block-wise scalingflashinfer.gemm.group_gemm_mxfp4_nt_groupwiseflashinfer.gemm.group_gemm_nvfp4_nt_groupwiseContext
The existing base implementation is in
projects/micro_perf/op_defs/llm_ops/moe_quant_group_gemm.py. It uses a Python loop over experts withfake_quant_gemmto simulate INT8 group GEMM. The new FlashInfer implementation should replace this loop with a single FlashInfer kernel call for each data type variant.Reference: Base Implementation Structure
The base class
MoeQuantGroupGemmOpinprojects/micro_perf/op_defs/llm_ops/moe_quant_group_gemm.py:prepare_args()to parse MoE parameters (num_tokens, hidden_size, new_hidden_size, num_experts, topk, ep_size, etc.)get_moe_tokens_info()to compute routing/dispatch metadatavendor_impl()to define input/output tensor info and set up the computationvendor_impl_run(tensor_mapping)to execute the actual GEMMImplementation Requirements
Create a new file at
projects/micro_perf/op_defs/llm_ops/moe_quant_group_gemm_flashinfer.pythat:Registers a FlashInfer provider using
@ProviderRegistry.register_provider_impl("moe_quant_group_gemm", "FlashInfer")decorator pattern.Inherits from the base
MoeQuantGroupGemmOpclass and overridesvendor_parser(),vendor_impl(), andvendor_impl_run().Supports multiple dtype configurations dispatched by
self.dtype,self.w_dtype,self.compute_dtype,self.dst_dtype:BF16:
dtype=bfloat16, w_dtype=bfloat16, dst_dtype=bfloat16flashinfer.grouped_mm_bf16(a, b, m_indptr, out_dtype=...)ashape:(dispatch_tokens, hidden_size)bf16bshape:(num_experts_per_rank, new_hidden_size, hidden_size)bf16m_indptrshape:(num_experts_per_rank + 1,)int32, built fromexpert_dispatch_token_offsetFP8 per-tensor:
dtype=fp8_e4m3, w_dtype=fp8_e4m3, compute_dtype=fp8, dst_dtype=bfloat16flashinfer.grouped_mm_fp8(a, b, m_indptr, alpha=alpha, out_dtype=...)ashape:(dispatch_tokens, hidden_size)float8_e4m3fnbshape:(num_experts_per_rank, new_hidden_size, hidden_size)float8_e4m3fnalpha: scalar float32 tensor (per-tensor scale)FP8 block scale:
dtype=fp8_e4m3, w_dtype=fp8_e4m3, compute_dtype=fp8_block, dst_dtype=bfloat16flashinfer.gemm.group_gemm_fp8_nt_groupwise(a, b, a_scale, b_scale, segment_offsets, out=...)ashape:(dispatch_tokens, hidden_size)float8_e4m3fnbshape:(num_experts_per_rank, new_hidden_size, hidden_size)float8_e4m3fna_scaleshape:(hidden_size // 128, dispatch_tokens)float32b_scaleshape:(num_experts_per_rank, hidden_size // 128, new_hidden_size // 128)float32segment_offsetsshape:(num_experts_per_rank + 1,)int32MXFP4:
dtype=mxfp4, w_dtype=mxfp4, compute_dtype=mxfp4, dst_dtype=bfloat16flashinfer.gemm.group_gemm_mxfp4_nt_groupwise(a, b, a_scale, b_scale, segment_offsets, out=...)ashape:(dispatch_tokens, hidden_size)float8_e4m3fn (activation in fp8 for mxfp4 kernel)bshape:(num_experts_per_rank, new_hidden_size, hidden_size // 2)uint8 (packed fp4)a_scaleshape:(dispatch_tokens_aligned // 128, hidden_size // 32)uint8b_scaleshape:(num_experts_per_rank, new_hidden_size_aligned // 128, hidden_size // 32)uint8NVFP4:
dtype=nvfp4, w_dtype=nvfp4, compute_dtype=nvfp4, dst_dtype=bfloat16flashinfer.gemm.group_gemm_nvfp4_nt_groupwise(a, b, a_scale, b_scale, segment_offsets, out=...)ashape:(dispatch_tokens, hidden_size // 2)uint8 (packed fp4)bshape:(num_experts_per_rank, new_hidden_size, hidden_size // 2)uint8a_scaleshape:(dispatch_tokens_aligned // 128, hidden_size // 16)uint8b_scaleshape:(num_experts_per_rank, new_hidden_size_aligned // 128, hidden_size // 16)uint8Build
m_indptr/segment_offsetsfrom the existingexpert_dispatch_token_offsetandexpert_dispatch_token_countarrays that are computed byget_moe_tokens_info().Compute FLOPs correctly:
2 * dispatch_tokens * hidden_size * new_hidden_sizeFollow the same pattern as the base implementation for
input_tensor_info,output_tensor_info, tensor size calculations, and the_create_tensors_func/_run_funcsetup.Key FlashInfer API signatures (for referenc...
This pull request was created from Copilot chat.