Skip to content
Merged
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
13 changes: 7 additions & 6 deletions csrc/trtllm_fused_moe_routing_deepseek.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

#include <cmath>

#include "flashinfer/exception.h"
#include "flashinfer/trtllm/fused_moe/RoutingKernel.cuh"

Expand Down Expand Up @@ -56,10 +58,9 @@ __global__ void routingMainKernel(KernelParams params) {
}
}

// note that for invalid scores, we simply use a negative value:
// they work well even with the compacted format used in topK, and
// sigmoid / bias activated scores cannot be negative
static constexpr float invalidScoreFloat = -1.F;
// note that for invalid scores, we use negative infinity,
// needed for GLM-style routing where bias can be negative
static constexpr float invalidScoreFloat = -float(INFINITY);
const OutputT invalidScore = OutputT{invalidScoreFloat};

// load bias already; each warp represents one expert group
Expand Down Expand Up @@ -101,8 +102,8 @@ __global__ void routingMainKernel(KernelParams params) {
smemScoreSigmoid[threadExpert] = scoreSigmoid;
}
// get the score with bias
// note that with invalid values, because sigmoid is < 1 and bias is -1,
// we must get a negative value, which is smaller than any valid value
// note: with invalid values, invalidScoreFloat ensures values are always smaller than valid
// ones
auto scoreBias = float{scoreSigmoid + float{biasVal}};

if (expertSelected) {
Expand Down
16 changes: 16 additions & 0 deletions tests/moe/test_trtllm_gen_fused_moe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2691,6 +2691,22 @@ def test_renormalize_routing(
},
id="DSLite",
),
pytest.param(
{
"num_experts": 160,
"top_k": 8,
"padding": 8,
"n_groups": 1,
"top_k_groups": 1,
"routed_scaling": 2.5,
"has_routing_bias": True,
"routing_method_type": RoutingMethodType.DeepSeekV3,
"compatible_moe_impls": [FP4Moe, FP8BlockScaleMoe, BF16Moe],
"compatible_intermediate_size": [512, 1024, 1536],
"enable_autotune": False,
},
id="GLM4_MoE",
),
],
)
@pytest.mark.parametrize(
Expand Down