feat: add backend-aware MUSA support#2216
Open
ForAxel wants to merge 1 commit into
Open
Conversation
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.
Add backend-aware MUSA support
Summary
This PR adds backend-aware MUSA (Moore Threads GPU) support to Slime while preserving the existing CUDA execution path.
The implementation is based on the MUSA adaptations required by the current Megatron-LM and SGLang integration. It centralizes device and distributed-runtime differences instead of scattering MUSA-specific conditionals throughout the training code.
Motivation
Slime currently assumes CUDA/NCCL in several training, checkpoint, profiling, Ray, SGLang, and weight-update paths. On MUSA, these assumptions cause one or more of the following problems:
CUDA_VISIBLE_DEVICESonly.What Changed
1. Backend abstraction and bootstrap
slime/utils/accelerator.pywith common helpers for:musa_patchcompatibility package before Megatron/SGLang initialization in the main entry points and independently imported plugin/tool entry points.musa_patchwhen a MUSA environment is detected. CUDA processes do not import or execute the MUSA patch.cpu:gloo,musa:mcclso CPU metadata communication and MUSA tensor communication use the appropriate backends.2. Ray and device visibility
CUDA_VISIBLE_DEVICESorMUSA_VISIBLE_DEVICES.3. Megatron and model paths
4. Weight synchronization
p2p-broadcastsender protocol required by the SGLang MUSA receiver: the training rank sends each tensor to engine rank 1, after which SGLang performs the intra-engine broadcast.5. Process-group and profiling support
CUDA Compatibility
The CUDA path remains the default when no MUSA environment is requested:
accelerator.device_type()resolves tocudawhen CUDA is available and MUSA is not selected.CUDA_VISIBLE_DEVICESresolution remains supported.musa_patchis not imported in a normal CUDA environment.If
MUSA_VISIBLE_DEVICESorMUSA_PATCH_PATHis explicitly configured, the process is treated as a MUSA process by design.Testing
The following tests pass locally:
Additional validation passes:
compileall.git diff --cached --check.The new CPU-only tests are registered in both the workflow template and generated GitHub Actions workflow.
End-to-end MUSA validation
The integration was also validated with a full post-training run on Moore Threads S5000 GPUs using the
Qwen3-30B-A3B-Instruct-2507model. The training job completed the rollout, reward computation, distributed weight synchronization, and Megatron optimization stages successfully. Evaluation pass rate increased clearly as the training step advanced, confirming that the MUSA execution path not only runs end to end but also preserves the expected learning behavior.Scope and Non-Goals
musa_patchpackage remains an environment prerequisite for the current MUSA Megatron/SGLang stack and is configured throughMUSA_PATCH_PATH.