← Back to Pull requests

fix(musa): take the MUSA arch table and build targets from torchada #326

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 06, 2026 20:30 UTC
Author

Summary

vllm-musa now takes its MUSA arch handling from torchada's new torchada.arch (torchada 0.1.107, MooreThreads/torchada#146). That means the native build target, the JIT target and cache root, and the FP8 gate. vllm-musa's own arch parsing and detection is deleted. On S5000 (mp_31) every runtime gate answers as before, and the native compile command lines are unchanged.

  • setup.py: one arch per build.

  • - It comes from MTGPU_TARGET, then TORCH_MUSA_ARCH_LIST, then the visible devices, then mp_31.
    - An arch outside torchada's table (only mp_31 today) stops the build.
    - The resolved arch is written back as TORCH_MUSA_ARCH_LIST for torch_musa's MUSAExtension.
    - -DENABLE_FP8 comes from the table's fp8 column.
    - There is no device check, so cross-compiling still works.
  • JIT (jit.py): targets come from VLLM_MUSA_ARCH_LIST, then MATE_MUSA_ARCH_LIST, then the devices.

  • - Once MUSA is initialized, a load whose targets miss a visible device's arch raises instead of building a module whose kernels would not launch.
    - Builds go under <VLLM_MUSA_JIT_CACHE_DIR>/<cache_tag>/, e.g. mp31_mu50200/, so different archs and MUSA toolkits never share a module.
    - The rope module name no longer carries the arch.
    - Nothing resolves at import.
  • The unread -D__MUSA_ARCH_LIST__=310 is removed from the norm, qk-mrope and custom all-reduce JIT flags. Preprocessing those units with and without it gives identical output on S5000.

  • supports_fp8() matches the device capability against the table's FP8 rows. The Triton fused-MoE FP8 gate calls supports_fp8() instead of has_device_capability((3, 1)).

  • - (3,1) answers True as before.
    - (3,0), (2,2), None and pymtml's failed-probe (0, 0) answer False as before. So does an MTML RuntimeError.
    - An arch without an FP8 row, e.g. (3,2), now answers False instead of passing the >= (3, 1) check unverified.
  • Pins: torchada 0.1.107 in requirements/common.txt, the stack contract test, the READMEs and the Nemotron cookbook.

  • - The legacy torch 2.9.1 stack row is raised too, because setup.py imports torchada.arch.
    - The install docs say to upgrade torchada before pip install -e ..
  • A tripwire test fails when torchada's table changes. Its message names the device code that branches on __MUSA_ARCH__ == 310, and a second test keeps that list complete.

  • Build-arch record and worker check:

  • - setup.py writes the arch it built the native extensions for to vllm_musa/_build_info.py. It goes into the source tree for editable installs and into build_lib for wheels. The file is ignored by git and kept out of the image build context.
    - MTGPUWorker checks its device against the record once init_device() has selected it, before the model loads.
    - A device outside the record raises a RuntimeError that names both archs. The message suggests a rebuild only when the device arch is in torchada's table.
    - On S5000, a kernel built for another arch fails at launch with musaErrorInvalidDeviceFunction. musaDeviceSynchronize still succeeds and the output stays unwritten, so this check is what turns a wrong-arch install into a clear error.
    - An install without a record skips the check, for example a tree built before this change.
  • Image arch variables: docker/check_musa_arch_env.py runs right before pip install -e .. It fails unless every variable below names the same single arch from torchada's table, each in its reader's spelling:

  • - MTGPU_TARGET, in any torchada spelling;
    - TORCH_MUSA_ARCH_LIST, as 31;
    - MATE_MUSA_ARCH_LIST, as 3.1;
    - VLLM_MUSA_ARCH_LIST, when set.
    - A MATE value that MATE cannot parse already fails at import torchada, with MATE's own error.
  • TileLang's kernel cache: no change needed. TileLang keys its disk cache on str(target), and on S5000 the MUSA target reads {"kind":"musa",...,"arch":"mp_31",...}, filled in from the device. A device test pins this.
  • The image already sets MTGPU_TARGET=mp_31, TORCH_MUSA_ARCH_LIST=31 and MATE_MUSA_ARCH_LIST=3.1, so the image env decides as before.

    MTGPU_TARGET=mp_22 builds now stop instead of compiling. torch_musa in the current image is mp_31-only, so this loses no runnable configuration.

    Test plan

    Leased 2x MTT S5000, driver 5.2.0-server, image vllm:v0.32.0-ph1-5.2.0-torch2.11.0.post2-20261106 (digest-pinned), torch / torch_musa 2.11.0.post2+musa5.2.0. Base d6ad785bda and this branch were built in place in the same tree, /workspace/vllm-musa, with the shared ccache. Every build started from the pristine pinned third_party/vllm. The branch builds had torchada 0.1.107 (this PR's dependency) installed.

  • Native build, 4 builds: base and branch, each in the image env and with no arch env (env -u MTGPU_TARGET -u TORCH_MUSA_ARCH_LIST -u MATE_MUSA_ARCH_LIST).

  • - Each build issues 52 compile commands. With pip's temp build dir normalized, the command lines are identical across all four builds.
    - Every line carries -DENABLE_FP8 and only --offload-arch=mp_31.
    - ccache: the branch image-env build after the base builds hit 52/52.
  • Focused tests (tests/test_musa.py, tests/test_inplace_porting_contract.py, tests/jit_kernel/test_csrc_jit_kernels.py; the branch adds tests/jit_kernel/test_jit_arch_resolution.py and tests/test_musa_arch_table.py): base 147 passed, branch 189 passed.

  • Full suite (pytest tests --deselect tests/test_musa_sync_upstream.py --continue-on-collection-errors): base 56 failed / 2827 passed / 64 skipped / 5 errors; branch 58 / 2867 / 64 / 5.

  • - The whole difference in failing tests is parameters of test_deep_gemm_three_wrappers::test_grouped_wrapper_full_ticket_boundary_matrix.
    - That test checks vendor DeepGEMM determinism, and which parameters fail varies from run to run.
  • JIT device check, with MUSA initialized:

  • - VLLM_MUSA_ARCH_LIST=mp_22 raises a RuntimeError naming the targets, the variable and the device arch ([mp_31]); nothing is built.
    - 310 raises a ValueError.
    - mp_31, the MATE_MUSA_ARCH_LIST fallback and the no-env device case build under mp31_mu50200/<name>/, with the lock at mp31_mu50200/tmp/<name>.lock.
  • Platform, prewarm and JIT under a subprocess audit hook, same script on base and branch:

  • - Neither platform load nor _moe.prewarm() initializes MUSA.
    - supports_fp8(), is_device_capability((3, 1)) and has_device_capability((3, 1)) are True on both.
    - The subprocesses started are the same; only the rope module path differs, and no musaInfo call is added.
  • Server smokes on the normal compiled path with PIECEWISE and FULL graph capture: Qwen3-8B and Qwen3-8B-FP8 (quantization=fp8). Each answered 3/3 requests with HTTP 200 and correct answers. The JIT modules were built under mp31_mu50200/.

  • Build-arch record, second leased run, same image, this branch with the record, check and image-check commits:

  • - The native build hit ccache 52/52 with unchanged compile lines: every line carries -DENABLE_FP8 and only --offload-arch=mp_31.
    - The build logs Recorded MUSA arch mp_31 and writes MUSA_ARCHS = ((3, 1),) to the source tree and to the editable build's build_lib.
  • Worker check:

  • - With the record edited to name mp_22, vllm serve Qwen3-8B stops in worker init before the model loads, with RuntimeError: vllm-musa's native extensions were built for [mp_22], but musa:0 is mp_31; their kernels do not launch there (musaErrorInvalidDeviceFunction). Rebuild vllm-musa with MTGPU_TARGET=mp_31.
    - With the real record, the Qwen3-8B compiled smoke passes 4/4.
  • Image check inside the image:

  • - The image env passes.
    - VLLM_MUSA_ARCH_LIST=mp_22 fails with the script's message.
    - MATE_MUSA_ARCH_LIST=31 fails in MATE's parser.
  • Wrong-arch launch: an add-one kernel built for mp_22 or mp_21 returns musaErrorInvalidDeviceFunction on S5000, while the mp_31 build is correct.

  • TileLang: on S5000, Target("musa") carries arch mp_31, and the cache-key target field of a compiled kernel holds it. With no visible device, TileLang falls back to mp_22 with a warning.

  • Focused tests on the device, run on the #327 tip that contains this branch: the three new files (tests/test_native_arch.py, tests/test_docker_musa_arch_env.py, tests/test_tilelang_target_arch.py) plus test_inplace_porting_contract.py, test_musa_arch_table.py, test_musa.py, jit_kernel/test_jit_arch_resolution.py and #327's test_rope_store_hint_prewarm.py. 201 passed.

  • -D__MUSA_ARCH_LIST__=310: mcc -E of norm/rmsnorm.mu, norm/qk_mrope.mu and distributed/custom_all_reduce.mu is byte-identical with and without it (plain, device-only and host-only).
  • Merge after the torchada 0.1.107 release is on the index.

    AI assistance: Claude Code drafted this change and ran the MUSA validation listed above.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: yeahdongcn Review duration: 3786m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #326"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 30.4% · Safe to merge
    30.4%