[Bugfix] Defer VoxCPM2 NPU patch to avoid platform import cycle (#8330)

Signed-off-by: amy-why-3459 <wuhaiyan17@huawei.com>
This commit is contained in:
amy-why-3459 authored and GitHub committed 2026-09-30 05:25:36 -07:00
1 parent 56763cd6c3
commit 4af28f33bd
4 files changed
+34 -10

No files matched your search

@@ -231,8 +231,12 @@ def _cfm_inputs(
time_emb = torch.randn(batch_size, 1, hidden, device=device)
cnn_cache = torch.randn(depth, batch_size, hidden, 2, device=device)
att_cache = torch.randn(depth, batch_size, 1, old_att_len, hidden, device=device)
cnn_out = torch.empty(depth, batch_size, hidden, 2, device=device)
att_out = torch.empty(depth, batch_size, 1, old_att_len + chunk_size, hidden, device=device)
# The fake estimator only fills ``att_out[:, :, :, :chunk_size]``. The tail
# is the previous cache slot and is not written. ``empty`` leaves it
# uninitialized, so eager and replay compare different garbage and CI
# fails when that garbage is NaN.
cnn_out = torch.zeros(depth, batch_size, hidden, 2, device=device)
att_out = torch.zeros(depth, batch_size, 1, old_att_len + chunk_size, hidden, device=device)
return estimator_input, time_emb, cnn_cache, att_cache, cnn_out, att_out
@@ -76,12 +76,13 @@ def test_model_patch_wraps_init_and_is_idempotent(monkeypatch) -> None:
assert model.prefix == "talker"
def test_npu_platform_registers_patch_and_keeps_worker_cls(monkeypatch) -> None:
def test_npu_platform_defers_patch_until_device_setup(monkeypatch) -> None:
pytest.importorskip(
"vllm_ascend",
reason="NPU platform registration requires the optional vllm-ascend plugin",
)
from vllm_ascend import utils as ascend_utils
from vllm_ascend.platform import NPUPlatform
from vllm_omni.platforms.npu import _310p
from vllm_omni.platforms.npu.models import (
@@ -115,7 +116,21 @@ def test_npu_platform_registers_patch_and_keeps_worker_cls(monkeypatch) -> None:
worker_cls = NPUOmniPlatform.get_omni_ar_worker_cls()
assert worker_cls == "vllm_omni.platforms.npu.worker.npu_ar_worker.NPUARWorker"
assert calls == ["voxcpm2"]
assert calls == []
device = torch.device("npu:0")
monkeypatch.setattr(
NPUPlatform,
"set_device",
classmethod(lambda cls, device: calls.append(("set_device", device))),
)
monkeypatch.setattr(ascend_utils, "enable_custom_op", lambda: calls.append("custom_ops"))
monkeypatch.setattr(torch.npu, "config", SimpleNamespace(allow_internal_format=False))
NPUOmniPlatform.set_device(device)
assert calls == [("set_device", device), "voxcpm2", "custom_ops"]
assert torch.npu.config.allow_internal_format
def test_loc_dit_npugraph_supports_wrapped_subclass_and_wraps_once(monkeypatch) -> None: