Add AMD ROCm / MI300X optimized MoE framework for Megatron-LM - #1
Draft
Xiaoming-AMD with Copilot wants to merge 3 commits into
Draft
Add AMD ROCm / MI300X optimized MoE framework for Megatron-LM#1Xiaoming-AMD with Copilot wants to merge 3 commits into
Xiaoming-AMD with Copilot wants to merge 3 commits into
Conversation
- Add megatron/core/amd_rocm/ module with device utils, ROCm config, and XGMI-aware hierarchical All-to-All MoE token dispatcher - Add moe_use_rocm_dispatcher and related AMD config fields to TransformerConfig - Integrate ROCmMoEAlltoAllDispatcher into MoELayer (lazy import, no-op on NVIDIA) - Add _log_amd_hardware_info() call in initialize_megatron() - Add AMD MI300X recipe files for GPT and MoE workloads - Add unit tests for AMD ROCm module" Co-authored-by: Xiaoming-AMD <198007710+Xiaoming-AMD@users.noreply.github.com> Agent-Logs-Url: https://github.com/Xiaoming-AMD/Megatron-LM/sessions/7a5ae9c0-293c-4667-8b6e-ac446e5236a5
Copilot
AI
changed the title
[WIP] Analyze Megatron architecture for AMD AI accelerator framework
Add AMD ROCm/MI300X optimized MoE framework for Megatron-LM
Mar 21, 2026
- Add docs/amd_rocm/AMD_ROCm_MoE_优化方案.md: Chinese-language design doc explaining all changes, hardware rationale, usage, and design decisions - Add docs/amd_rocm/amd_rocm_moe_optimization.md: English-language version - Fix blank line between test methods in test_amd_moe.py Co-authored-by: Xiaoming-AMD <198007710+Xiaoming-AMD@users.noreply.github.com> Agent-Logs-Url: https://github.com/Xiaoming-AMD/Megatron-LM/sessions/b01be629-14eb-4680-ba9f-f00da33351a8
Copilot
AI
changed the title
Add AMD ROCm/MI300X optimized MoE framework for Megatron-LM
Add AMD ROCm / MI300X optimized MoE framework for Megatron-LM
Mar 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Megatron-LM had no AMD/ROCm support. This PR introduces
megatron/core/amd_rocm/and integrates AMD MI300X hardware optimizations into the MoE training path. All changes are zero-impact on NVIDIA hardware (conditional imports + runtime detection).Key changes
New module:
megatron/core/amd_rocm/device_utils.pyis_rocm_available,is_amd_gpu,is_mi300x), HBM/XGMI property queries; covers MI200 (gfx90a) through MI300X (gfx942)rocm_config.pyROCmMoEConfigdataclass — XGMI-aware dispatch, HBM capacity check, hipBLASLt grouped GEMM, load-balancing strategymoe_dispatcher.pyROCmMoEAlltoAllDispatcherextendingMoEAlltoAllTokenDispatcherwith: (1) hierarchical XGMI A2A — intra-node fast XGMI first, then inter-node RCCL/IB; (2) HBM capacity check at init; (3)ROCM_USE_GROUPED_GEMM=1hint for hipBLASLt batched expert GEMMModified files
transformer_config.py: Five newmoe_rocm_*fields —moe_use_rocm_dispatcher,moe_rocm_xgmi_aware_dispatch,moe_rocm_intra_node_ep_size,moe_rocm_use_hipblaslt_grouped_gemm,moe_rocm_hbm_capacity_check. All default to off; ignored on NVIDIA.moe_layer.py: SelectsROCmMoEAlltoAllDispatcherwhenmoe_use_rocm_dispatcher=Trueand AMD hardware is detected; silently falls back toMoEAlltoAllTokenDispatcherotherwise.initialize.py: Logs MI300X capabilities (HBM, XGMI BW, CU count, ROCm version) on rank-0 at startup.Usage
On non-AMD hardware
moe_use_rocm_dispatcher=Trueis silently ignored.New artifacts
tests/test_utils/recipes/mi300x/{gpt,moe}.yaml— MI300X CI recipes (mirroring H100 suite + MI300X-specific large expert-pool tests)tests/unit_tests/transformer/moe/amd_rocm/test_amd_moe.py— 20+ unit tests covering device detection, config validation, HBM capacity check, hierarchical A2A, andTransformerConfigAMD fieldsdocs/amd_rocm/— Chinese and English design docs explaining the architecture and rationaleContribution process
Pre-checks
Code review
Feel free to message or comment the @mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!
All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.
Step 1: Mark PR as "Ready for Review"
.github/CODEOWNERS.Final Review might get declined if these requirements are not fulfilled.
Step 2: Final Review
For PRs that change
megatron/core, once all expert reviewers have approved, theFinal Reviewlabel is applied automatically and final reviewers are assigned.For PRs outside
megatron/core, this step is skipped.Step 3: Approved
Once all required reviewers have approved, the
Approvedlabel is applied automatically.Merge
Any member of mcore-engineers will be able to merge your PR.
For MRs into `dev` branch
The proposed review process for `dev` branch is under active discussion.MRs are mergable after one approval by either
eharper@nvidia.comorzijiey@nvidia.com.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.