|
| 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 | +# This file is a part of the vllm-ascend project. |
| 17 | +# |
| 18 | +"""Compare the short outputs of HF and vLLM when using greedy sampling. |
| 19 | +
|
| 20 | +Run `pytest tests/multicard/test_torchair_graph_mode.py`. |
| 21 | +""" |
| 22 | +import os |
| 23 | + |
| 24 | +import pytest |
| 25 | + |
| 26 | +from tests.conftest import VllmRunner |
| 27 | + |
| 28 | +os.environ["PYTORCH_NPU_ALLOC_CONF"] = "max_split_size_mb:256" |
| 29 | + |
| 30 | + |
| 31 | +@pytest.mark.skipif(os.getenv("VLLM_USE_V1") == "0", |
| 32 | + reason="torchair graph is not supported on v0") |
| 33 | +def test_e2e_deepseekv3_with_torchair(monkeypatch: pytest.MonkeyPatch): |
| 34 | + with monkeypatch.context() as m: |
| 35 | + m.setenv("VLLM_USE_MODELSCOPE", "True") |
| 36 | + m.setenv("VLLM_WORKER_MULTIPROC_METHOD", "spawn") |
| 37 | + |
| 38 | + example_prompts = [ |
| 39 | + "Hello, my name is", |
| 40 | + "The president of the United States is", |
| 41 | + "The capital of France is", |
| 42 | + "The future of AI is", |
| 43 | + ] |
| 44 | + dtype = "half" |
| 45 | + max_tokens = 5 |
| 46 | + # torchair is only work without chunked-prefill now |
| 47 | + with VllmRunner( |
| 48 | + "vllm-ascend/DeepSeek-V3-Pruning", |
| 49 | + dtype=dtype, |
| 50 | + tensor_parallel_size=4, |
| 51 | + distributed_executor_backend="mp", |
| 52 | + additional_config={ |
| 53 | + "torchair_graph_config": { |
| 54 | + "enabled": True, |
| 55 | + }, |
| 56 | + "ascend_scheduler_config": { |
| 57 | + "enabled": True, |
| 58 | + }, |
| 59 | + "refresh": True, |
| 60 | + }, |
| 61 | + enforce_eager=False, |
| 62 | + ) as vllm_model: |
| 63 | + # use greedy sampler to make sure the generated results are fix |
| 64 | + vllm_output = vllm_model.generate_greedy(example_prompts, |
| 65 | + max_tokens) |
| 66 | + # NOTE: vllm-ascend/DeepSeek-V3-Pruning is a random weight of |
| 67 | + # DeepSeek-V3 with 2 hidden layers, thus the golden results seems |
| 68 | + # inaccurate. This will only change if accuracy improves with the |
| 69 | + # official weights of DeepSeek-V3. |
| 70 | + golden_results = [ |
| 71 | + 'Hello, my name is feasibility伸 spazio debtor添', |
| 72 | + 'The president of the United States is begg"""\n杭州风和 bestimm', |
| 73 | + 'The capital of France is frequentlyশามalinkAllowed', |
| 74 | + 'The future of AI is deleting俯احت怎么样了حراف', |
| 75 | + ] |
| 76 | + |
| 77 | + assert len(golden_results) == len(vllm_output) |
| 78 | + for i in range(len(vllm_output)): |
| 79 | + assert golden_results[i] == vllm_output[i][1] |
| 80 | + print(f"Generated text: {vllm_output[i][1]!r}") |
0 commit comments