Skip to content

Commit a26a7f1

Browse files
Add bf16/fp32 token-per-expert to the MoE aux loss kernel (#2162)
* add bf16/fp32 token-per-expert on the moe-loss-computation on router fusion Signed-off-by: tongliu <tongliu@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: tongliu <tongliu@nvidia.com> Co-authored-by: tongliu <tongliu@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 84fa28d commit a26a7f1

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎transformer_engine/common/fused_router/fused_moe_aux_loss.cu‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ __global__ void fused_moe_aux_loss_backward_kernel(const float* Const_buf,
229229
// Loop: for all positions in each row
230230
for (int i = lane_id; i < num_cols; i += kThreadsPerWarp) {
231231
float C_coeff = Const_buf[0];
232-
IndexType tokens_per_expert_i = tokens_per_expert[i];
232+
double tokens_per_expert_i = static_cast<double>(tokens_per_expert[i]);
233233
double grad_aux_loss_value = static_cast<double>(grad_aux_loss[0]);
234234
// Loop: for all rows
235235
for (int j = global_warp_id; j < num_rows; j += global_warp_num) {

‎transformer_engine/common/fused_router/utils.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ __device__ inline void naive_topk_and_mask(T *scores, int data_size, int topk, i
246246
using type = int64_t; \
247247
{ __VA_ARGS__ } \
248248
} break; \
249+
case DType::kBFloat16: { \
250+
using type = bf16; \
251+
{ __VA_ARGS__ } \
252+
} break; \
253+
case DType::kFloat32: { \
254+
using type = float; \
255+
{ __VA_ARGS__ } \
256+
} break; \
249257
default: \
250258
NVTE_ERROR("Invalid type."); \
251259
}

0 commit comments

Comments
 (0)