|
| 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/multicard/test_data_parallel.py`. |
| 21 | +""" |
| 22 | + |
| 23 | +import os |
| 24 | + |
| 25 | +import pytest |
| 26 | + |
| 27 | +from tests.conftest import VllmRunner |
| 28 | +from tests.model_utils import check_outputs_equal |
| 29 | + |
| 30 | +MODELS = ["Qwen/Qwen2.5-0.5B-Instruct"] |
| 31 | + |
| 32 | + |
| 33 | +@pytest.mark.skipif(os.getenv("VLLM_USE_V1") == "0", |
| 34 | + reason="Data parallel only support on v1") |
| 35 | +@pytest.mark.parametrize("model", MODELS) |
| 36 | +@pytest.mark.parametrize("max_tokens", [32]) |
| 37 | +def test_data_parallel_correctness( |
| 38 | + model: str, |
| 39 | + max_tokens: int, |
| 40 | +) -> None: |
| 41 | + example_prompts = [ |
| 42 | + "Hello, my name is", "The president of the United States is", |
| 43 | + "The capital of France is", "The future of AI is" |
| 44 | + ] |
| 45 | + |
| 46 | + with VllmRunner(model_name=model, |
| 47 | + max_model_len=1024, |
| 48 | + max_num_seqs=16, |
| 49 | + data_parallel_size=2, |
| 50 | + distributed_executor_backend="mp") as vllm_model: |
| 51 | + vllm_dp_outputs = vllm_model.generate_greedy(example_prompts, |
| 52 | + max_tokens) |
| 53 | + |
| 54 | + with VllmRunner( |
| 55 | + model_name=model, |
| 56 | + max_model_len=1024, |
| 57 | + max_num_seqs=16, |
| 58 | + ) as vllm_model: |
| 59 | + vllm_outputs = vllm_model.generate_greedy(example_prompts, max_tokens) |
| 60 | + |
| 61 | + check_outputs_equal( |
| 62 | + outputs_0_lst=vllm_outputs, |
| 63 | + outputs_1_lst=vllm_dp_outputs, |
| 64 | + name_0="vllm_outputs", |
| 65 | + name_1="vllm_dp_outputs", |
| 66 | + ) |
0 commit comments