Skip to content
Open
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
6 changes: 6 additions & 0 deletions csrc/include/topk_gating_kernels.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,10 @@ __global__ void topk_gating_kernel(
static constexpr int vec_size = opus::vector_traits<f32vec>::size();
using vec_i = opus::vector_t<cktype_i, vec_size>;
const int num_experts_vec = num_experts / vec_size;
// Top-k scans whole vectors only, so a partial last vector would be skipped.
// topk_gating_launch picks f32vec so that vec_size divides num_experts.
if(num_experts % vec_size != 0)
__builtin_trap();

// Step 1: load + score function
// For softmax, bias is NOT added here -- it's added AFTER normalization
Expand Down Expand Up @@ -1143,6 +1147,8 @@ __global__ void topk_gating_kernel_smem_n(
static constexpr int vec_size = opus::vector_traits<f32vec>::size();
using vec_i = opus::vector_t<cktype_i, vec_size>;
const int num_experts_vec = num_experts / vec_size;
if(num_experts % vec_size != 0)
__builtin_trap();

// Guard: trailing tokens of the last block may be out of range.
const bool valid = token_idx < num_tokens;
Expand Down
Loading