-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Let EP prefill support new DeepGEMM #7310
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
Changes from 5 commits
2e8baee
54b6056
5f1a0cc
7efc496
f6b4f23
c0a641c
6e29349
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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| from sgl_kernel import silu_and_mul | ||
| from torch.nn import Module | ||
|
|
||
| from sglang.math_utils import ceil_div | ||
| from sglang.srt.custom_op import CustomOp | ||
| from sglang.srt.distributed import ( | ||
| get_tensor_model_parallel_rank, | ||
|
|
@@ -1370,10 +1371,19 @@ def forward_deepgemm_contiguous( | |
| device=hidden_states_fp8.device, | ||
| dtype=hidden_states_fp8.dtype, | ||
| ), | ||
| torch.empty( | ||
| (all_tokens, K // 128), | ||
| device=hidden_states_fp8.device, | ||
| dtype=torch.float32, | ||
| ( | ||
| # TODO check whether need `zeros` | ||
|
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. Regarding the If However, if Could you clarify if |
||
| torch.zeros( | ||
| (ceil_div(K // 128, 4), all_tokens), | ||
| device=hidden_states_fp8.device, | ||
| dtype=torch.int, | ||
| ).transpose(0, 1) | ||
| if deep_gemm_wrapper.DEEPGEMM_SCALE_UE8M0 | ||
| else torch.empty( | ||
| (all_tokens, K // 128), | ||
| device=hidden_states_fp8.device, | ||
| dtype=torch.float32, | ||
| ) | ||
| ), | ||
| ] | ||
| m_indices = torch.empty( | ||
|
|
@@ -1399,6 +1409,7 @@ def forward_deepgemm_contiguous( | |
| input_tensor[1], | ||
| m_indices, | ||
| output_index, | ||
| scale_ue8m0=deep_gemm_wrapper.DEEPGEMM_SCALE_UE8M0, | ||
| ) | ||
| dispose_tensor(hidden_states_fp8) | ||
|
|
||
|
|
@@ -1407,7 +1418,8 @@ def forward_deepgemm_contiguous( | |
| device=hidden_states_fp8_device, | ||
| dtype=torch.bfloat16, | ||
| ) | ||
| input_tensor[1] = tma_align_input_scale(input_tensor[1]) | ||
| if not deep_gemm_wrapper.DEEPGEMM_SCALE_UE8M0: | ||
| input_tensor[1] = tma_align_input_scale(input_tensor[1]) | ||
| deep_gemm_wrapper.grouped_gemm_nt_f8f8bf16_contig( | ||
| input_tensor, self.w13_weight_fp8, gateup_output, m_indices | ||
| ) | ||
|
|
@@ -1428,10 +1440,15 @@ def forward_deepgemm_contiguous( | |
| dtype=torch.bfloat16, | ||
| ) | ||
| down_input_fp8, down_input_scale = sglang_per_token_group_quant_fp8( | ||
| down_input, scale_block_size | ||
| down_input, | ||
| scale_block_size, | ||
| column_major_scales=deep_gemm_wrapper.DEEPGEMM_SCALE_UE8M0, | ||
| scale_tma_aligned=deep_gemm_wrapper.DEEPGEMM_SCALE_UE8M0, | ||
| scale_ue8m0=deep_gemm_wrapper.DEEPGEMM_SCALE_UE8M0, | ||
| ) | ||
| del down_input | ||
| down_input_scale = tma_align_input_scale(down_input_scale) | ||
| if not deep_gemm_wrapper.DEEPGEMM_SCALE_UE8M0: | ||
| down_input_scale = tma_align_input_scale(down_input_scale) | ||
| deep_gemm_wrapper.grouped_gemm_nt_f8f8bf16_contig( | ||
| (down_input_fp8, down_input_scale), | ||
| self.w2_weight_fp8, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -246,7 +246,13 @@ def dispatch_a( | |
| topk_idx = topk_idx.to(torch.int64) | ||
| if deep_gemm_wrapper.ENABLE_JIT_DEEPGEMM: | ||
| # TODO hard code 128 block quant,use fp8 communication | ||
|
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. The To improve maintainability and readability, consider defining this block size (128) as a named constant. This constant could reside in a shared configuration module (e.g., within |
||
| hidden_states = sglang_per_token_group_quant_fp8(hidden_states, 128) | ||
| hidden_states = sglang_per_token_group_quant_fp8( | ||
| hidden_states, | ||
| 128, | ||
| column_major_scales=deep_gemm_wrapper.DEEPGEMM_SCALE_UE8M0, | ||
| scale_tma_aligned=deep_gemm_wrapper.DEEPGEMM_SCALE_UE8M0, | ||
| scale_ue8m0=deep_gemm_wrapper.DEEPGEMM_SCALE_UE8M0, | ||
| ) | ||
| previous_event = Buffer.capture() if self.async_finish else None | ||
| return hidden_states, topk_idx, topk_weights, previous_event | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.