Skip to content

Commit eff4b57

Browse files
authored
Recover offline_inference_npu.py to make doctest passed (#1756)
### What this PR does / why we need it? Rename offline_inference_npu_v1.py to offline_inference_npu.py to recover doctest ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? CI passed - vLLM version: v0.9.2 - vLLM main: vllm-project/vllm@a859323 Signed-off-by: Yikun Jiang <yikunkero@gmail.com>
1 parent 8b3a483 commit eff4b57

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

.github/workflows/vllm_ascend_doctest.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ jobs:
7575
echo "Replacing /vllm-workspace/vllm-ascend/tests/e2e ..."
7676
rm -rf /vllm-workspace/vllm-ascend/tests/e2e
7777
mkdir -p /vllm-workspace/vllm-ascend/tests
78+
# Overwrite e2e and examples
7879
cp -r tests/e2e /vllm-workspace/vllm-ascend/tests/
80+
cp -r examples /vllm-workspace/vllm-ascend/
7981
8082
# Simulate container to enter directory
8183
cd /workspace

examples/offline_inference_npu.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#
2+
# Copyright (c) 2025 Huawei Technologies Co., Ltd. All Rights Reserved.
3+
# This file is a part of the vllm-ascend project.
4+
# Adapted from vllm-project/vllm/examples/offline_inference/basic.py
5+
# Copyright 2023 The vLLM team.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
# isort: skip_file
21+
import os
22+
23+
os.environ["VLLM_USE_MODELSCOPE"] = "True"
24+
25+
from vllm import LLM, SamplingParams
26+
27+
prompts = [
28+
"Hello, my name is",
29+
"The president of the United States is",
30+
"The capital of France is",
31+
"The future of AI is",
32+
]
33+
34+
# Create a sampling params object.
35+
sampling_params = SamplingParams(max_tokens=100, temperature=0.0)
36+
# Create an LLM.
37+
llm = LLM(model="Qwen/Qwen2.5-0.5B-Instruct")
38+
39+
# Generate texts from the prompts.
40+
outputs = llm.generate(prompts, sampling_params)
41+
for output in outputs:
42+
prompt = output.prompt
43+
generated_text = output.outputs[0].text
44+
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

0 commit comments

Comments
 (0)