Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
0d81ab2
feat(platform): enable model runner v2 by default via whitelists
yjyang62 Sep 10, 2026
49c9f3b
test(rlhf): pin sleep/wake e2e to model runner v1
yjyang62 Sep 14, 2026
4b97bc5
fix(platform): isolate MRv2 extras when V2 is whitelist-enabled
yjyang62 Sep 14, 2026
32eb36e
fix(platform): ignore MagicMock use_v2_model_runner in extra ctx
yjyang62 Sep 14, 2026
b0e7077
fix(attention): gate FIA graph_task_group on ACL stream capture
yjyang62 Sep 15, 2026
2c0efe5
fix(attention): treat MagicMock stream capturing as idle
yjyang62 Sep 15, 2026
ab5c4cf
fix(platform): disable default MRv2 for LoRA and dynamic spec decode
yjyang62 Sep 15, 2026
4605ad5
fix(worker): map CUDA stream capturing to NPU in MRv2
yjyang62 Sep 15, 2026
0ddd7f1
test(e2e): drop NZ-graph prefetch xfail under default MRv2
yjyang62 Sep 16, 2026
669d378
fix(platform): isolate MRv2 extras via current VllmConfig
yjyang62 Sep 16, 2026
25b7c9e
refactor(platform): inline extra-ctx V2 isolation check
yjyang62 Sep 16, 2026
676ebe7
refactor(platform): drop extra-ctx try around V2 check
yjyang62 Sep 16, 2026
3538c10
refactor(platform): restore original extra-ctx kwargs access
yjyang62 Sep 16, 2026
0527596
fix(platform): treat unset VllmConfig as V1 extra-ctx
yjyang62 Sep 16, 2026
bd955ec
fix(platform): keep extra-ctx V2 isolation out of Dynamo
yjyang62 Sep 16, 2026
a2bc395
fix(platform): keep extra-ctx __getattr__ visible to mypy
yjyang62 Sep 16, 2026
4c03f47
test(platform): assert torch 2.10 Dynamo disable tag
yjyang62 Sep 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/e2e/pull_request/one_card/rlhf/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def server(
**os.environ,
"VLLM_SERVER_DEV_MODE": "1",
"HF_HUB_OFFLINE": "1",
# Qwen3ForCausalLM now defaults to MRv2. Sleep/wake generate is still
# V1-only; pin the RLHF server to V1 until the MRv2 allocator path is
# ready. Keep this on the subprocess env only.
"VLLM_USE_V2_MODEL_RUNNER": "0",
}
base = _DUMMY_ARGS if dummy_weights else _BASE_ARGS
cmd = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@


@pytest.fixture(autouse=True)
def default_vllm_config():
def default_vllm_config(monkeypatch):
# Qwen3 now defaults to the V2 model runner, whose forward-context hook
# (NPUPlatform.set_additional_forward_context) queries TP/DP groups. This
# suite drives attention backends in a single process with no engine, so
# mock the group accessors, mirroring patch_distributed_groups above.
monkeypatch.setattr("vllm.distributed.get_tensor_model_parallel_world_size", lambda: 1)
monkeypatch.setattr("vllm.distributed.get_dp_group", lambda: MagicMock(world_size=1))
mock_config = MagicMock()
mock_config.compilation_config = MagicMock()
mock_config.compilation_config.custom_ops = ["all"]
Expand Down
20 changes: 3 additions & 17 deletions tests/e2e/pull_request/one_card/test_cpu_weight_offload.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,9 @@ def _compare_offload_logprobs(
pytest.param(True, 0, id="ND-eager"),
pytest.param(False, 0, id="ND-graph"),
pytest.param(True, 2, id="NZ-eager"),
# TODO(wangfiox): nz+graph not supported yet
pytest.param(
False,
2,
id="NZ-graph",
marks=pytest.mark.xfail(
strict=True,
reason=(
"NZ static buffers make the prefetch H2D copy a "
"cross-format (ND->NZ) conversion that is aclop-only on "
"CANN 9.0.0 and rejected during ACL graph capture; "
"AscendPrefetchOffloader fails fast with a clear error "
"for this combo. Remove this marker and the offloader "
"guard once the no-transdata prefetch path lands."
),
),
),
# Qwen3 defaults to MRv2; GPU V2 prefetch + NZ graph now matches the
# eager baseline. V1 still fail-fasts in AscendPrefetchOffloader.
pytest.param(False, 2, id="NZ-graph"),
],
)
@wait_until_npu_memory_free()
Expand Down
5 changes: 5 additions & 0 deletions tests/ut/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ def synchronize(self):
torch.npu.graph_task_update_begin = MagicMock()
torch.npu.graph_task_update_end = MagicMock()
torch.npu.stream = MagicMock()
# cpu-ut is never capturing an ACL graph. Leave this unstubbed and
# is_current_stream_capturing() is a truthy MagicMock, which would send
# FIA into graph_task_group_begin.
torch.npu.is_current_stream_capturing = MagicMock(return_value=False)
# Some code paths do `import torch.npu`; attribute assignment alone is not enough.
sys.modules["torch.npu"] = torch.npu
torch_npu.npu.Stream = _NpuStreamStub # type: ignore[attr-defined]
Expand Down Expand Up @@ -253,6 +257,7 @@ def synchronize(self):
# Re-sync after enable_custom_op / adapt_patch so @patch("torch.npu.*") hits
# the same object production code uses via `torch.npu`.
torch.npu.current_device = MagicMock(return_value="cpu")
torch.npu.is_current_stream_capturing = MagicMock(return_value=False)
sys.modules["torch.npu"] = torch.npu

# Clean up any stale mock modules that may have been installed by
Expand Down
32 changes: 28 additions & 4 deletions tests/ut/patch/platform/test_patch_use_v2_model_runner.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import pytest
from vllm.config.vllm import VllmConfig

from vllm_ascend.patch.platform import patch_use_v2_model_runner
from vllm_ascend.utils import vllm_version_is


def test_use_v2_model_runner_is_driven_by_ascend_whitelist():
assert isinstance(VllmConfig.use_v2_model_runner, property)
from vllm_ascend.mrv2_utils import use_v2_model_runner

assert VllmConfig.use_v2_model_runner.fget is use_v2_model_runner


def test_ascend_v1_supported_features_are_not_rejected(monkeypatch):
if vllm_version_is("0.28.0"):
assert "_get_v1_model_runner_unsupported_features" not in VllmConfig.__dict__
return
if not hasattr(VllmConfig, "_get_v1_model_runner_unsupported_features"):
pytest.skip("V1 model runner validation is only present on vLLM main")

monkeypatch.setattr(
patch_use_v2_model_runner,
Expand All @@ -23,3 +29,21 @@ def test_ascend_v1_supported_features_are_not_rejected(monkeypatch):
unsupported = patch_use_v2_model_runner._patched_get_v1_model_runner_unsupported_features(object())

assert unsupported == ["prefill context parallel", "diffusion models"]


def test_release_pcp_is_not_rejected_as_v2_unsupported_feature(monkeypatch):
monkeypatch.setattr(patch_use_v2_model_runner, "vllm_version_is", lambda version: version == "0.28.0")
monkeypatch.setattr(
patch_use_v2_model_runner,
"_original_get_unsupported_features",
lambda _: ["prefill context parallelism", "diffusion models"],
)
monkeypatch.setattr(
patch_use_v2_model_runner,
"resolve_spec_pp_support",
lambda _: None,
)

unsupported = patch_use_v2_model_runner._patched_get_unsupported_features(object())

assert unsupported == ["diffusion models"]
103 changes: 102 additions & 1 deletion tests/ut/test_ascend_forward_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def test_deepseek_v4_forward_passes_input_ids_to_layers(monkeypatch):

from vllm_ascend.models.deepseek_v4 import model as deepseek_v4

monkeypatch.setattr(afc.envs_vllm, "VLLM_USE_V2_MODEL_RUNNER", True)
monkeypatch.setattr(afc, "get_current_vllm_config", lambda: SimpleNamespace())
monkeypatch.setattr(afc, "use_v2_model_runner", lambda _cfg: True)
monkeypatch.setattr(
deepseek_v4,
"get_pp_group",
Expand Down Expand Up @@ -511,3 +512,103 @@ def fake_set_forward_context(**_kwargs):
assert seen["config"] is vllm_config

assert seen["inside"] is False


def _is_dynamo_disabled(fn) -> bool:
# torch 2.10 tags `_torchdynamo_disable`; older torch used `_dynamo_disable`.
return bool(getattr(fn, "_torchdynamo_disable", False) or getattr(fn, "_dynamo_disable", False))


def test_extra_ctx_v2_isolation_is_dynamo_disabled():
# Compiled attention/MoE read _EXTRA_CTX. Dynamo cannot trace
# use_v2_model_runner's logger.warning_once / info_once.
assert _is_dynamo_disabled(afc._use_v2_extra_kwargs)
assert _is_dynamo_disabled(afc._extra_ctx_getattr)
assert _is_dynamo_disabled(afc._extra_ctx_setattr)


def test_extra_ctx_whitelist_v2_hides_gpu_capturing_flag(monkeypatch):
# GPU V2 ForwardContext has no vllm_config. Isolation must follow
# use_v2_model_runner(get_current_vllm_config()), not ctx.vllm_config.
monkeypatch.setattr(afc, "get_current_vllm_config", lambda: SimpleNamespace())
monkeypatch.setattr(afc, "use_v2_model_runner", lambda _cfg: True)
forward_context = SimpleNamespace(
additional_kwargs={},
capturing=True,
)
monkeypatch.setattr(afc, "get_forward_context", lambda: forward_context)

assert afc._EXTRA_CTX.capturing is None
afc._EXTRA_CTX.capturing = False
assert afc._EXTRA_CTX.capturing is False
assert forward_context.capturing is True
assert forward_context.additional_kwargs["capturing"] is False


def test_extra_ctx_v1_stores_capturing_on_context(monkeypatch):
monkeypatch.setattr(afc, "get_current_vllm_config", lambda: SimpleNamespace())
monkeypatch.setattr(afc, "use_v2_model_runner", lambda _cfg: False)
forward_context = SimpleNamespace(
additional_kwargs={},
capturing=False,
)
monkeypatch.setattr(afc, "get_forward_context", lambda: forward_context)

afc._EXTRA_CTX.capturing = True
assert afc._EXTRA_CTX.capturing is True
assert forward_context.capturing is True
assert "capturing" not in forward_context.additional_kwargs


def test_extra_ctx_env_override_wins_over_whitelist(monkeypatch):
monkeypatch.setattr(afc, "get_current_vllm_config", lambda: SimpleNamespace())
monkeypatch.setattr(afc, "use_v2_model_runner", lambda _cfg: False)
forward_context = SimpleNamespace(
additional_kwargs={},
capturing=False,
)
monkeypatch.setattr(afc, "get_forward_context", lambda: forward_context)

afc._EXTRA_CTX.capturing = True
assert forward_context.capturing is True
assert "capturing" not in forward_context.additional_kwargs


def test_extra_ctx_magicmock_forward_context_stays_on_v1_attrs(monkeypatch):
monkeypatch.setattr(afc, "get_current_vllm_config", lambda: MagicMock())
monkeypatch.setattr(afc, "use_v2_model_runner", lambda _cfg: MagicMock())
forward_context = MagicMock(capturing=False)
monkeypatch.setattr(afc, "get_forward_context", lambda: forward_context)

assert afc._EXTRA_CTX.capturing is False
afc._EXTRA_CTX.capturing = True
assert forward_context.capturing is True


def test_extra_ctx_unset_vllm_config_stays_on_v1_attrs(monkeypatch):
def _unset_config():
raise AssertionError("Current vLLM config is not set.")

monkeypatch.setattr(afc, "get_current_vllm_config", _unset_config)
forward_context = MagicMock(capturing=False)
monkeypatch.setattr(afc, "get_forward_context", lambda: forward_context)

assert afc._EXTRA_CTX.capturing is False
afc._EXTRA_CTX.capturing = True
assert forward_context.capturing is True


def test_extra_ctx_env_true_uses_additional_kwargs(monkeypatch):
monkeypatch.setattr(afc, "get_current_vllm_config", lambda: SimpleNamespace())
monkeypatch.setattr(afc, "use_v2_model_runner", lambda _cfg: True)
forward_context = SimpleNamespace(
additional_kwargs={},
capturing=True,
)
monkeypatch.setattr(afc, "get_forward_context", lambda: forward_context)

assert afc._EXTRA_CTX.capturing is None
afc._EXTRA_CTX.capturing = False
assert afc._EXTRA_CTX.capturing is False
assert forward_context.capturing is True
assert forward_context.additional_kwargs["capturing"] is False
Loading
Loading