Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e1bce00
upgrade main2main0612
zhangxinyuehfad Jun 29, 2026
5b230b4
upgrade main2main0612
zhangxinyuehfad Jun 29, 2026
436f751
upgrade main2main0612
zhangxinyuehfad Jun 29, 2026
cd05dbc
upgrade vllm 0619
zhangxinyuehfad Jun 29, 2026
d007b3d
fix lint
zhangxinyuehfad Jun 29, 2026
a252718
upgrade vllm 0619
zhangxinyuehfad Jun 30, 2026
b2331b3
upgrade vllm 0619
zhangxinyuehfad Jun 30, 2026
f62648a
fix
zhangxinyuehfad Jun 30, 2026
8cc9568
set VLLM_USE_V2_MODEL_RUNNER = 0
zhangxinyuehfad Jun 30, 2026
6eae03b
fix lint
zhangxinyuehfad Jun 30, 2026
1875fc3
upgrade vllm v0.24.0
zhangxinyuehfad Jul 1, 2026
6bf00a0
fix: resolve compatibility issues with vllm dev builds post-0.23.0
zhangxinyuehfad Jul 1, 2026
519339f
fix: resolve compatibility issues with vllm dev builds post-0.23.0
zhangxinyuehfad Jul 1, 2026
8a03bda
fix: resolve compatibility issues with vllm dev builds post-0.23.0
zhangxinyuehfad Jul 1, 2026
719ddd1
fix: resolve compatibility issues with vllm dev builds post-0.23.0
zhangxinyuehfad Jul 1, 2026
3d5316b
fix: resolve compatibility issues with vllm dev builds post-0.23.0
zhangxinyuehfad Jul 1, 2026
ac7d542
fix: resolve compatibility issues with vllm dev builds post-0.23.0
zhangxinyuehfad Jul 1, 2026
5517336
fix lint
zhangxinyuehfad Jul 2, 2026
54bcff5
fix lint
zhangxinyuehfad Jul 2, 2026
0b42f51
fix lint
zhangxinyuehfad Jul 2, 2026
9350c64
fix: patch _get_kv_cache_config_packed to fix OOM with vllm v0.24.0
zhangxinyuehfad Jul 2, 2026
e0bd116
fix:isolate NPU devices for application-level DP when ASCEND_RT_VISIB…
zhangxinyuehfad Jul 3, 2026
f13be37
fix: isolate NPU devices for application-level DP when ASCEND_RT_VISI…
zhangxinyuehfad Jul 3, 2026
a0702cc
use _build_device_ids from vllm no-v0.23.0
zhangxinyuehfad Jul 4, 2026
cd7600a
revert test_process_weights_transposes_weights
zhangxinyuehfad Jul 4, 2026
663eeed
replace unit64 to int64 by MambaCopyBuffers
zhangxinyuehfad Jul 4, 2026
ec74a26
align _init_device with upstream gpu_worker.py init_device
zhangxinyuehfad Jul 4, 2026
954d773
fix
zhangxinyuehfad Jul 5, 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
2 changes: 1 addition & 1 deletion .github/vllm-main-verified.commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b9a7cd464c9ae9b1b450f8982b76d7be4de73724
ee0da84ab9e04ac7610e28580af62c365e898389
10 changes: 8 additions & 2 deletions examples/offline_data_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@ def main(
os.environ["VLLM_DP_MASTER_IP"] = dp_master_ip
os.environ["VLLM_DP_MASTER_PORT"] = str(dp_master_port)

# CUDA_VISIBLE_DEVICES for each DP rank is set automatically inside the
# engine processes.
from vllm_ascend.utils import vllm_version_is

_dp_device_ids = None
if not vllm_version_is("0.23.0"):
import torch

_dp_device_ids = [str(i) for i in range(torch.npu.device_count())]

# Sample prompts.
prompts = [
Expand Down Expand Up @@ -165,6 +170,7 @@ def start(rank):
enable_expert_parallel=enable_expert_parallel,
trust_remote_code=trust_remote_code,
quantization=quantization,
**({} if _dp_device_ids is None else {"device_ids": _dp_device_ids}),
)
outputs = llm.generate(prompts, sampling_params)
# Print the outputs.
Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,24 @@ def _run_vllm_runner_dp_worker(conn, llm_kwargs: dict[str, Any], dp_rank: int, d
os.environ["VLLM_DP_MASTER_PORT"] = str(master_port)
os.environ["VLLM_WORKER_MULTIPROC_METHOD"] = "spawn"

from vllm_ascend.utils import vllm_version_is

if not vllm_version_is("0.23.0"):
Comment thread
zhangxinyuehfad marked this conversation as resolved.
import torch

visible = os.environ.get("ASCEND_RT_VISIBLE_DEVICES", "")
full_device_ids: list[str] = [d for d in visible.split(",") if d]
if not full_device_ids:
full_device_ids = [str(i) for i in range(torch.npu.device_count())]

if llm_kwargs.get("distributed_executor_backend") == "ray":
devs = full_device_ids
chunk = max(len(devs) // dp_size, 1)
start = dp_rank * chunk
os.environ["ASCEND_RT_VISIBLE_DEVICES"] = ",".join(devs[start : start + chunk])
else:
llm_kwargs["device_ids"] = full_device_ids

llm = LLM(**llm_kwargs)
conn.send({"status": "ready", "rank": dp_rank})

Expand Down
4 changes: 4 additions & 0 deletions tests/ut/core/test_profiling_chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def test_invalid_min_chunk_raises(self):
ProfilingChunkConfig({"min_chunk": 0})

@patch("vllm.config.VllmConfig.__post_init__", MagicMock())
@patch("vllm.config.device.DeviceConfig.__post_init__", MagicMock())
Comment thread
zhangxinyuehfad marked this conversation as resolved.
@patch("vllm_ascend.platform.NPUPlatform._fix_incompatible_config")
def test_enabled_without_pp_raises(self, _mock):
clear_ascend_config()
Expand All @@ -106,6 +107,7 @@ def test_enabled_without_pp_raises(self, _mock):
clear_ascend_config()

@patch("vllm.config.VllmConfig.__post_init__", MagicMock())
@patch("vllm.config.device.DeviceConfig.__post_init__", MagicMock())
@patch("vllm_ascend.platform.NPUPlatform._fix_incompatible_config")
def test_enabled_with_pp_ok(self, _mock):
clear_ascend_config()
Expand All @@ -121,6 +123,7 @@ def test_enabled_with_pp_ok(self, _mock):
clear_ascend_config()

@patch("vllm.config.VllmConfig.__post_init__", MagicMock())
@patch("vllm.config.device.DeviceConfig.__post_init__", MagicMock())
@patch("vllm_ascend.platform.NPUPlatform._fix_incompatible_config")
def test_disabled_without_pp_ok(self, _mock):
clear_ascend_config()
Expand Down Expand Up @@ -246,6 +249,7 @@ class TestProfilingChunkScheduler(TestBase):
@patch("vllm_ascend.ascend_config.get_ascend_config")
@patch("vllm.config.ModelConfig.__post_init__", MagicMock())
@patch("vllm.config.VllmConfig.__post_init__", MagicMock())
@patch("vllm.config.device.DeviceConfig.__post_init__", MagicMock())
def create_scheduler(self, mock_get_ascend_config):
profiling_cfg = MagicMock()
profiling_cfg.enabled = True
Expand Down
15 changes: 15 additions & 0 deletions tests/ut/ops/test_gdn_attn_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dataclasses import dataclass
from types import SimpleNamespace
from typing import cast
from unittest.mock import patch

import pytest
import torch
Expand Down Expand Up @@ -35,6 +36,7 @@
from vllm_ascend.ops.triton.fla.utils import (
prepare_update_chunk_offsets as runtime_prepare_update_chunk_offsets,
)
from vllm_ascend.utils import vllm_version_is


@pytest.fixture(autouse=True)
Expand All @@ -48,6 +50,19 @@ def _patch_triton_cdiv(monkeypatch):
)


@pytest.fixture(autouse=True)
def _no_pin_memory():
# compute_causal_conv1d_metadata uses np_to_pinned_tensor which reads
# PIN_MEMORY. Without physical NPU, t.pin_memory() raises
# "Please register PrivateUse1HooksInterface first".
with patch("vllm.utils.torch_utils.PIN_MEMORY", False):
if vllm_version_is("0.23.0"):
yield
else:
with patch("vllm.v1.attention.backends.utils.PIN_MEMORY", False):
yield


@dataclass
class BatchSpec:
seq_lens: list[int]
Expand Down
6 changes: 4 additions & 2 deletions tests/ut/quantization/methods/test_w4a16_mxfp4.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest.mock import patch
from unittest.mock import Mock, patch

import pytest
import torch
Expand All @@ -17,10 +17,12 @@ class TestAscendW4A16MXFP4MoEMethod(TestBase):
@patch("vllm_ascend.quantization.methods.w4a16_mxfp4.ensure_mxfp4_moe_available")
@patch("vllm_ascend.quantization.methods.w4a16_mxfp4.get_current_vllm_config")
@patch("vllm_ascend.quantization.methods.w4a16_mxfp4.get_ascend_config")
def setUp(self, mock_ascend, mock_vllm, mock_ensure):
@patch("vllm_ascend.quantization.methods.w4a16_mxfp4.get_ep_group")
def setUp(self, mock_ep_group, mock_ascend, mock_vllm, mock_ensure):
mock_vllm.return_value = create_mock_vllm_config()
mock_ascend.return_value = create_mock_ascend_config()
mock_ensure.return_value = None
mock_ep_group.return_value = Mock()
self.scheme = AscendW4A16MXFP4FusedMoEMethod()

@pytest.mark.skip("Execute after the issue is fixed")
Expand Down
22 changes: 13 additions & 9 deletions tests/ut/spec_decode/test_extract_hidden_states_proposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,23 @@
from vllm_ascend.spec_decode.extract_hidden_states_proposer import (
AscendExtractHiddenStatesProposer,
)
from vllm_ascend.utils import vllm_version_is


@pytest.fixture(autouse=True)
def _no_pin_memory():
# On Ascend/NPU CI runners without physical hardware, torch.zeros(...,
# pin_memory=True) triggers aclInit and fails. Patch
# is_pin_memory_available so vllm's ExtractHiddenStatesProposer.__init__
# creates CpuGpuBuffer with pin_memory=False.
with patch(
"vllm.v1.spec_decode.extract_hidden_states.is_pin_memory_available",
return_value=False,
):
yield
if vllm_version_is("0.23.0"):
with patch(
"vllm.v1.spec_decode.extract_hidden_states.is_pin_memory_available",
return_value=False,
):
yield
else:
with patch(
"vllm.v1.spec_decode.extract_hidden_states.PIN_MEMORY",
False,
):
yield


class MockCachedRequestState:
Expand Down
12 changes: 10 additions & 2 deletions tests/ut/worker/a2/test_worker_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def test_wake_up_mode_enabled(self, mock_get_config, mock_allocator_class):
mock_allocator.wake_up.assert_called_once_with(tags=["test_tag"])
worker.sleep_wakeup_manager.wakeup.assert_called_once_with(["test_tag"])

@patch("vllm_ascend.worker.worker.current_platform")
@patch("vllm_ascend.worker.worker.MemorySnapshot")
@patch("vllm_ascend.worker.worker.NPUWorker._init_worker_distributed_environment")
@patch("vllm_ascend.worker.worker.init_device_properties_triton")
Expand All @@ -265,6 +266,7 @@ def test_init_device(
mock_init_triton,
mock_init_dist_env,
mock_snapshot_cls,
mock_current_platform,
):
"""Test _init_device method"""
from vllm_ascend.worker.worker import AscendDeviceType, NPUWorker
Expand All @@ -279,15 +281,21 @@ def test_init_device(
mock_snapshot.total_memory = 2000
mock_snapshot_cls.return_value = mock_snapshot

# Mock current_platform for v0.24.0 init_device path
mock_current_platform.logical_device_id_to_visible_device_id.return_value = 0
mock_current_platform.device_type = "npu"

# Create worker mock
with patch.object(NPUWorker, "__init__", lambda x, **kwargs: None):
worker = NPUWorker()
worker.local_rank = 1
worker.local_rank = 0
worker.model_config = MagicMock()
worker.model_config.seed = 42
worker.parallel_config = MagicMock()
worker.parallel_config.local_world_size = 0
worker.parallel_config.data_parallel_size = 1
worker.parallel_config.assigned_physical_gpu_ids = None
worker.parallel_config.distributed_executor_backend = "ray"
worker.vllm_config = MagicMock()
worker.vllm_config.kv_transfer_config = None
worker.cache_config = MagicMock()
Expand All @@ -297,7 +305,7 @@ def test_init_device(
result = worker._init_device()

mock_init_dist_env.assert_called_once()
self.assertEqual(str(result), "npu:1")
self.assertEqual(str(result), "npu:0")
self.assertEqual(worker.init_snapshot, mock_snapshot)
self.assertEqual(worker.requested_memory, 2000 * 0.5)

Expand Down
7 changes: 5 additions & 2 deletions vllm_ascend/_310p/worker_310p.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from vllm.utils.torch_utils import set_random_seed # noqa: E402

from vllm_ascend._310p.model_runner_310p import NPUModelRunner310
from vllm_ascend.utils import is_rc_device
from vllm_ascend.utils import is_rc_device, vllm_version_is
from vllm_ascend.worker.worker import NPUWorker, init_workspace_manager


Expand Down Expand Up @@ -137,7 +137,10 @@ def _init_device(self):
torch.npu.empty_cache()

# take current memory snapshot
self.init_snapshot = MemorySnapshot()
if vllm_version_is("0.23.0"):
self.init_snapshot = MemorySnapshot()
else:
self.init_snapshot = MemorySnapshot(device=device)
self.requested_memory = self.init_snapshot.total_memory * self.cache_config.gpu_memory_utilization
if is_rc_device():
self.init_snapshot.free_memory = psutil.virtual_memory().available
Expand Down
5 changes: 3 additions & 2 deletions vllm_ascend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# This file is a part of the vllm-ascend project.
#

import vllm_ascend.logger # noqa: F401

_GLOBAL_PATCH_APPLIED = False


Expand Down Expand Up @@ -75,3 +73,6 @@ def register_model():
from .models import register_model

register_model()


import vllm_ascend.logger # noqa: E402, F401

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why moving this here?

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.

To avoid circular imports when vLLM's plugin chain triggers during logger loading.

1 change: 1 addition & 0 deletions vllm_ascend/patch/platform/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@

if not vllm_version_is("0.23.0"):
import vllm_ascend.patch.platform.patch_fused_moe # noqa
import vllm_ascend.patch.platform.patch_dp_device_ids # noqa
72 changes: 72 additions & 0 deletions vllm_ascend/patch/platform/patch_dp_device_ids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#
# Copyright (c) 2025 Huawei Technologies Co., Ltd. All Rights Reserved.
# This file is a part of the vllm-ascend project.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Patch vLLM v0.24.0+ ``get_physical_gpu_ids_for_local_dp_rank`` so that it
# tolerates a pre-sharded ASCEND_RT_VISIBLE_DEVICES env var (one slice per
# DP rank), instead of unconditionally applying ``local_dp_rank * world_size``
# as an offset into it.
#
# Background:
# PR #45026 removed the per-process device isolation that older vLLM
# versions performed internally. Application-level DP (e.g.
# ``offline_data_parallel.py``) now has to slice ASCEND_RT_VISIBLE_DEVICES
# per rank itself, but the upstream helper still expects the env var to
# contain ALL devices for ALL ranks and tries to read it with the
# ``local_dp_rank * world_size`` offset. With a sharded env var, that
# offset is out of range and the helper raises ``IndexError`` (wrapped in
# the user-facing "Error computing device indices for ..." message).

from vllm_ascend.utils import vllm_version_is

if not vllm_version_is("0.23.0"):
import os

from vllm.platforms import current_platform
from vllm.v1.engine import utils as _engine_utils

_original_get_physical_gpu_ids = _engine_utils.get_physical_gpu_ids_for_local_dp_rank

def _patched_get_physical_gpu_ids_for_local_dp_rank(
device_control_env_var,
local_dp_rank,
world_size,
local_world_size=None,
user_assigned_gpu_ids=None,
):
if local_world_size is None:
local_world_size = world_size

# If the caller did not pass --device-ids and the env var has
# fewer devices than the full DP range expects, the env var has
# already been pre-sharded per rank by the caller. Use it
# directly from index 0 instead of applying the DP offset again.
if user_assigned_gpu_ids is None and device_control_env_var in os.environ:
visible = [d for d in os.environ[device_control_env_var].split(",") if d]
if local_dp_rank * world_size + local_world_size > len(visible):
return [
current_platform.device_control_id_to_physical_device_id(visible[device_id])
for device_id in range(local_world_size)
]

return _original_get_physical_gpu_ids(
device_control_env_var,
local_dp_rank,
world_size,
local_world_size,
user_assigned_gpu_ids,
)

_engine_utils.get_physical_gpu_ids_for_local_dp_rank = _patched_get_physical_gpu_ids_for_local_dp_rank
10 changes: 9 additions & 1 deletion vllm_ascend/patch/platform/patch_kv_cache_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
UniformTypeKVCacheSpecs,
)

from vllm_ascend.utils import vllm_version_is

_orig_resolve_kv_cache_block_sizes = vllm.v1.core.kv_cache_utils.resolve_kv_cache_block_sizes


Expand Down Expand Up @@ -249,8 +251,14 @@ def _get_kv_cache_config_deepseek_v4(

vllm.v1.core.kv_cache_utils.resolve_kv_cache_block_sizes = _ascend_resolve_kv_cache_block_sizes
vllm.v1.core.kv_cache_utils.group_and_unify_kv_cache_specs = group_and_unify_kv_cache_specs
vllm.v1.core.kv_cache_utils._get_kv_cache_config_deepseek_v4 = _get_kv_cache_config_deepseek_v4
vllm.v1.core.kv_cache_utils._get_kv_cache_groups_uniform_groups = _get_kv_cache_groups_uniform_groups
# vllm v0.24.0 renamed _get_kv_cache_config_deepseek_v4 to _get_kv_cache_config_packed and
# get_kv_cache_config_from_groups now calls _get_kv_cache_config_packed directly, bypassing
# the alias patch above. Patch the canonical name so Ascend's non-packed layout is used.
if vllm_version_is("0.23.0"):
vllm.v1.core.kv_cache_utils._get_kv_cache_config_deepseek_v4 = _get_kv_cache_config_deepseek_v4
else:
vllm.v1.core.kv_cache_utils._get_kv_cache_config_packed = _get_kv_cache_config_deepseek_v4

# Also patch the reference used by engine/core.py which imports the function directly.
import vllm.v1.engine.core # noqa: E402
Expand Down
18 changes: 18 additions & 0 deletions vllm_ascend/patch/worker/patch_mamba_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,24 @@ def _batch_memcpy_unavailable(src_ptrs, dst_ptrs, sizes):
mamba_utils.do_mamba_copy_block = _do_mamba_copy_block_torch
mamba_utils.postprocess_mamba_align_gpu = _postprocess_mamba_align_gpu_cpu_fallback

# Ascend NPU does not support DT_UINT64 in aclnnInplaceZero.
# MambaCopyBuffers.create() uses torch.uint64 for src_ptrs/dst_ptrs,
# which triggers a runtime error. Remap to int64 at the source.
_original_create = MambaCopyBuffers.create


@classmethod
def _patched_create(cls, max_num_reqs, kv_cache_config, copy_funcs, make_buffer):
return _original_create(
max_num_reqs,
kv_cache_config,
copy_funcs,
lambda n, dtype: make_buffer(n, dtype=torch.int64 if dtype == torch.uint64 else dtype),
)


MambaCopyBuffers.create = _patched_create


def preprocess_mamba(
scheduler_output: SchedulerOutput,
Expand Down
Loading
Loading