|
| 1 | +import os |
| 2 | + |
| 3 | +import pytest |
| 4 | +from vllm import SamplingParams |
| 5 | + |
| 6 | +from tests.e2e.conftest import VllmRunner |
| 7 | +from tests.e2e.model_utils import check_outputs_equal |
| 8 | + |
| 9 | +MODELS = [ |
| 10 | + "vllm-ascend/DeepSeek-V2-Lite", |
| 11 | +] |
| 12 | +os.environ["VLLM_WORKER_MULTIPROC_METHOD"] = "spawn" |
| 13 | + |
| 14 | + |
| 15 | +@pytest.mark.parametrize("model", MODELS) |
| 16 | +def test_models_with_enable_shared_expert_dp(model: str) -> None: |
| 17 | + |
| 18 | + if 'HCCL_OP_EXPANSION_MODE' in os.environ: |
| 19 | + del os.environ['HCCL_OP_EXPANSION_MODE'] |
| 20 | + |
| 21 | + prompts = [ |
| 22 | + "Hello, my name is", "The capital of the United States is", |
| 23 | + "The capital of France is", "The future of AI is" |
| 24 | + ] |
| 25 | + sampling_params = SamplingParams(max_tokens=32, temperature=0.0) |
| 26 | + |
| 27 | + with VllmRunner( |
| 28 | + model, |
| 29 | + max_model_len=1024, |
| 30 | + enforce_eager=True, |
| 31 | + tensor_parallel_size=2, |
| 32 | + enable_expert_parallel=True, |
| 33 | + ) as runner: |
| 34 | + vllm_eager_outputs = runner.model.generate(prompts, sampling_params) |
| 35 | + |
| 36 | + os.environ["VLLM_ASCEND_ENABLE_FLASHCOMM1"] = "1" |
| 37 | + with VllmRunner( |
| 38 | + model, |
| 39 | + max_model_len=1024, |
| 40 | + enforce_eager=True, |
| 41 | + tensor_parallel_size=2, |
| 42 | + enable_expert_parallel=True, |
| 43 | + additional_config={ |
| 44 | + "enable_shared_expert_dp": True, |
| 45 | + }, |
| 46 | + ) as runner: |
| 47 | + shared_expert_dp_eager_outputs = runner.model.generate( |
| 48 | + prompts, sampling_params) |
| 49 | + |
| 50 | + with VllmRunner( |
| 51 | + model, |
| 52 | + max_model_len=1024, |
| 53 | + tensor_parallel_size=2, |
| 54 | + enforce_eager=False, |
| 55 | + compilation_config={ |
| 56 | + "cudagraph_capture_sizes": [1, 4, 8, 16], |
| 57 | + "cudagraph_mode": "FULL_DECODE_ONLY", |
| 58 | + }, |
| 59 | + additional_config={ |
| 60 | + "enable_shared_expert_dp": True, |
| 61 | + }, |
| 62 | + ) as runner: |
| 63 | + shared_expert_dp_aclgraph_outputs = runner.model.generate( |
| 64 | + prompts, sampling_params) |
| 65 | + |
| 66 | + vllm_eager_outputs_list = [] |
| 67 | + for output in vllm_eager_outputs: |
| 68 | + vllm_eager_outputs_list.append( |
| 69 | + (output.outputs[0].index, output.outputs[0].text)) |
| 70 | + |
| 71 | + shared_expert_dp_eager_outputs_list = [] |
| 72 | + for output in shared_expert_dp_eager_outputs: |
| 73 | + shared_expert_dp_eager_outputs_list.append( |
| 74 | + (output.outputs[0].index, output.outputs[0].text)) |
| 75 | + |
| 76 | + shared_expert_dp_aclgraph_outputs_list = [] |
| 77 | + for output in shared_expert_dp_aclgraph_outputs: |
| 78 | + shared_expert_dp_aclgraph_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=shared_expert_dp_eager_outputs_list, |
| 84 | + name_0="vllm_eager_outputs", |
| 85 | + name_1="shared_expert_dp_eager_outputs", |
| 86 | + ) |
| 87 | + |
| 88 | + check_outputs_equal( |
| 89 | + outputs_0_lst=vllm_eager_outputs_list, |
| 90 | + outputs_1_lst=shared_expert_dp_aclgraph_outputs_list, |
| 91 | + name_0="vllm_eager_outputs", |
| 92 | + name_1="shared_expert_dp_aclgraph_outputs", |
| 93 | + ) |
0 commit comments