|
| 1 | +# |
| 2 | +# Copyright (c) 2025 Huawei Technologies Co., Ltd. All Rights Reserved. |
| 3 | +# Copyright 2023 The vLLM team. |
| 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 | +Compare the outputs of vLLM with and without aclgraph. |
| 19 | +
|
| 20 | +Run `pytest tests/compile/test_aclgraph.py`. |
| 21 | +""" |
| 22 | + |
| 23 | +import os |
| 24 | + |
| 25 | +import pytest |
| 26 | +import torch |
| 27 | +from vllm import LLM, SamplingParams |
| 28 | + |
| 29 | +from tests.conftest import VllmRunner |
| 30 | +from tests.model_utils import check_outputs_equal |
| 31 | +from vllm_ascend.utils import vllm_version_is |
| 32 | + |
| 33 | +MODELS = ["Qwen/Qwen2.5-0.5B-Instruct"] |
| 34 | + |
| 35 | + |
| 36 | +@pytest.mark.skipif(os.getenv("VLLM_USE_V1") == "0", |
| 37 | + reason="aclgraph only support on v1") |
| 38 | +@pytest.mark.skipif( |
| 39 | + (vllm_version_is("0.8.5") or vllm_version_is("0.8.5.post1")), |
| 40 | + reason="aclgraph not supported in v0.8.5 and v0.8.5.post1") |
| 41 | +@pytest.mark.parametrize("model", MODELS) |
| 42 | +@pytest.mark.parametrize("max_tokens", [32]) |
| 43 | +def test_models( |
| 44 | + model: str, |
| 45 | + max_tokens: int, |
| 46 | + monkeypatch: pytest.MonkeyPatch, |
| 47 | +) -> None: |
| 48 | + with monkeypatch.context() as m: |
| 49 | + prompts = [ |
| 50 | + "Hello, my name is", "The president of the United States is", |
| 51 | + "The capital of France is", "The future of AI is" |
| 52 | + ] |
| 53 | + |
| 54 | + # aclgraph only support on v1 |
| 55 | + m.setenv("VLLM_USE_V1", "1") |
| 56 | + |
| 57 | + sampling_params = SamplingParams(max_tokens=max_tokens, |
| 58 | + temperature=0.0) |
| 59 | + # TODO: change to use vllmrunner when the registry of custom op is solved |
| 60 | + # while running pytest |
| 61 | + vllm_model = LLM(model) |
| 62 | + vllm_aclgraph_outputs = vllm_model.generate(prompts, sampling_params) |
| 63 | + del vllm_model |
| 64 | + torch.npu.empty_cache() |
| 65 | + |
| 66 | + vllm_model = LLM(model, enforce_eager=True) |
| 67 | + vllm_eager_outputs = vllm_model.generate(prompts, sampling_params) |
| 68 | + del vllm_model |
| 69 | + torch.npu.empty_cache() |
| 70 | + |
| 71 | + vllm_aclgraph_outputs_list = [] |
| 72 | + for output in vllm_aclgraph_outputs: |
| 73 | + vllm_aclgraph_outputs_list.append( |
| 74 | + (output.outputs[0].index, output.outputs[0].text)) |
| 75 | + |
| 76 | + vllm_eager_outputs_list = [] |
| 77 | + for output in vllm_eager_outputs: |
| 78 | + vllm_eager_outputs_list.append( |
| 79 | + (output.outputs[0].index, output.outputs[0].text)) |
| 80 | + |
| 81 | + check_outputs_equal( |
| 82 | + outputs_0_lst=vllm_eager_outputs_list, |
| 83 | + outputs_1_lst=vllm_aclgraph_outputs_list, |
| 84 | + name_0="vllm_eager_outputs", |
| 85 | + name_1="vllm_aclgraph_outputs", |
| 86 | + ) |
| 87 | + |
| 88 | + |
| 89 | +@pytest.mark.skipif(os.getenv("VLLM_USE_V1") == "0", |
| 90 | + reason="aclgraph only support on v1") |
| 91 | +@pytest.mark.skipif( |
| 92 | + (vllm_version_is("0.8.5") or vllm_version_is("0.8.5.post1")), |
| 93 | + reason="aclgraph not supported in v0.8.5 and v0.8.5.post1") |
| 94 | +def test_deepseek_raises_error(monkeypatch: pytest.MonkeyPatch) -> None: |
| 95 | + with monkeypatch.context() as m: |
| 96 | + m.setenv("VLLM_USE_MODELSCOPE", "True") |
| 97 | + m.setenv("VLLM_USE_V1", "1") |
| 98 | + with pytest.raises(NotImplementedError) as excinfo: |
| 99 | + VllmRunner("deepseek-ai/DeepSeek-V2-Lite-Chat", |
| 100 | + max_model_len=1024, |
| 101 | + enforce_eager=False) |
| 102 | + assert "ACL Graph does not support deepseek" in str(excinfo.value) |
0 commit comments