Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 5 additions & 6 deletions csrc/trtllm_fused_moe_routing_deepseek.cu
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,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 a very negative value:
// needed for GLM-style routing where bias can be negative
static constexpr float invalidScoreFloat = -1e10F;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to use negative zero? It's usually used as an invalid score in float.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I think it would not work? (I think signed 0 is a valid representation here right and will just be 0? Correct me if I'm wrong)

model.layers.92.mlp.gate.e_score_correction_bias
  shape: torch.Size([160])
  min: -9.6087
  max: -9.2649
  mean: -9.3417
  鈿狅笍  Has 160 NEGATIVE values!

model.layers.88.mlp.gate.e_score_correction_bias
  shape: torch.Size([160])
  min: -2.0029
  max: -1.8230
  mean: -1.8640
  鈿狅笍  Has 160 NEGATIVE values!

model.layers.89.mlp.gate.e_score_correction_bias
  shape: torch.Size([160])
  min: -2.1478
  max: -1.9239
  mean: -1.9730
  鈿狅笍  Has 160 NEGATIVE values!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I think we can also use static constexpr float invalidScoreFloat = float{-INFINITY};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 馃憤

const OutputT invalidScore = OutputT{invalidScoreFloat};

// load bias already; each warp represents one expert group
Expand Down Expand Up @@ -101,8 +100,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