-
Notifications
You must be signed in to change notification settings - Fork 13
feat(musa): add Moore Threads MUSA platform and engine support #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a5764b1
b91c183
31aac3e
29441a9
8d2a695
b3ae2d2
ba86476
69829c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # VERL MUSA User Guide | ||
|
|
||
| ## Introduction | ||
|
|
||
| This document describes how to use verl for reinforcement learning training on | ||
| Moore Threads MUSA accelerators. | ||
|
|
||
| ## Directory Structure | ||
|
|
||
| ```text | ||
| verl_hardware_plugin/ | ||
| ├── engines | ||
| │ ├── fsdp_musa.py # FSDP engine support | ||
| │ └── megatron_musa.py # Megatron engine support | ||
| └── platforms | ||
| └── platform_musa.py # MUSA platform settings | ||
| ``` | ||
|
|
||
| ```text | ||
| user_guide_musa/ | ||
| ├── README.md # This file | ||
| ├── install_guidance.md # Installation and environment setup | ||
| └── quick_start.md # GSM8K GRPO quick start | ||
| ``` | ||
|
|
||
| ## Getting Started | ||
|
|
||
| - [Installation Guide](./install_guidance.md) — prerequisites and environment setup | ||
| - [Quick Start](./quick_start.md) — run a GSM8K GRPO training job | ||
|
|
||
| ## Platform Summary | ||
|
|
||
| | Item | Description | | ||
| |------|-------------| | ||
| | Device type | `musa` | | ||
| | Vendor identifier | `moore_threads` | | ||
| | Communication backend | `mccl` | | ||
| | Device visibility env var | `MUSA_VISIBLE_DEVICES` | | ||
| | Ray resource name | `GPU` | | ||
| | IPC support | Yes | | ||
|
|
||
| ## MUSA Migration Patches | ||
|
|
||
| MUSA deployments may use two separate compatibility layers: | ||
|
|
||
| - MUSA support for the upstream Megatron/MCore implementation is provided by | ||
| the external `megatron-lm-musa-patch` compatibility layer. The patch is loaded | ||
| at runtime from the directory specified by `MUSA_PATCH_PATH` (usually | ||
| `/home/megatron-lm-musa-patch` in the release image); it adapts the | ||
| unmodified Megatron code for MUSA execution. | ||
|
|
||
| - MUSA compatibility for VERL and SGLang runtime components is provided by the | ||
| deployment-specific `verl-musa-patch` compatibility layer. The patch is loaded | ||
| at runtime from the directory specified by `VERL_MUSA_PATCH` (usually | ||
| `/home/verl-musa-patch` in the release image) and made available to Ray workers | ||
| through `PYTHONPATH`; it adapts the VERL and SGLang runtime components for MUSA | ||
| execution. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # MUSA Installation Guide | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - A MUSA Docker image with the matching driver/runtime, `torch_musa`, MCCL, | ||
| SGLang, and other MUSA dependencies. | ||
| - Network access to download models and datasets. | ||
| - A VERL checkout and this plugin checkout. | ||
|
|
||
| The standard MUSA images already include SGLang and the external Megatron-LM | ||
| MUSA patch (usually `/home/megatron-lm-musa-patch`). Other runtime dependencies | ||
| such as Ray are also normally pre-installed. Do not add CUDA versions of these | ||
| packages, as they may override the MUSA packages. | ||
|
|
||
| ## 1. Start the MUSA Docker Image | ||
|
|
||
| Use the MUSA release image provided for your hardware. The exact image name and | ||
| device mounts depend on the driver release; the following is a generic example: | ||
|
|
||
| ```bash | ||
| docker_image="${MUSA_DOCKER_IMAGE:-}" | ||
| docker_name="${MUSA_DOCKER_NAME:-verl_musa}" | ||
|
|
||
| docker container create \ | ||
| --name "${docker_name}" \ | ||
| --privileged \ | ||
| --net host \ | ||
| --pid=host \ | ||
| --shm-size 100g \ | ||
| --ulimit memlock=-1 \ | ||
| -v /home:/home \ | ||
| -it \ | ||
| "${docker_image}" \ | ||
| /bin/bash | ||
|
|
||
| docker start -ai "${docker_name}" | ||
| ``` | ||
|
|
||
| Inside the container, verify that the pre-installed components are available: | ||
|
|
||
| ```bash | ||
| ls /home | ||
| python3 -c 'import torch; import sglang; print(torch.musa.is_available())' | ||
| ``` | ||
|
|
||
| A public image is: | ||
|
|
||
| `registry.mthreads.com/mcctest/training-suite:v2.1.7.rc3-ut-verify` | ||
|
|
||
| ## 2. Install verl and verl-hardware-plugin | ||
|
|
||
| ```bash | ||
| # Install verl | ||
| git clone https://github.com/verl-project/verl.git | ||
| cd verl | ||
| pip install -e . | ||
|
|
||
| # Install verl-hardware-plugin | ||
| git clone https://github.com/verl-project/verl-hardware-plugin.git | ||
| cd verl-hardware-plugin | ||
| pip install -e . | ||
| ``` | ||
|
|
||
| ## 3. Prepare Data and Models | ||
|
|
||
| The baseline scripts use Qwen3-0.6B and GSM8K. Set `MODEL_DIR` and `DATA_DIR` | ||
| to the paths available in your environment, for example: | ||
|
|
||
| ```text | ||
| MODEL_DIR=/ipfs/models/Qwen/Qwen3-0.6B | ||
| DATA_DIR=/ipfs/models/gsm8k | ||
| ``` | ||
|
|
||
| ## 4. Verify the Environment | ||
|
|
||
| ```bash | ||
| python3 -c 'import torch; print(torch.musa.is_available(), torch.musa.device_count())' | ||
| ``` | ||
|
|
||
| The output should show that MUSA is available and report the visible device | ||
| count. Then follow the [Quick Start](./quick_start.md) to run a VERL script. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| # MUSA Quick Start | ||
|
|
||
| This guide walks you through the GSM8K GRPO baseline on Moore Threads MUSA. | ||
| Complete the [Installation Guide](./install_guidance.md) first. | ||
|
|
||
| **Baseline scenario:** Qwen3-0.6B + GSM8K + FSDP actor + SGLang rollout — see | ||
| [`scripts/baseline_grpo_gsm8k.sh`](../../scripts/baseline_grpo_gsm8k.sh). | ||
|
|
||
| ## 1. Prepare Data and Model | ||
|
|
||
| The MUSA image normally provides the runtime dependencies. Set the model and | ||
| dataset directories to paths available in your environment: | ||
|
|
||
| ```bash | ||
| MODEL_DIR=/ipfs/models/Qwen/Qwen3-0.6B | ||
| DATA_DIR=/ipfs/models/gsm8k | ||
| ``` | ||
|
|
||
| ## 2. Run the Baseline | ||
|
|
||
| From the repository root: | ||
|
|
||
| ```bash | ||
|
|
||
| export VERL_PLATFORM=musa | ||
| export VERL_USE_EXTERNAL_MODULES=verl_hardware_plugin | ||
| export VERL_MUSA_PATCH=/home/verl-musa-patch | ||
| export RAY_EXPERIMENTAL_NOSET_MUSA_VISIBLE_DEVICES=1 | ||
| export MUSA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 | ||
| export RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0 | ||
| export MCCL_LIB=/usr/local/musa/lib/libmccl.so | ||
| export LD_LIBRARY_PATH="/usr/local/musa/lib:${LD_LIBRARY_PATH:-}" | ||
| export VLLM_PATCH_MUSA_CUSTOM_OPS=1 | ||
| export SGLANG_MUSA_GRAPH_COMPAT=1 | ||
| export PYTHONPATH="${VERL_MUSA_PATCH}:${PYTHONPATH:-}" | ||
|
|
||
| export INFER_BACKEND=sglang | ||
| export DATA_DIR=/ipfs/models/gsm8k | ||
| export MODEL_DIR=/ipfs/models/Qwen/Qwen3-0.6B | ||
|
|
||
| exec bash "scripts/baseline_grpo_gsm8k.sh" \ | ||
| "+ray_kwargs.ray_init.runtime_env.env_vars.VERL_PLATFORM='musa'" \ | ||
| "+ray_kwargs.ray_init.runtime_env.env_vars.VERL_USE_EXTERNAL_MODULES='${VERL_USE_EXTERNAL_MODULES}'" \ | ||
| "+ray_kwargs.ray_init.runtime_env.env_vars.VERL_MUSA_PATCH='${VERL_MUSA_PATCH}'" \ | ||
| "+ray_kwargs.ray_init.runtime_env.env_vars.PYTHONPATH='${VERL_MUSA_PATCH}:${PYTHONPATH:-}'" \ | ||
| "+ray_kwargs.ray_init.runtime_env.env_vars.RAY_EXPERIMENTAL_NOSET_MUSA_VISIBLE_DEVICES='${RAY_EXPERIMENTAL_NOSET_MUSA_VISIBLE_DEVICES}'" \ | ||
| "+ray_kwargs.ray_init.runtime_env.env_vars.RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO='${RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO}'" \ | ||
| "+ray_kwargs.ray_init.runtime_env.env_vars.MUSA_VISIBLE_DEVICES='${MUSA_VISIBLE_DEVICES}'" \ | ||
| "+ray_kwargs.ray_init.runtime_env.env_vars.MCCL_LIB='${MCCL_LIB}'" \ | ||
| "+ray_kwargs.ray_init.runtime_env.env_vars.LD_LIBRARY_PATH='${LD_LIBRARY_PATH}'" \ | ||
| "+ray_kwargs.ray_init.runtime_env.env_vars.VLLM_PATCH_MUSA_CUSTOM_OPS='${VLLM_PATCH_MUSA_CUSTOM_OPS}'" \ | ||
| "+ray_kwargs.ray_init.runtime_env.env_vars.SGLANG_MUSA_GRAPH_COMPAT='${SGLANG_MUSA_GRAPH_COMPAT}'" \ | ||
| trainer.device=musa \ | ||
| +actor_rollout_ref.rollout.engine_kwargs.sglang.device=musa \ | ||
| +actor_rollout_ref.rollout.engine_kwargs.sglang.attention_backend=fa3 \ | ||
| +actor_rollout_ref.rollout.engine_kwargs.sglang.disable_piecewise_cuda_graph=True \ | ||
| "$@" | ||
|
|
||
| ``` | ||
|
|
||
| The script passes the platform settings, `verl-musa-patch`, SGLang options, and | ||
| device environment to Ray workers through `runtime_env`. Shell exports alone | ||
| are not sufficient for Ray workers. | ||
|
|
||
|
|
||
|
|
||
| ## 3. Compare Results | ||
|
|
||
| Compare `critic/rewards/mean` with the [NVIDIA reference run](https://swanlab.cn/@heavyrain/verl_grpo_gsm8k_math/runs/8h196r8o/chart). | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a result on
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put this MUSA SwanLab link in this PR summary, at the very top, and the link is: https://swanlab.cn/@wukecong/verl_grpo_gsm8k_math/runs/z4ybajqy/chart |
||
|
|
||
| The baseline should: | ||
|
|
||
| 1. Complete all epochs without a crash or hang. | ||
| 2. Show an upward reward trend within the first 20 steps. | ||
| 3. Avoid a flat or collapsing reward curve during the first 100 steps. | ||
|
|
||
| ## 4. Quick Verification | ||
|
|
||
| ```bash | ||
| python3 -c 'import torch; print(torch.musa.is_available(), torch.musa.device_count())' | ||
| ``` | ||
|
|
||
| The output should show that MUSA is available and report the visible device | ||
| count. The logs should also contain `[VERL_MUSA_SITE]` bootstrap messages. | ||
|
|
||
|
|
||
| ## Multi-Node Setup | ||
|
|
||
| Start Ray on the head node and workers, then set `NNODES` and run the baseline: | ||
|
|
||
| ```bash | ||
| # Head node | ||
| ray start --head --port=6379 | ||
| export RAY_ADDRESS='auto' | ||
|
|
||
| # Worker nodes | ||
| ray start --address='<head-ip>:6379' | ||
|
|
||
| NNODES=2 bash scripts/baseline_grpo_gsm8k.sh | ||
| ``` | ||
|
|
||
| MUSA uses Ray's built-in `GPU` resource. Do not configure a custom `musa` | ||
| resource. | ||
|
|
||
| ## Next Steps | ||
|
|
||
| - See [Installation Guide](./install_guidance.md) for image and dependency setup. | ||
| - See [development.md — Acceptance Baseline](../development.md#acceptance-baseline-for-new-hardware-adaptation) for the PR checklist. | ||
Uh oh!
There was an error while loading. Please reload this page.