Skip to content

Commit 4a0ce36

Browse files
[Misc] Remove some parts of metrics patch (#603)
### What this PR does / why we need it? Remove some parts of metrics patch, since the `cuda` hard code has been fixed by vllm-project/vllm#14411. Signed-off-by: shen-shanshan <467638484@qq.com>
1 parent cf6ab42 commit 4a0ce36

File tree

4 files changed

+69
-40
lines changed

4 files changed

+69
-40
lines changed

vllm_ascend/patch/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
#
9191
# * Worker Patch:
9292
# ===============
93-
# ** File: worker/patch_common/patch_metrics.py **
93+
# ** File: worker/patch_0_8_4/patch_metrics.py **
9494
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9595
# 1. `vllm.spec_decode.metrics.AsyncMetricsCollector.init_tensors` and
9696
# `vllm.spec_decode.metrics.AsyncMetricsCollector._copy_rejsample_metrics_async`
@@ -104,7 +104,9 @@
104104
# Future Plan:
105105
# Revert it when the related pr is merged in vllm.
106106
#
107-
# 2. `vllm.spec_decode.metrics.AsyncMetricsCollector.maybe_collect_rejsample_metrics`
107+
# ** File: worker/patch_common/patch_metrics.py **
108+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109+
# 1. `vllm.spec_decode.metrics.AsyncMetricsCollector.maybe_collect_rejsample_metrics`
108110
# Why:
109111
# There are cuda hard code (current_platform.is_cuda_alike()) in
110112
# `AsyncMetricsCollector.maybe_collect_rejsample_metrics`

vllm_ascend/patch/worker/patch_0_8_4/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
#
16+
#
17+
18+
import vllm_ascend.patch.worker.patch_0_8_4.patch_metrics # noqa
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#
2+
# Copyright (c) 2025 Huawei Technologies Co., Ltd. All Rights Reserved.
3+
# This file is a part of the vllm-ascend project.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
from typing import Callable, Optional, Union
19+
20+
import torch
21+
import torch_npu
22+
from vllm.spec_decode.metrics import (AsyncMetricsCollector,
23+
SpecDecodeWorkerMetrics)
24+
25+
Timer = Callable[[], float]
26+
27+
# TODO: revert this patch when the cuda hard code is removed in vllm
28+
# init_tensors: Modified the hard-coded cuda judgment logic to npu;
29+
# maybe_collect_rejsample_metrics: Removed the check for current_platform.is_cuda_alike()
30+
31+
32+
def init_tensors(self,
33+
rank: int,
34+
device_type: Union[torch.device, str] = 'npu') -> None:
35+
self._rank = rank
36+
if isinstance(device_type, torch.device):
37+
device_type = device_type.type
38+
if device_type == 'npu':
39+
self._copy_stream = torch_npu.npu.Stream()
40+
41+
42+
def maybe_collect_rejsample_metrics(
43+
self, k: int) -> Optional[SpecDecodeWorkerMetrics]:
44+
45+
# If a copy was initiated in the previous call, collect and return.
46+
if self._in_flight_copy is not None:
47+
ready_event = self._in_flight_copy
48+
self._in_flight_copy = None
49+
return self._collect_rejsample_metrics(k, ready_event)
50+
51+
# Otherwise, check if we should start a new copy.
52+
if self._should_collect_rejsample_metrics(self._timer()):
53+
assert self._in_flight_copy is None
54+
self._in_flight_copy = self._copy_rejsample_metrics_async()
55+
56+
return None
57+
58+
59+
AsyncMetricsCollector.init_tensors = init_tensors
60+
AsyncMetricsCollector.maybe_collect_rejsample_metrics = maybe_collect_rejsample_metrics

vllm_ascend/patch/worker/patch_common/patch_metrics.py

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,13 @@
1515
# limitations under the License.
1616
#
1717

18-
from typing import Callable, Optional, Union
18+
from typing import Callable
1919

2020
import torch
21-
import torch_npu
22-
from vllm.spec_decode.metrics import (AsyncMetricsCollector,
23-
SpecDecodeWorkerMetrics)
21+
from vllm.spec_decode.metrics import AsyncMetricsCollector
2422

2523
Timer = Callable[[], float]
2624

27-
# TODO: revert this patch when the cuda hard code is removed in vllm
28-
# init_tensors: Modified the hard-coded cuda judgment logic to npu;
29-
# maybe_collect_rejsample_metrics: Removed the check for current_platform.is_cuda_alike()
30-
31-
32-
def init_tensors(self,
33-
rank: int,
34-
device_type: Union[torch.device, str] = 'npu') -> None:
35-
self._rank = rank
36-
if isinstance(device_type, torch.device):
37-
device_type = device_type.type
38-
if device_type == 'npu':
39-
self._copy_stream = torch_npu.npu.Stream()
40-
41-
42-
def maybe_collect_rejsample_metrics(
43-
self, k: int) -> Optional[SpecDecodeWorkerMetrics]:
44-
45-
# If a copy was initiated in the previous call, collect and return.
46-
if self._in_flight_copy is not None:
47-
ready_event = self._in_flight_copy
48-
self._in_flight_copy = None
49-
return self._collect_rejsample_metrics(k, ready_event)
50-
51-
# Otherwise, check if we should start a new copy.
52-
if self._should_collect_rejsample_metrics(self._timer()):
53-
assert self._in_flight_copy is None
54-
self._in_flight_copy = self._copy_rejsample_metrics_async()
55-
56-
return None
57-
5825

5926
def _copy_rejsample_metrics_async(self) -> torch.npu.Event:
6027
"""
@@ -83,6 +50,4 @@ def _copy_rejsample_metrics_async(self) -> torch.npu.Event:
8350
return aggregate_metrics_ready
8451

8552

86-
AsyncMetricsCollector.init_tensors = init_tensors
87-
AsyncMetricsCollector.maybe_collect_rejsample_metrics = maybe_collect_rejsample_metrics
8853
AsyncMetricsCollector._copy_rejsample_metrics_async = _copy_rejsample_metrics_async

0 commit comments

Comments
 (0)