|
| 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 multistream_overlap_shared_expert |
| 19 | +enabled and disabled. |
| 20 | +
|
| 21 | +Run `pytest tests/e2e/singlecard/test_multistream_overlap_shared_expert.py`. |
| 22 | +""" |
| 23 | + |
| 24 | +import pytest |
| 25 | +from vllm import SamplingParams |
| 26 | + |
| 27 | +from tests.e2e.conftest import VllmRunner |
| 28 | +from tests.e2e.model_utils import check_outputs_equal |
| 29 | + |
| 30 | +MODELS = [ |
| 31 | + "Qwen/Qwen3-0.6B", |
| 32 | +] |
| 33 | + |
| 34 | + |
| 35 | +@pytest.mark.parametrize("model", MODELS) |
| 36 | +@pytest.mark.parametrize("max_tokens", [32]) |
| 37 | +def test_models_with_multistream_overlap_shared_expert( |
| 38 | + model: str, |
| 39 | + max_tokens: int, |
| 40 | +) -> None: |
| 41 | + 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 | + sampling_params = SamplingParams(max_tokens=max_tokens, temperature=0.0) |
| 47 | + with VllmRunner( |
| 48 | + model, |
| 49 | + max_model_len=1024, |
| 50 | + enforce_eager=True, |
| 51 | + additional_config={ |
| 52 | + "multistream_overlap_shared_expert": True, |
| 53 | + }, |
| 54 | + ) as runner: |
| 55 | + vllm_moe_ms_eager_outputs = runner.model.generate( |
| 56 | + prompts, sampling_params) |
| 57 | + |
| 58 | + with VllmRunner( |
| 59 | + model, |
| 60 | + max_model_len=1024, |
| 61 | + enforce_eager=False, |
| 62 | + additional_config={ |
| 63 | + "multistream_overlap_shared_expert": True, |
| 64 | + }, |
| 65 | + ) as runner: |
| 66 | + vllm_moe_ms_aclgraph_outputs = runner.model.generate( |
| 67 | + prompts, sampling_params) |
| 68 | + |
| 69 | + with VllmRunner( |
| 70 | + model, |
| 71 | + max_model_len=1024, |
| 72 | + enforce_eager=True, |
| 73 | + ) as runner: |
| 74 | + vllm_eager_outputs = runner.model.generate(prompts, sampling_params) |
| 75 | + |
| 76 | + vllm_moe_ms_eager_outputs_list = [] |
| 77 | + for output in vllm_moe_ms_eager_outputs: |
| 78 | + vllm_moe_ms_eager_outputs_list.append( |
| 79 | + (output.outputs[0].index, output.outputs[0].text)) |
| 80 | + |
| 81 | + vllm_moe_ms_aclgraph_outputs_list = [] |
| 82 | + for output in vllm_moe_ms_aclgraph_outputs: |
| 83 | + vllm_moe_ms_aclgraph_outputs_list.append( |
| 84 | + (output.outputs[0].index, output.outputs[0].text)) |
| 85 | + |
| 86 | + vllm_eager_outputs_list = [] |
| 87 | + for output in vllm_eager_outputs: |
| 88 | + vllm_eager_outputs_list.append( |
| 89 | + (output.outputs[0].index, output.outputs[0].text)) |
| 90 | + |
| 91 | + check_outputs_equal( |
| 92 | + outputs_0_lst=vllm_eager_outputs_list, |
| 93 | + outputs_1_lst=vllm_moe_ms_eager_outputs_list, |
| 94 | + name_0="vllm_eager_outputs", |
| 95 | + name_1="vllm_moe_ms_eager_outputs", |
| 96 | + ) |
| 97 | + |
| 98 | + check_outputs_equal( |
| 99 | + outputs_0_lst=vllm_eager_outputs_list, |
| 100 | + outputs_1_lst=vllm_moe_ms_aclgraph_outputs_list, |
| 101 | + name_0="vllm_eager_outputs", |
| 102 | + name_1="vllm_moe_ms_aclgraph_outputs", |
| 103 | + ) |
0 commit comments