Skip to content

fused moe fix #4534

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ at::Tensor fused_moe_impl(
auto prec_o = get_prec_str(output);
auto prec_tkw = get_prec_str(topk_weights);

int workspace_size = ck_tile::moe_sorting_get_workspace_size(tokens, experts);
int workspace_size = ck_tile::moe_sorting_get_workspace_size(tokens, experts, topk, 0);
void *ws_ptr = nullptr;
if (workspace_size > 0)
{
auto ws = at::zeros({workspace_size}, at::TensorOptions().dtype(topk_ids.dtype()).device(device_of(topk_ids)));
ws_ptr = ws.data_ptr();
}


// Set up traits structure
fused_moe_traits traits{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ float fused_moesorting(
fused_moesorting_args a,
ck_tile::stream_config s);

int moe_sorting_get_workspace_size(int tokens, int num_experts);
int moe_sorting_get_workspace_size(int tokens, int num_experts, int topk);
float moe_sorting_mp(
fused_moesorting_trait t,
fused_moesorting_args a,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ float fused_moe(fused_moe_traits t, fused_moe_args a, const ck_tile::stream_conf
a.topk_ids_ptr, // const void* p_topk_ids;
a.topk_weight_ptr, // const void* p_weights;
a.local_expert_mask_ptr, // const void* p_local_expert_mask;
nullptr, // const void* p_local_tokens;
a.sorted_token_ids_ptr, // void* p_sorted_token_ids;
a.sorted_weight_ptr, // void* p_sorted_weights;
a.sorted_expert_ids_ptr, // void* p_sorted_expert_ids;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
ms_weight_type, \
sub_token_tile, \
sub_token_onshot, \
local_expert_masking>; \
local_expert_masking, \
false>; \
using kernel = ck_tile::MoeSortingKernel<ms_problem>; \
auto kargs = kernel::MakeKargs(a); \
const dim3 grids = kernel::GridSize(a); \
Expand Down Expand Up @@ -153,7 +154,7 @@ float fused_moesorting(fused_moesorting_trait t, fused_moesorting_args a, ck_til
}
}
#else
if(moe_sorting_get_workspace_size(a.tokens, a.num_experts) != 0)
if(moe_sorting_get_workspace_size(a.tokens, a.num_experts, a.topk) != 0)
{
return moe_sorting_mp(t, a, s);
}
Expand All @@ -176,7 +177,7 @@ float fused_moesorting(fused_moesorting_trait t, fused_moesorting_args a, ck_til
constexpr ck_tile::index_t unroll_num = unroll_num_; \
constexpr bool expert_masking = expert_masking_; \
using ms_problem = \
ck_tile::MoeSortingProblemMp<ms_index_t, ms_weight_type, unroll_num, expert_masking>; \
ck_tile::MoeSortingProblemMp<ms_index_t, ms_weight_type, ck_tile::index_t, unroll_num, expert_masking, false>; \
using kernel = ck_tile::MoeSortingMultiPhaseKernel_P0<ms_problem>; \
auto kargs = kernel::MakeKargs(a); \
const dim3 grids = kernel::GridSize(a); \
Expand All @@ -189,7 +190,7 @@ float fused_moesorting(fused_moesorting_trait t, fused_moesorting_args a, ck_til
constexpr ck_tile::index_t unroll_num = unroll_num_; \
constexpr bool expert_masking = expert_masking_; \
using ms_problem = \
ck_tile::MoeSortingProblemMp<ms_index_t, ms_weight_type, unroll_num, expert_masking>; \
ck_tile::MoeSortingProblemMp<ms_index_t, ms_weight_type, ck_tile::index_t, unroll_num, expert_masking, false>; \
using kernel = ck_tile::MoeSortingMultiPhaseKernel_P1<ms_problem>; \
auto kargs = kernel::MakeKargs(a); \
const dim3 grids = kernel::GridSize(a); \
Expand All @@ -202,7 +203,7 @@ float fused_moesorting(fused_moesorting_trait t, fused_moesorting_args a, ck_til
constexpr ck_tile::index_t unroll_num = unroll_num_; \
constexpr bool expert_masking = expert_masking_; \
using ms_problem = \
ck_tile::MoeSortingProblemMp<ms_index_t, ms_weight_type, unroll_num, expert_masking>; \
ck_tile::MoeSortingProblemMp<ms_index_t, ms_weight_type, ck_tile::index_t, unroll_num, expert_masking, false>; \
using kernel = ck_tile::MoeSortingMultiPhaseKernel_P2<ms_problem>; \
auto kargs = kernel::MakeKargs(a); \
const dim3 grids = kernel::GridSize(a); \
Expand All @@ -215,7 +216,7 @@ float fused_moesorting(fused_moesorting_trait t, fused_moesorting_args a, ck_til
constexpr ck_tile::index_t unroll_num = unroll_num_; \
constexpr bool expert_masking = expert_masking_; \
using ms_problem = \
ck_tile::MoeSortingProblemMp<ms_index_t, ms_weight_type, unroll_num, expert_masking>; \
ck_tile::MoeSortingProblemMp<ms_index_t, ms_weight_type, ck_tile::index_t, unroll_num, expert_masking, false>; \
using kernel = ck_tile::MoeSortingMultiPhaseKernel_P3<ms_problem>; \
auto kargs = kernel::MakeKargs(a); \
const dim3 grids = kernel::GridSize(a); \
Expand Down Expand Up @@ -252,7 +253,7 @@ float moe_sorting_mp(fused_moesorting_trait t, fused_moesorting_args a, ck_tile:
return -1;
}

int moe_sorting_get_workspace_size(int tokens, int num_experts)
int moe_sorting_get_workspace_size(int tokens, int num_experts, int topk)
{
return ck_tile::moe_sorting_get_workspace_size(tokens, num_experts);
}
return ck_tile::moe_sorting_get_workspace_size(tokens, num_experts, topk, 0);
}
Loading