|
| 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 | +MODELS = ["deepseek-ai/DeepSeek-V2-Lite"] |
| 30 | + |
| 31 | + |
| 32 | +@pytest.mark.skipif(os.getenv("VLLM_USE_V1") == "0", |
| 33 | + reason="new chunked only support on v1") |
| 34 | +@pytest.mark.parametrize("model", MODELS) |
| 35 | +@pytest.mark.parametrize("max_tokens", [1]) |
| 36 | +def test_models( |
| 37 | + model: str, |
| 38 | + max_tokens: int, |
| 39 | + monkeypatch: pytest.MonkeyPatch, |
| 40 | +) -> None: |
| 41 | + return |
| 42 | + with monkeypatch.context() as m: |
| 43 | + prompts = "The president of the United States is" |
| 44 | + |
| 45 | + m.setenv("VLLM_USE_V1", "1") |
| 46 | + |
| 47 | + sampling_params = SamplingParams( |
| 48 | + max_tokens=max_tokens, |
| 49 | + temperature=0.0, |
| 50 | + ) |
| 51 | + |
| 52 | + vllm_model = LLM(model, |
| 53 | + long_prefill_token_threshold=4, |
| 54 | + enforce_eager=True) |
| 55 | + output_chunked = vllm_model.generate(prompts, sampling_params) |
| 56 | + logprobs_chunked = output_chunked.outputs[0].logprobs |
| 57 | + del vllm_model |
| 58 | + torch.npu.empty_cache() |
| 59 | + |
| 60 | + vllm_model = LLM(model, |
| 61 | + enforce_eager=True, |
| 62 | + additional_config={ |
| 63 | + 'ascend_scheduler_config': { |
| 64 | + 'enabled': True |
| 65 | + }, |
| 66 | + }) |
| 67 | + output = vllm_model.generate(prompts, sampling_params) |
| 68 | + logprobs = output.outputs[0].logprobs |
| 69 | + del vllm_model |
| 70 | + torch.npu.empty_cache() |
| 71 | + |
| 72 | + logprobs_similarity = torch.cosine_similarity( |
| 73 | + logprobs_chunked.flatten(), logprobs.flatten(), dim=0) |
| 74 | + assert logprobs_similarity > 0.95 |
0 commit comments