feat: add backend-aware MUSA support - #2216
Merged
Merged
Conversation
ForAxel
force-pushed
the
dev/fb42ae4-musa-patch
branch
from
July 20, 2026 03:41
510ded8 to
a17ce62
Compare
Contributor
Author
|
Hi @zhuzilin , I adapted Slime for Moore Threads GPUs based on commit Could you please review whether this implementation is suitable for merging into |
ForAxel
force-pushed
the
dev/fb42ae4-musa-patch
branch
2 times, most recently
from
July 24, 2026 06:12
aec2b4f to
9bd1a73
Compare
ForAxel
force-pushed
the
dev/fb42ae4-musa-patch
branch
4 times, most recently
from
August 19, 2026 02:39
ae9449c to
a48e6d4
Compare
ForAxel
force-pushed
the
dev/fb42ae4-musa-patch
branch
from
August 20, 2026 03:25
a48e6d4 to
7720751
Compare
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.
Introduce runtime-selectable accelerator backends with MUSA support
Summary
This PR introduces a backend-neutral accelerator layer for Slime and adds a MUSA implementation while preserving the existing CUDA/ROCm execution path.
The PR contains two commits:
f63afa1e44e89422033d620c37e92b7a24651b5a feat: introduce extensible accelerator backends with MUSA support77207515917aeae51282659d187b20a33bdf0a92 test: cover accelerator selection and MUSA weight updatesThe main goal is to centralize device, memory, visibility, and communication-backend differences instead of spreading MUSA-specific branches across training, rollout, profiling, model, and conversion code.
Motivation
Several shared Slime paths directly assume
torch.cuda,CUDA_VISIBLE_DEVICES, and NCCL. MUSA exposes equivalent device operations throughtorch.musa, usesMUSA_VISIBLE_DEVICES, and uses MCCL for accelerator communication.Without a backend boundary, each shared runtime path would need vendor-specific conditionals and import-order handling.
What Changed
Accelerator abstraction and selection
Add
slime/utils/accelerator/with:Accelerator, the backend contract used by Slime;TorchAccelerator, shared delegation for CUDA-like PyTorch namespaces;CUDAAccelerator, which delegates to the existingtorch.cudaAPIs and keeps NCCL;MUSAAccelerator, which delegates totorch.musaand maps accelerator communication to MCCL.Backend selection supports:
SLIME_ACCELERATOR=<backend>as an explicit override;MUSA_VISIBLE_DEVICESorMUSA_PATCH_PATHas an explicit MUSA request;register_accelerator()andset_accelerator().An unavailable explicitly requested backend fails with a clear error. CPU-only imports remain possible because
initialize_accelerator()returnsNonewhen no accelerator is requested or available.MUSA bootstrap ordering
Importing
slime.utils.acceleratoralone does not loadmusa_patch. The patch is loaded only after MUSA is selected, but before the MUSA backend is validated and constructed.The Megatron and SGLang backend packages finalize accelerator selection before importing their third-party runtime modules. An explicit CUDA selection therefore does not import
musa_patch, even when MUSA-related environment variables are present.Runtime integration
Shared runtime paths now use the selected accelerator for the operations they already perform, including:
sglang-routerreleases that do not exposedisable_health_check;This PR does not claim portable MUSA implementations for existing CUDA-only kernels or extensions.
Distributed backend handling
Logical accelerator backends are mapped as follows:
nccl;nccltomccl;cpu:gloo,musa:mcclso CPU metadata and MUSA tensors can use their respective transports.This PR changes weight-update group creation to use the selected backend while keeping the existing asynchronous
dist.broadcasttensor-transfer protocol.Reloadable process-group handling recognizes registered accelerator communication backends. The
torch.distributed.new_groupwrapper normalizes a logicalncclbackend, whether supplied explicitly or inherited from the current default; Gloo, already-normalized MCCL, and composite backend strings remain unchanged.The WORLD teardown/reload lifecycle is generalized from NCCL-specific naming to accelerator process groups while retaining the temporary Gloo WORLD used during communicator teardown. Existing CPU-only and pre-registration behavior is preserved.
Allocator configuration
Training actors can opt in to expandable allocator segments for the selected PyTorch accelerator:
The value must be
0or1and defaults to0, so the CUDA allocator behavior is unchanged unless this option is explicitly enabled.CUDA Compatibility
When CUDA is selected:
torch.cuda;ncclremainsnccl;CUDA_VISIBLE_DEVICESremains the visibility source;musa_patchis not imported;MUSA-related environment variables intentionally request MUSA when no explicit backend overrides them. A CUDA deployment that exports those variables can select CUDA explicitly with
SLIME_ACCELERATOR=cuda.Tests
The new and updated tests are CPU-runnable. MUSA and MCCL behavior is checked with monkeypatches, a fake
torch.musanamespace, and backend strings; no test importstorch_musa, initializes MCCL, or requires accelerator hardware.tests/test_accelerator.pyis registered in the CPU unit-test matrix in both the workflow template and generated workflow.Validated at the PR tip, commit
77207515917aeae51282659d187b20a33bdf0a92:Result:
The CPU-only HF checkpoint-saver tests also pass (
6 passed) without accelerator environment variables.These tests cover backend selection, strict MUSA bootstrap timing, CUDA delegation, visible-device mapping, NCCL-to-MCCL normalization, CPU/Gloo process-group reload, and empty colocated weight buckets. They do not replace an end-to-end MUSA/MCCL integration run.
compileallandgit diff --checkalso pass for the PR tip.Scope and Validation Limits
musa_patchremains an optional external dependency for MUSA environments that require it and can be located throughMUSA_PATCH_PATH.