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
6 changes: 3 additions & 3 deletions megatron/core/transformer/moe/moe_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,9 +865,9 @@ def compute_routing_scores_for_aux_loss(
score_function (str): The score function to use. Can be "softmax", "sigmoid"
or "sqrtsoftplus".
fused (bool, optional): Whether to use the fused version. Defaults to False.
padding_mask (torch.Tensor, optional): Boolean mask indicating non-padding tokens.
Shape in [num_tokens]. True for valid tokens,
False for padding tokens. Defaults to None.
padding_mask (torch.Tensor, optional): Boolean mask indicating padding positions.
Shape [num_tokens]. True = padding (exclude),
False = valid (include). Defaults to None.

Returns:
Tuple[torch.Tensor, torch.Tensor]: The routing map and the normalized routing scores.
Expand Down
5 changes: 3 additions & 2 deletions tests/unit_tests/transformer/moe/test_moe_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,17 @@ def test_moe_layer_recompute_forward_backward(
)

# Create padding mask if needed: shape [batch_size, sequence_length]
# Convention: True = padding (exclude), False = valid (include)
padding_mask = None
if with_padding_mask:
padding_mask = torch.ones(
padding_mask = torch.zeros(
micro_batch_size,
sequence_length,
device=torch.cuda.current_device(),
dtype=torch.bool,
)
# Mark last 4 tokens as padding for each batch
padding_mask[:, -4:] = False
padding_mask[:, -4:] = True

output, _ = moe_layer(hidden_states, padding_mask=padding_mask)

Expand Down
Loading