[DO NOT MERGE]Enable FP4 bmm for k_up_proj and v_up_proj in MLA #797
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.
Purpose
To further take the memory and compute advantage of MXFP4 inference, this PR complement the MLA fp4 computing by replacing the current FP8 bmm with FP4 bmm, which should achieve higher speedup.
Details of Weight Unpacking
After loading weights, we have weights kv_b_proj with
[num_heads * (qk_nope_head_dim + v_head_dim), kv_lora_rank // 2]shape.kv_lora_rank // 2here means 2 FP4 elements packed into 1 byte uint8 elements. The accompained scale is[num_heads * (qk_noe_head_dim + v_head_dim), kv_lora_rank // 32]The weight unpacking target layout is defined by the computing process
k_up_projandv_up_proj.W_K and W_K_scale
As for
k_up_proj, the high precision computation(fp8/bf16) formula isdecode_q_nope @ W_K, where the shape isFrom the GEMM kernel perspective, the input weight layout is
[B, N, K //2]. Hence, the PR unpack kv_proj_weight and split W_K weights. Then reorder it to[num_heads, kv_lora_rank, qk_nope_head_dim // 2]. The corresponding W_K_scale is with shape[num_heads, kv_lora_rank, qk_nope_head_dim // 32]. The 32 here is the group size defined by OCP Specification.W_V and W_V_scale
W_VandW_V_scaleis used in v_up_proj process. The high precision formula can be describted asx @ W_V, where the shape isAs for the GEMM, perspective, the W_V should have shape
[num_heads, v_head_dim, kv_lora_rank]and the corresponding scale is with shape[num_heads, v_head_dim, kv_lora_rank // 32]Test Plan
Test Result
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.