Skip to content

refactor: unify vLLM-MUSA registration around native vLLM plugin contracts - #365

Draft
yeahdongcn wants to merge 1 commit into
v0.32.0-devfrom
refactor/vllm-musa-registration
Draft

yeahdongcn wants to merge 1 commit into
v0.32.0-devfrom
refactor/vllm-musa-registration

Conversation

@yeahdongcn

Copy link
Copy Markdown
Collaborator

Summary

Unifies vLLM-MUSA's registration architecture around vLLM's native out-of-tree plugin contracts (superseding draft experiments #359 and #362 without adding a parallel manifest or global registry):

  • Split and idempotent general plugin entry points (pyproject.toml, vllm_musa/__init__.py):
    • vllm.general_plugins now declares musa_out_of_tree = "vllm_musa:register_out_of_tree" and musa_attn_backends = "vllm_musa:register_attn_backends" (with idempotency guards). register_custom_ops() is kept as a backward-compatible alias.
    • Deferred maybe_register_musa_template_heuristics() out of bare import vllm_musa into _register_patches() so platform discovery and packaging smoke checks do not touch torch._inductor.
    • Aligned MUSAPlatformBase.import_kernels() to load all four AOT extensions (vllm._C, vllm._C_stable_libtorch, vllm._moe_C, vllm_musa._C), matching build: split v0.32 MUSA image runtime from source #360's NATIVE_MODULES.
  • Separated vllm_musa/ir/ from vllm_musa/kernels/:
    • Moved vLLM IR providers (musa_ops.py, gated_qkv.py) into vllm_musa/ir/, loaded exclusively by MUSAPlatformBase.import_ir_kernels().
    • vllm_musa/kernels/ now holds only standalone MUSA/Triton kernel helpers (with thin compatibility re-exports for musa_ops / gated_qkv).
  • Converted all 13 implicit import-time monkey-patch modules to explicit idempotent install_hooks():
    • Model-executor adapters (fused_moe, 3 MoE routers, quantization/fp8, fp8_utils, deep_gemm_warmup) are installed explicitly by vllm_musa.model_executor.register_model_executor_adapters(), cleanly separated from the 8 formal @*.register_oot layer modules.
    • V1 runtime adapters (mla/common, mla/flashmla_sparse, multiproc_executor, topk_topp_sampler, uniform_sample_counts, spec_decode/utils) are installed explicitly by vllm_musa.v1.register_v1_adapters() (and vllm__v1__spec_decode__eagle.patch.py calls spec_decode.utils.install_hooks()).
  • End-to-end RMSNorm IR convergence:
    • vllm_musa/ir/musa_ops.py wires the validated MUSA JIT kernel (musa_csrc_rmsnorm) ahead of _C::rms_norm under the single "musa" IR provider.
    • MusaRMSNorm.forward_oot() delegates non-residual RMSNorm to self.forward_native(x, residual) -> vllm.ir.ops.rms_norm instead of bypassing IR.
    • MUSAPlatformBase.get_default_ir_op_priority() honors VLLM_MUSA_CUSTOM_OP_USE_NATIVE and quantized PIECEWISE safety routing for rms_norm as well.
  • Developer guide & contract tests:
    • Added docs/vllm_musa/registration.md and tests/test_registration_architecture.py (offline AST/contract tests + MUSA runtime integration tests).

Alignment with #360

When rebasing onto #360 (codex/v032-image-runtime-refactor):

Validation

Completed (offline / source)

  • ruff check on all new and refactored registration modules: pass
  • git diff --check: pass
  • pytest -q tests/test_registration_architecture.py tests/test_custom_op_preload.py tests/test_v1_worker_import_order.py tests/test_quant_fp8_oot_source.py tests/test_vit_attention_backend_registration.py tests/test_deepseek_v4_contract_source.py tests/test_inplace_porting_contract.py tests/test_dsv4_moe_shared_fold.py tests/test_manifest.py tests/test_split_series_source.py tests/test_omni_compat.py: 154 passed, 28 skipped

Planned on S5000 (using pre-built image sh-harbor.mthreads.com/mcctest/vllm:v0.32.0-ph1-5.2.0-torch2.13.0.post1-20261124)

  • pip install -e . --no-build-isolation --no-deps and verify importlib.metadata.entry_points(group="vllm.general_plugins")
  • pytest -q tests/test_registration_architecture.py tests/test_v1_worker_import_order.py tests/test_fused_add_rms_norm_compile.py tests/test_musa.py tests/test_patches.py

@yeahdongcn yeahdongcn left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge verdict: 2 blocking findings — not ready to merge.

Reviewed 61b9263fc833. Splitting the general-plugin entry points silently disables every documented VLLM_PLUGINS=musa,musa_custom_ops command, and offline-series is red on a drift tripwire this PR made stale.

Findings: 2 blocking · 3 nit

Gate: pre-commit 13/15 — isort and black failed and rewrote 7 files (vllm_musa/model_executor/__init__.py, tests/test_registration_architecture.py, vllm_musa/v1/attention/backends/mla/common.py, and 4 more). Re-run the same hook over the 34 changed files to reproduce.

nit location problem fix
nit vllm_musa/patches/vllm__distributed__parallel_state.patch.py:157 import-time "prime" now installs nothing call spec_decode_utils.install_hooks()
nit vllm_musa/v1/attention/backends/turboquant.py:48 still installs hooks at import add it to register_v1_adapters()
nit vllm_musa/kernels/__init__.py:1 docstring promise false for both re-export shims scope the claim to non-shim helpers
What changed · evidence · what I could not verify

Diff map (34 files). pyproject.toml + vllm_musa/__init__.py: one vllm.general_plugins entry point becomes two idempotent ones, with register_custom_ops() kept as an alias; Inductor heuristics move from bare import into _register_patches(). New vllm_musa/ir/ holds the two vllm.ir.ops providers, vllm_musa/kernels/ keeps thin re-exports. 13 import-time monkey-patch modules become idempotent install_hooks() wired by register_model_executor_adapters() / register_v1_adapters(). MusaRMSNorm.forward_oot() now delegates to IR. New docs/vllm_musa/registration.md and tests/test_registration_architecture.py.

Blocking 1 — stale MLA drift tripwire. tools/musa_sync.py computes the cat-4a tripwire as difflib.unified_diff(upstream_file, ROOT / entry.path) (_module_tripwire, the shadow = ROOT / entry.path line), so editing the shadow copy invalidates it. I recomputed it locally with the script's own normalization against upstream vllm/model_executor/layers/attention/mla_attention.py at pin 5df63a7203cdb9328d824a27b682e77c7b9928be (third_party/PINS): it matches the stored vllm_musa/patches/module-drift/v1.attention.backends.mla.common.diff byte-for-byte at base 4191986845371897641aa04fdb98096d524f4b69, and does not match at head. gh pr checks 365 reports offline-series fail 1m12s (build pass, deploy skipping); the job log ends with [4a] drifted-copy v1.attention.backends.mla.common (upstream changed under the copy), --- 221 clean / 257 total / 1 need attention (drifted-copy) ---, === musa_sync verify: FAIL (divergence=1, series-format=0, numbering=0) ===. Regenerating the tripwire is the whole fix; the MLA hook conversion itself looks correct.

Blocking 2 — documented VLLM_PLUGINS value no longer matches anything. At the pin, vllm/plugins/__init__.py::load_plugins_by_group() filters with if allowed_plugins is None or plugin.name in allowed_plugins, and vllm/envs.py defines VLLM_PLUGINS as os.environ["VLLM_PLUGINS"].split(","). After this rename, ["musa", "musa_custom_ops"] matches only the platform plugin; neither musa_out_of_tree nor musa_attn_backends loads, so _register_patches(), _register_ops() and _register_modules() never run. A local grep over the head tree finds 34 files containing VLLM_PLUGINS=musa,musa_custom_ops (docs/installation.md:113, docs/installation-cn.md:102, 15 docs/cookbook/qwen/*.md, example/generate/README.md) plus example/generate/qwen3_5_offline.py:17 setting it in code. Nothing warns: the run starts on the MUSA platform with no OOT layers, no runtime patches, no custom-op preload, and no attention-backend registration. Either keep a musa_custom_ops entry point (safe, register_custom_ops() is idempotent) or sweep all 35 sites.

Nits. (1) The parallel_state shim was not updated alongside the eagle shim: its import vllm_musa.v1.spec_decode.utils now only imports, since install_hooks() is the sole installer — harmless at this pin because the upstream wrapper captures eagle_prepare_next_token_padded_kernel in its @triton_kernel_dispatcher_with_warmup(kernel=...) decorator before any rebind can matter, but the comment now describes a mechanism that no longer exists. (2) turboquant.py keeps a module-level install_hooks() call and is absent from EXPLICIT_INSTALLER_MODULES, so the new contract test neither wires nor covers it, and register_v1_adapters() does not call it. (3) kernels/__init__.py claims importing vllm_musa.kernels.<name> no longer registers IR providers, but kernels/musa_ops.py and kernels/gated_qkv.py both import vllm_musa.ir.* and do register (and ir/musa_ops.py calls current_platform.import_kernels() at import).

Checked, no finding. docs/vllm_musa/registration.md is linked from its directory README, has one H1 and no heading-level jumps, and names the same entry points as pyproject.toml. No pins or --flag usage change in this diff, so there was nothing to verify against third_party/PINS beyond the vLLM revision above. No repository-native checker other than offline-series covers these files, and I did not re-run the gate.

Not verified. No MUSA hardware in this session: the PR's S5000 checklist (pip install -e ., pytest tests/test_musa.py tests/test_patches.py, …) is entirely unchecked, the new runtime tests skip off-device, and CPU CI cannot prove MUSA runtime behavior. I read no test or benchmark result for this head except the gh pr checks lines quoted above.

auto-review round 1/3 · verdict: blockers

_install_prefill_backend_hook(vllm.model_executor.layers.attention.mla_attention)
_install_prefill_backend_hook(vllm.v1.attention.backends.mla.prefill)
_install_prefill_backend_hook(vllm.v1.attention.backends.mla.prefill.selector)
_HOOKS_INSTALLED = False

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 — Regenerate the MLA drift tripwire for this edit

tools/musa_sync.py recomputes this cat-4a tripwire as a diff between upstream mla_attention.py and the shadow copy this PR edits, while vllm_musa/patches/module-drift/v1.attention.backends.mla.common.diff stays untouched. offline-series now fails with [4a] drifted-copy v1.attention.backends.mla.common and musa_sync verify: FAIL (divergence=1).

Fix: run python tools/musa_sync.py regen --area module and commit the regenerated diff.

Comment thread pyproject.toml
[project.entry-points."vllm.general_plugins"]
musa_custom_ops = "vllm_musa:register_custom_ops"
musa_out_of_tree = "vllm_musa:register_out_of_tree"
musa_attn_backends = "vllm_musa:register_attn_backends"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 — Keep the documented VLLM_PLUGINS name working

At pinned vLLM 5df63a7, load_plugins_by_group() loads a general plugin only when plugin.name in envs.VLLM_PLUGINS, and VLLM_PLUGINS is a comma-split list. Renaming musa_custom_ops leaves 35 documented sites (docs/installation.md:113, the cookbook pages, both example/generate scripts) matching neither new name, so no general plugin loads and patches, OOT layers and backends are silently skipped.

Fix: keep musa_custom_ops as a third entry point, or sweep every VLLM_PLUGINS value.

Suggested change
musa_attn_backends = "vllm_musa:register_attn_backends"
[project.entry-points."vllm.general_plugins"]
musa_custom_ops = "vllm_musa:register_custom_ops"
musa_out_of_tree = "vllm_musa:register_out_of_tree"
musa_attn_backends = "vllm_musa:register_attn_backends"

@yeahdongcn

Copy link
Copy Markdown
Collaborator Author

S5000 Validation Results (61b9263fc)

  • Host / Hardware: worker34068 (10.20.34.68), GPUs 6 & 7 (MTT S5000, UUIDs b53a10c5-ff20-ad53-69b0-3d2a7fa31b2a, 4ad6c7b6-57a5-d6cf-de61-cf1d8861aab4)
  • Pre-built Image: sh-harbor.mthreads.com/mcctest/vllm:v0.32.0-ph1-5.2.0-torch2.13.0.post1-20261124@sha256:3bd17e280acd003685a88a337cde333022c713449bfd59a0a7ab6936619fa889
  • Stack: Python 3.12.16, torch 2.13.0.post1+musa5.2.0, torchada 0.1.111, mate 0.2.8.post1, triton 3.2.0, vllm 0.32.0
  • Entry points verified:
    • vllm.platform_plugins: musa -> vllm_musa:musa_platform_plugin
    • vllm.general_plugins: musa_out_of_tree -> vllm_musa:register_out_of_tree, musa_attn_backends -> vllm_musa:register_attn_backends (+ upstream LoRA resolvers)
  • Test results:
    • tests/test_registration_architecture.py (including fresh-process plugin startup/idempotency/preload/AOT-extension/IR-isolation check and MUSA RMSNorm OOT->IR dispatch + numerical parity): 24/24 passed
    • tests/test_v1_worker_import_order.py (including isolated GPU worker import order + runner hooks via general plugin): 9/9 passed
    • tests/test_fused_add_rms_norm_compile.py: 2/2 passed
    • tests/test_custom_op_preload.py: 2/2 passed
    • tests/test_musa.py + tests/test_deepseek_v4_fused_add_rmsnorm.py: 83/83 passed
    • tests/test_patches.py: 70 passed, 2 failed (pre-existing test_deepseek_v4_tp8_uses_contract_without_profile_env / test_deepseek_v4_tp8_flashmla_uses_validated_page256 where optimization_contract expects TP8 page-256; untouched by this PR).
  • Cleanup: temporary container hlease-reg-pr365-68-gpu6_7 and /tmp/pr365-files.tgz removed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant