Adjust padding size to improve triton_kernels moe performance (#19174)
This commit is contained in:
@@ -271,7 +271,9 @@ def triton_kernel_fused_experts_with_bias(
|
||||
# feature check
|
||||
assert inplace is False, "Inplace is not supported in new triton MoE kernel"
|
||||
|
||||
E, _, _ = w1.shape
|
||||
M, K = hidden_states.shape
|
||||
E, _, N = w1.shape
|
||||
n_expts_act = routing_data.n_expts_act
|
||||
|
||||
if global_num_experts == -1:
|
||||
global_num_experts = E
|
||||
@@ -292,7 +294,16 @@ def triton_kernel_fused_experts_with_bias(
|
||||
2,
|
||||
)
|
||||
|
||||
intermediate_cache = matmul_ogs(
|
||||
intermediate_cache = torch.empty(
|
||||
(1, M * n_expts_act, N // 2),
|
||||
device=hidden_states.device,
|
||||
dtype=hidden_states.dtype,
|
||||
)
|
||||
output = torch.empty(
|
||||
(1, M, K), device=hidden_states.device, dtype=hidden_states.dtype
|
||||
)
|
||||
|
||||
matmul_ogs(
|
||||
hidden_states,
|
||||
w1,
|
||||
b1,
|
||||
@@ -301,14 +312,17 @@ def triton_kernel_fused_experts_with_bias(
|
||||
precision_config=w1_pcg,
|
||||
gammas=routing_data.gate_scal if apply_router_weight_on_input else None,
|
||||
fused_activation=act,
|
||||
y=intermediate_cache,
|
||||
)
|
||||
|
||||
return matmul_ogs(
|
||||
intermediate_cache,
|
||||
matmul_ogs(
|
||||
intermediate_cache.view(M * n_expts_act, N // 2),
|
||||
w2,
|
||||
b2,
|
||||
routing_data,
|
||||
scatter_indx=scatter_indx,
|
||||
precision_config=w2_pcg,
|
||||
gammas=None if apply_router_weight_on_input else routing_data.gate_scal,
|
||||
y=output,
|
||||
)
|
||||
return output.view(M, K)
|
||||
|
||||
@@ -335,6 +335,7 @@ class Mxfp4MoEMethod(FusedMoEMethodBase):
|
||||
scale_dtype = torch.uint8
|
||||
self.with_bias = with_bias
|
||||
mxfp4_block = 32
|
||||
triton_kernels_padding_alignment = 64
|
||||
|
||||
# pad the intermediate size to be a multiple of 2 * mxfp4_block
|
||||
# for to hold non-uniform sharded tensor as well as swizzling
|
||||
@@ -347,7 +348,7 @@ class Mxfp4MoEMethod(FusedMoEMethodBase):
|
||||
hidden_size = round_up(hidden_size, 256)
|
||||
else:
|
||||
intermediate_size_per_partition_after_pad = round_up(
|
||||
intermediate_size_per_partition, 64
|
||||
intermediate_size_per_partition, triton_kernels_padding_alignment
|
||||
)
|
||||
elif _use_aiter:
|
||||
|
||||
@@ -362,11 +363,8 @@ class Mxfp4MoEMethod(FusedMoEMethodBase):
|
||||
- layer.intermediate_size_per_partition
|
||||
)
|
||||
elif has_triton_kernels:
|
||||
# TODO: this is a hack to make
|
||||
# intermediate_size_per_partition_after_pad the same as the
|
||||
# per_rank_intermediate_size during weight loading
|
||||
intermediate_size_per_partition_after_pad = round_up(
|
||||
intermediate_size_per_partition, mxfp4_block
|
||||
intermediate_size_per_partition, triton_kernels_padding_alignment
|
||||
)
|
||||
|
||||
self.intermediate_size_per_partition = intermediate_size_per_partition_after_pad
|
||||
|
||||
Reference in New Issue
Block a user