-
Notifications
You must be signed in to change notification settings - Fork 825
[RFC]MXFP8 autotune IMA at some batch size #2800
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1157,7 +1157,20 @@ def forward( | |||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| elif self.fp8_quantization_type == Fp8QuantizationType.MxFp8: | ||||||||||||||||||||||||||||||||||||||||||||||||
| current_hidden_states_scale = extra_inputs[0] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| # During autotuner profiling, DynamicTensorSpec | ||||||||||||||||||||||||||||||||||||||||||||||||
| # creates an undersized 1D scale tensor (it | ||||||||||||||||||||||||||||||||||||||||||||||||
| # replaces dim 0 with the bucket value, but the | ||||||||||||||||||||||||||||||||||||||||||||||||
| # MXFP8 scale is 1D with size num_tokens * | ||||||||||||||||||||||||||||||||||||||||||||||||
| # hidden_size // 32). Recreate with correct size | ||||||||||||||||||||||||||||||||||||||||||||||||
| # to avoid OOB reads in the MoE GEMM kernel. | ||||||||||||||||||||||||||||||||||||||||||||||||
| padded_k = (current_hidden_size + 31) // 32 * 32 | ||||||||||||||||||||||||||||||||||||||||||||||||
| sf_size = current_num_tokens * padded_k // 32 | ||||||||||||||||||||||||||||||||||||||||||||||||
| if current_hidden_states_scale.numel() < sf_size: | ||||||||||||||||||||||||||||||||||||||||||||||||
| current_hidden_states_scale = torch.ones( | ||||||||||||||||||||||||||||||||||||||||||||||||
| (sf_size,), | ||||||||||||||||||||||||||||||||||||||||||||||||
| dtype=torch.uint8, | ||||||||||||||||||||||||||||||||||||||||||||||||
| device=hidden_states.device, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1168
to
+1173
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good catch to fix the illegal memory access error during autotuning. The logic to check and resize the However, as you noted, this fix may cause a performance regression. This is likely because filling the tensor with To potentially resolve the performance regression, I suggest initializing the tensor with random data, which better simulates real-world scale values. This should help the autotuner find a more performant kernel.
Suggested change
Comment on lines
+1169
to
+1173
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering the e8m0 data, maybe using 126-127 (0.5-2).
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError( | ||||||||||||||||||||||||||||||||||||||||||||||||
| f"Unsupported FP8 quantization type: {self.fp8_quantization_type}" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1734,7 +1747,7 @@ def trtllm_fp8_block_scale_moe_op( | |||||||||||||||||||||||||||||||||||||||||||||||
| _, tactic = tuner.choose_one( | ||||||||||||||||||||||||||||||||||||||||||||||||
| "flashinfer::trtllm_fp8_block_scale_moe", | ||||||||||||||||||||||||||||||||||||||||||||||||
| [moe_runner], | ||||||||||||||||||||||||||||||||||||||||||||||||
| MoERunner.tuning_config_with_hidden_states_scales, # FP8 block-scale uses hidden_states_scale | ||||||||||||||||||||||||||||||||||||||||||||||||
| MoERunner.tuning_config_with_hidden_states_scales, | ||||||||||||||||||||||||||||||||||||||||||||||||
| inputs, | ||||||||||||||||||||||||||||||||||||||||||||||||
| routing_bias=routing_bias, | ||||||||||||||||||||||||||||||||||||||||||||||||
| gemm1_weights=gemm1_weights, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
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.