MooreThreads/torch_musa
torch_musa is an open source repository based on PyTorch, which can make full use of the super computing power of MooreThreads graphics cards.
torch_musa – PyTorch for Moore Threads MUSA GPUs
What it is
- An official PyTorch extension that lets you run PyTorch code on Moore Threads’ MUSA graphics cards. It mirrors the regular PyTorch API, so you only need to replace device strings like
cudawithmusa.
Why it matters
- Enables the large PyTorch ecosystem (models, libraries, tutorials) to run on a hardware platform that is not CUDA‑based, opening up a new class of accelerators for deep‑learning training and inference.
Key capabilities
- Drop‑in backend –
torch.musa.is_available(),tensor.to('musa'),torch.musa.Stream(), etc., work just like their CUDA counterparts. - Distributed training – supports the
mcclbackend (MCCL library) for multi‑GPU scaling. - C/C++ extensions – provides a low‑boilerplate API for writing custom ops in native code.
- Tooling – utilities for porting CUDA code, building extensions, and debugging.
- Ecosystem support – pre‑built MUSA‑compatible wheels for torchvision, torchaudio, and a curated list of other projects (e.g., Hugging Face Transformers, PyTorch Lightning, PyTorch3D).
Getting started
- Prerequisites – install the MUSA SDK (driver, toolkit, muDNN, MCCL) and math libraries (muThrust, muAlg). Verify with
musaInfo. - Installation – either download pre‑compiled wheels from the GitHub releases page or build from source with the provided
build.shscript (options for building only PyTorch, only torch_musa, debug/ASAN builds, wheel generation, etc.). - Docker – ready‑made images are hosted on
registry.mthreads.com/mcconline. Pull and run with--privilegedandMTHREADS_VISIBLE_DEVICES=allto expose the GPUs inside the container. - Code change – import
torchas usual; the library auto‑loads. Switch device strings:
For distributed jobs:import torch a = torch.tensor([1., 2.], device='musa') torch.backends.mudnn.allow_tf32 = Trueimport torch.distributed as dist dist.init_process_group('mccl', rank=..., world_size=...)
Supported companion libraries
- torchvision – install from the Moore Threads
visionrepo (v0.26.0.post1 for torch_musa ≥ 2.7.0) or from upstream PyTorch if versions match. - torchaudio – built from the official PyTorch audio source matching the torch version.
- Other projects – a list of “musified” repos (pytorch3d, pytorch_sparse, pytorch_scatter, pytorch_cluster, pytorch_lightning, etc.) is maintained in the README; they can be installed with
pip install .orpython setup.py install.
Troubleshooting highlights
torch.musa.is_available()returnsFalse→ check MUSA driver/SKD installation andLD_LIBRARY_PATH.- Missing shared libraries (
libmusa.so,libmudnn.so,libmccl.so) → ensureMUSA_HOMEpoints to the SDK and the libraries are on the library path. - Distributed init fails → verify MCCL is installed (only on S4000) or build with
USE_MCCL=0for other chips. - Container sees no device → run the Docker command shown in the README and set
MTHREADS_VISIBLE_DEVICES.
License
- BSD‑style license (see
LICENSE).
Bottom line: torch_musa lets developers leverage the familiar PyTorch workflow on Moore Threads’ MUSA GPUs, with full support for tensors, autograd, CUDA‑like extensions, and distributed training, backed by official Docker images and a growing set of compatible libraries.
関連
- プロジェクト
- プロジェクト
- プロジェクト
- プロジェクト
- プロジェクト