You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6559bca
Browse filesBrowse the repository at this point in the historyBrowse files
Run the shared PrivateUse1 autocast and GradScaler contract on native MUSA builds, and document measured FP16/BF16 behavior on MTT S5000. Keep GradScaler unscale on the existing correctness-oriented CPU fallback because mudnn has no fused AMP foreach primitive.
Co-authored-by: lvyufeng <lvyufeng@flagopen.baai.ac.cn>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,7 +81,7 @@ Capability availability and validation status vary by platform. A feature existi
81
81
| PPU | CUDA boxing against PPU's CUDA-13-compatible SDK | Eager, autograd |**Experimental**|[PPU](docs/vendors/ppu/installation.md)|
82
82
| Hygon DCU | CUDA boxing over hipified DTK torch | Eager, autograd, FP16/BF16 AMP, profiler |**Beta**|[DCU](docs/vendors/dcu/installation.md)|
83
83
| Enflame GCU | Native topsaten backend, CPU fallback for unrouted/int64 ops | Eager |**Experimental**|[GCU](docs/vendors/gcu/installation.md)|
84
-
| Moore Threads MUSA | Native mudnn backend, CPU fallback for unrouted ops | Eager |**Experimental**|[MUSA](docs/vendors/musa/installation.md)|
84
+
| Moore Threads MUSA | Native mudnn backend, CPU fallback for unrouted ops | Eager, FP16/BF16 AMP|**Experimental**|[MUSA](docs/vendors/musa/installation.md)|
85
85
| D-Robotics BPU | No eager kernels; `torch.compile` graph path via hbdk4 | Graph compilation only |**Runtime only**|[BPU](docs/vendors/bpu/installation.md)|
Copy file name to clipboardExpand all lines: docs/reference/compatibility.md
+12-6Lines changed: 12 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@
28
28
| PPU |`ACCELERATOR=cuda` + `PPU_SDK`/`PPU_HOME` detection | Same CUDA-boxing path as NVIDIA CUDA, against the PPU's CUDA-13-compatible SDK | Experimental (FP16/BF16 autocast and GradScaler measured on PPU hardware, not in CI) | Not validated | Experimental (NCCL fallback via vendor-adapted `libnccl.so.2`; not CI-covered) | Not validated on this vendor's tracer | Experimental (vendor-index Triton required) | Experimental |
29
29
| Hygon DCU |`ACCELERATOR=dcu`| CUDA boxing over the hipified DTK torch build (HIP kernels under the CUDA dispatch key) | Beta (including FP16/BF16 autocast and GradScaler) | Experimental (FlagTree HCU validated on `gfx936`; not in CI) | Experimental (RCCL via DTK; all_reduce/DDP measured on 2 cards, not in CI) | Beta (parity suite runs in CI) | Beta (Python dispatch only) | Beta |
30
30
| Enflame GCU |`ACCELERATOR=gcu`| Native `libtopsaten.so` operator backend, with CPU fallback for unrouted/int64 ops | Experimental | Not validated | Not validated | Not validated | Experimental (Python dispatch, requires vendor Triton) | Experimental |
31
-
| Moore Threads MUSA |`ACCELERATOR=musa`| Native `mudnn` operator backend, with CPU fallback for unrouted ops | Experimental | Not validated | Not validated | Experimental (MUPTI device timeline measured on MTT S5000; CPU-Kineto linkage is environment-dependent) | Experimental (Python dispatch, requires vendor Triton) | Experimental |
31
+
| Moore Threads MUSA |`ACCELERATOR=musa`| Native `mudnn` operator backend, with CPU fallback for unrouted ops | Experimental (including FP16/BF16 autocast and GradScaler measured on MTT S5000) | Not validated | Not validated | Experimental (MUPTI device timeline measured on MTT S5000; CPU-Kineto linkage is environment-dependent) | Experimental (Python dispatch, requires vendor Triton) | Experimental |
32
32
| D-Robotics BPU |`ACCELERATOR=bpu`| No eager kernel sets are built; eager ops run on CPU | Runtime only (CPU fallback for eager) | Experimental (`torch.compile(backend="bpu")` graph path via hbdk4) | Not applicable | Not validated | Not applicable (no per-op kernel build) | Runtime only |
33
33
| TsingMicro |`ACCELERATOR=tsingmicro`| Runtime/build selector present; no per-op kernel set documented | Runtime only | Not validated | Not validated | Not validated | Not applicable | Runtime only |
34
34
@@ -155,11 +155,17 @@ with a documented CPU fallback for ops the vendor kernel table does not cover (s
155
155
[`setup.py`](../../setup.py), lines 440-457, and
156
156
`tests/integration/ops/test_musa_dispatch.py`, lines 15-24). No CUDA boxing kernels or FlagGems
157
157
C++ kernels are compiled for this platform; FlagGems Python dispatch is optional and needs the
158
-
vendor Triton backend. Distributed support remains unvalidated on hardware. The optional MUPTI
159
-
tracer has been measured on the available MTT S5000 host and emits real positive-duration kernel,
160
-
runtime, and memcpy activities with device, stream, name, and Chrome-trace metadata. CPU-to-device
161
-
linkage depends on whether the installed PyTorch/Kineto build supplies the PrivateUse1 resolver;
162
-
the CPU-only PyTorch 2.10 wheel used for this measurement does not justify a general parity claim.
158
+
vendor Triton backend. The shared `AutocastPrivateUse1` policies and native mudnn routes were
159
+
measured on an MTT S5000 with both FP16 and BF16. The 25-case AMP suite covers lower-precision
160
+
matmul, linear, and convolution; float32 and promote policies; nested autocast state; finite scale
161
+
growth; overflow backoff and optimizer-step skipping; and end-to-end GradScaler training. The
162
+
GradScaler unscale operation currently follows the correctness-oriented CPU fallback and copies
163
+
its mutated tensors and `found_inf` flag back to MUSA rather than using a native mudnn foreach
164
+
kernel. Distributed support remains unvalidated on hardware. The optional MUPTI tracer has been
165
+
measured on the available MTT S5000 host and emits real positive-duration kernel, runtime, and
166
+
memcpy activities with device, stream, name, and Chrome-trace metadata. CPU-to-device linkage
167
+
depends on whether the installed PyTorch/Kineto build supplies the PrivateUse1 resolver; the
168
+
CPU-only PyTorch 2.10 wheel used for this measurement does not justify a general parity claim.
| MUSA |float16, bfloat16, float32, float64, integer, bool | mudnn coverage; unrouted operations use the CPU fallback | float16, bfloat16, and float32 measured for AMP paths; broader support is vendor-dependent | float16, bfloat16|
29
29
30
30
The MetaX AMP entry is measured for the CUDA-boxing path on C550 with MACA
31
-
3.8.0; it does not cover the legacy handwritten MetaX kernel mode. The DCU and
32
-
MUSA entries intentionally do not claim AMP target parity without hardware
33
-
measurements for the specific library release. Their native boxing or
34
-
code-generated kernels determine the available operator/dtype combinations.
31
+
3.8.0; it does not cover the legacy handwritten MetaX kernel mode. The DCU entry
32
+
remains vendor-dependent. MUSA AMP coverage below is measured for the specific
33
+
S5000 and mudnn release rather than inferred from its route configuration.
34
+
35
+
## MUSA Boundaries
36
+
37
+
MUSA AMP uses the shared `AutocastPrivateUse1` policy lists with the native
38
+
mudnn operator routes. On the measured MTT S5000 and mudnn v3300 setup, both
39
+
float16 and bfloat16 execute the lower-precision matmul, linear, and convolution
40
+
policies. Logarithm, layer normalization, MSE loss, and the default softmax
41
+
policy return float32; an explicit softmax dtype is preserved; mixed inputs use
42
+
the promote policy.
43
+
44
+
`torch.amp.GradScaler("flagos")` uses the existing PrivateUse1 fallback for
45
+
`_amp_foreach_non_finite_check_and_unscale_`. That fallback moves the list and
46
+
scalar operands to CPU, runs the reference kernel, and copies the mutated values
47
+
and `found_inf` flag back to MUSA. This is correctness-oriented rather than a
48
+
claim of native mudnn AMP-foreach acceleration. Finite scale growth, overflow
49
+
backoff, optimizer-step skipping, and FP16/BF16 autocast training were measured
This test file checks that ops route to the `musa` backend, exercises per-op environment overrides, and validates results against CPU references. It replaces the generic per-op tests in `tests/integration/ops/`, which assert `-> cuda` routing that MUSA builds cannot produce (no CUDA boxing kernels are compiled).
with torch.autocast("flagos", dtype=torch.bfloat16):
163
+
output = model(inputs)
164
+
loss = F.mse_loss(output, targets)
165
+
166
+
scaler.scale(loss).backward()
167
+
scaler.step(optimizer)
168
+
scaler.update()
169
+
```
170
+
171
+
The standard policy groups cast matmul, linear, and convolution to the selected
172
+
lower-precision dtype. Logarithm, layer normalization, MSE loss, and the default
173
+
softmax policy run in float32; operations in the promote group use the widest
174
+
input dtype. Nested autocast state and explicit softmax dtypes follow PyTorch's
175
+
PrivateUse1 behavior.
176
+
177
+
GradScaler's `_amp_foreach_non_finite_check_and_unscale_` currently reaches the
178
+
existing CPU fallback because mudnn has no fused AMP-foreach primitive. The
179
+
fallback copies tensor-list operands and scalar state to CPU, invokes PyTorch's
180
+
reference kernel, and copies the mutated gradients and `found_inf` flag back to
181
+
MUSA. This preserves finite-step growth, overflow backoff, and optimizer-step
182
+
skipping, but it is not a native device-side performance path.
183
+
138
184
### Native RNG and CPU fallback
139
185
140
186
Native RNG uses a per-device Philox generator from `libmurand.so`. Each operation consumes one seed from the selected PyTorch `flagos` generator under its mutex, then configures a cached muRAND generator on the shared MUSA stream. This preserves `torch.manual_seed`, `torch.flagos.manual_seed`, `manual_seed_all`, `get_rng_state`/`set_rng_state`, explicit `generator=` isolation, and independent per-device sequences without maintaining a second Python-side RNG state. The optional FlagGems bridge reserves operation seeds through the same C++ API and starts each FlagGems Philox invocation at offset zero, so mixed native/FlagGems call order has one authoritative state.
@@ -183,6 +229,7 @@ MUSA has no CI runner (no `.github/configs/musa.yml` config exists), so all test
183
229
184
230
The native RNG and hybrid FlagGems implementation were measured on 2026-08-17 on an eight-device Moore Threads MTT S5000 host. Device 0 reported capability 3.1, 60 multiprocessors, and 85,813,358,592 bytes of memory. The environment used CPU PyTorch 2.10.0, the installed `/usr/local/musa` toolkit (`mudnn` v3300), FlagGems 5.0.2, and the vendor `flagtree-0.5.0+mthreads3.1` wheel (Triton 3.1.0, backend `mthreads`). Results:
185
231
232
+
-`pytest tests/integration/test_amp.py -v`: **25 passed** in 9.00 seconds. Both FP16 and BF16 passed lower-precision matmul/linear/convolution, float32 and promote policies, nested state, mutable non-finite unscale, finite scale growth, overflow backoff, optimizer-step skipping, and autocast/GradScaler training.
186
233
-`pytest tests/integration/ops/test_rng_dispatch.py -m "main_ops" -v`: the unified RNG suite passed, including explicit generators, state round trips, `torch.manual_seed`, full-width int64 ranges, native dropout, shared native/FlagGems reservation ordering, and multi-device sequence isolation. MUSA-only generator and reservation cases are selected by the `musa` mark.
187
234
-`pytest tests/integration/ops/test_musa_dispatch.py -v`: **89 passed** in 36.31 seconds.
188
235
-`pytest tests/unit/test_vendor_routing.py tests/unit/test_musa_rng_bridge.py -v`: **24 passed** in 2.19 seconds.
0 commit comments