Skip to content

[compat] compat moe_router_load_balancing_type mcore>=0.16#9603

Open
Jintao-Huang wants to merge 1 commit into
modelscope:mainfrom
Jintao-Huang:fix_moe_router_load_balancing_type
Open

[compat] compat moe_router_load_balancing_type mcore>=0.16#9603
Jintao-Huang wants to merge 1 commit into
modelscope:mainfrom
Jintao-Huang:fix_moe_router_load_balancing_type

Conversation

@Jintao-Huang

Copy link
Copy Markdown
Collaborator

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request adds support for multiple MoE router load balancing strategies and their corresponding auxiliary loss coefficients, updating both the documentation and implementation. The review feedback highlights two issues: a potential TypeError in base.py when the load balancing type is None, and an incorrect type hint for moe_aux_loss_coeff in megatron_args.py.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +140 to +142
load_balancing_type = config.moe_router_load_balancing_type
if isinstance(load_balancing_type, str):
load_balancing_type = [load_balancing_type]

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.

high

If config.moe_router_load_balancing_type is None (which is its default value), load_balancing_type will remain None. This will cause a TypeError: argument of type 'NoneType' is not iterable when evaluating 'aux_loss' in load_balancing_type on line 143. We should handle the None case safely.

Suggested change
load_balancing_type = config.moe_router_load_balancing_type
if isinstance(load_balancing_type, str):
load_balancing_type = [load_balancing_type]
load_balancing_type = config.moe_router_load_balancing_type
if load_balancing_type is None:
load_balancing_type = []
elif isinstance(load_balancing_type, str):
load_balancing_type = [load_balancing_type]

moe_grouped_gemm: bool = True
moe_permute_fusion: bool = False
moe_aux_loss_coeff: float = 0.
moe_aux_loss_coeff: Union[List[float]] = 0.

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.

medium

The type hint Union[List[float]] is equivalent to List[float], which conflicts with the default value of 0. (a float). Since moe_aux_loss_coeff can be either a single float or a list of floats, the type hint should be updated to Union[float, List[float]].

Suggested change
moe_aux_loss_coeff: Union[List[float]] = 0.
moe_aux_loss_coeff: Union[float, List[float]] = 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants