Skip to content
Closed
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
8 changes: 3 additions & 5 deletions tensorrt_llm/_torch/modules/fused_moe/fused_moe_cutlass.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,11 @@ def __init__(
assert len(
self.initial_local_expert_ids) == self.expert_size_per_partition

max_num_tokens = model_config.max_num_tokens
# The maximum number of tokens in MoE are multiplied by DP size when attention DP is enabled
if self.use_dp:
max_num_tokens *= model_config.mapping.world_size
self.moe_max_num_tokens = model_config.moe_max_num_tokens or max_num_tokens
moe_max_num_tokens = model_config.max_num_tokens * model_config.mapping.dp_size
self.moe_max_num_tokens = model_config.moe_max_num_tokens or moe_max_num_tokens
# The auxiliary CUDA stream and CUDA events are only used when MoE chunking is applied
if self.moe_max_num_tokens < max_num_tokens:
if self.moe_max_num_tokens < moe_max_num_tokens:
self.aux_stream = aux_stream_dict[
AuxStreamType.
MoeChunkingOverlap] if aux_stream_dict is not None else torch.cuda.Stream(
Expand Down
12 changes: 12 additions & 0 deletions tensorrt_llm/_torch/modules/fused_moe/fused_moe_deepgemm.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,18 @@ def __init__(
apply_router_weight_on_input: bool = False,
layer_idx: Optional[int] = None,
):
if model_config.moe_max_num_tokens is None:
moe_max_num_tokens = model_config.max_num_tokens * model_config.mapping.dp_size
# The default moe_max_num_tokens is calculated from the following formula:
# max_isl = 8196, max_batch_size = 1024, mtp = 0
# max_num_tokens = ((mtp+1)*max_batch_size+max_isl+128+63)//64*64 = 9344
# moe_max_num_tokens = max_num_tokens * 2 = 18688
# It can avoid OOM for 8k/1k cases.
default_moe_max_num_tokens = 18688
if moe_max_num_tokens > default_moe_max_num_tokens:
model_config._frozen = False
model_config.moe_max_num_tokens = default_moe_max_num_tokens
model_config._frozen = True

super().__init__(
routing_method=routing_method,
Expand Down
8 changes: 2 additions & 6 deletions tensorrt_llm/_torch/modules/fused_moe/fused_moe_vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,9 @@ def __init__(
self.num_experts)
self.expert_size_per_partition = self.expert_end - self.expert_start

max_num_tokens = model_config.max_num_tokens
# The maximum number of tokens in MoE are multiplied by DP size when attention DP is enabled
if self.use_dp:
max_num_tokens *= model_config.mapping.world_size
self.moe_max_num_tokens = (model_config.moe_max_num_tokens
if model_config.moe_max_num_tokens
is not None else max_num_tokens)
moe_max_num_tokens = model_config.max_num_tokens * model_config.mapping.dp_size
self.moe_max_num_tokens = model_config.moe_max_num_tokens or moe_max_num_tokens

self._weights_created = False
if not model_config.skip_create_weights_in_init:
Expand Down
7 changes: 3 additions & 4 deletions tensorrt_llm/_torch/modules/fused_moe/fused_moe_wide_ep.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,11 @@ def __init__(
assert len(
self.initial_local_expert_ids) == self.expert_size_per_partition

max_num_tokens = model_config.max_num_tokens
# The maximum number of tokens in MoE are multiplied by DP size when attention DP is enabled
max_num_tokens *= model_config.mapping.world_size
self.moe_max_num_tokens = model_config.moe_max_num_tokens if model_config.moe_max_num_tokens is not None else max_num_tokens
moe_max_num_tokens = model_config.max_num_tokens * model_config.mapping.dp_size
self.moe_max_num_tokens = model_config.moe_max_num_tokens or moe_max_num_tokens
# The auxiliary CUDA stream and CUDA events are only used when MoE chunking is applied
if self.moe_max_num_tokens < max_num_tokens:
if self.moe_max_num_tokens < moe_max_num_tokens:
self.aux_stream = aux_stream_dict[
AuxStreamType.
MoeChunkingOverlap] if aux_stream_dict is not None else torch.cuda.Stream(
Expand Down
4 changes: 4 additions & 0 deletions tensorrt_llm/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ def node_rank(self):
def local_rank(self):
return self.rank % self.gpus_per_node

@property
def dp_size(self):
return self.tp_size if self.enable_attention_dp else 1

def has_cp(self):
return self.cp_size > 1

Expand Down