|
| 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