[feat] Disable r3 for MTP#608
Conversation
Summary of ChangesHello @guapisolo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an incompatibility between the rollout routing replay (r3) system and Megatron-LM Transformer Parallel (MTP) layers. It introduces a mechanism to temporarily disable r3 during the setup of MTP modules, preventing erroneous replay registration and ensuring proper model initialization. The change is a targeted workaround due to current design limitations in obtaining module names before full layer registration and the absence of module info in MoE routing functions. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request disables rollout routing replay (r3) for Mixture of Tensors Parallelism (MTP) modules by temporarily setting routing_replay_manager.enabled to False. While this approach works, the current implementation is not exception-safe. My review includes a suggestion to use a try...finally block to ensure the replay manager's state is correctly restored even if an error occurs during MTP block creation. This will make the implementation more robust.
| # hard code here to skip r3 registration for mtp layers | ||
| if args.use_rollout_routing_replay: | ||
| routing_replay_manager.enabled = False | ||
| logger.warning( | ||
| "Rollout routing replay is not applicable for MTP modules, so skipped replay registration" | ||
| ) | ||
| mtp_block_spec = get_gpt_mtp_block_spec(config, transformer_layer_spec, **mtp_kwargs) | ||
| kwargs["mtp_block_spec"] = mtp_block_spec | ||
| if args.use_rollout_routing_replay: | ||
| routing_replay_manager.enabled = True |
There was a problem hiding this comment.
The current approach to temporarily disable the routing_replay_manager is not exception-safe. If an exception is raised within get_gpt_mtp_block_spec, routing_replay_manager.enabled will remain False, potentially causing issues later in the execution. Using a try...finally block will guarantee that the manager's state is restored correctly.
| # hard code here to skip r3 registration for mtp layers | |
| if args.use_rollout_routing_replay: | |
| routing_replay_manager.enabled = False | |
| logger.warning( | |
| "Rollout routing replay is not applicable for MTP modules, so skipped replay registration" | |
| ) | |
| mtp_block_spec = get_gpt_mtp_block_spec(config, transformer_layer_spec, **mtp_kwargs) | |
| kwargs["mtp_block_spec"] = mtp_block_spec | |
| if args.use_rollout_routing_replay: | |
| routing_replay_manager.enabled = True | |
| # hard code here to skip r3 registration for mtp layers | |
| if args.use_rollout_routing_replay: | |
| routing_replay_manager.enabled = False | |
| logger.warning( | |
| "Rollout routing replay is not applicable for MTP modules, so skipped replay registration" | |
| ) | |
| try: | |
| mtp_block_spec = get_gpt_mtp_block_spec(config, transformer_layer_spec, **mtp_kwargs) | |
| kwargs["mtp_block_spec"] = mtp_block_spec | |
| finally: | |
| if args.use_rollout_routing_replay: | |
| routing_replay_manager.enabled = True |
Disable r3 replay for mtp
Already tested on GLM-4.7-Flash.
This impl is a little bit hard code, but maybe the best impl in current design. Mainly because we cannot get the module name before the layer is fully registered, so the
Replayclass cannot record anything about the layer name. Also, the MoE routing function does not included module info, so we cannot skip MoE mtp replay during runtime...