Files
enginex-ascend-910-vllm/tests/e2e/pull_request/two_card/test_external_launcher.py
Sun Ruoxi 7f8a1b1f7a init v0.23.0
Signed-off-by: Sun Ruoxi <sunruoxi@4paradigm.com>
2026-08-27 15:11:51 +08:00

230 lines
6.1 KiB
Python

#
# Copyright (c) 2025 Huawei Technologies Co., Ltd. All Rights Reserved.
# Copyright 2023 The vLLM team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""
Compare the outputs of vLLM with and without aclgraph.
Run `pytest tests/e2e/pull_request/two_card/test_external_launcher.py`.
"""
import os
import subprocess
import sys
from pathlib import Path
from unittest.mock import patch
import huggingface_hub
import pytest
import torch_npu
from modelscope import snapshot_download # type: ignore
from tests.e2e.conftest import wait_until_npu_memory_free
MODELS = ["Qwen/Qwen3-0.6B"]
MOE_MODELS = ["Qwen/Qwen3-30B-A3B"]
DEVICE_NAME = torch_npu.npu.get_device_name(0)[:10]
REPO_ROOT = Path(__file__).resolve().parents[4]
EXTERNAL_LAUNCHER_SCRIPT = REPO_ROOT / "examples" / "offline_external_launcher.py"
EXTERNAL_LAUNCHER_TIMEOUT_S = 720
def _decode_output(output):
if output is None:
return ""
if isinstance(output, bytes):
return output.decode(errors="ignore")
return output
def _run_external_launcher(cmd, env):
env = env.copy()
env["PYTHONUNBUFFERED"] = "1"
print(f"Running subprocess: {' '.join(cmd)}")
try:
proc = subprocess.run(
cmd,
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
timeout=EXTERNAL_LAUNCHER_TIMEOUT_S,
)
except subprocess.TimeoutExpired as exc:
print(f"Subprocess timed out after {EXTERNAL_LAUNCHER_TIMEOUT_S} seconds.")
output = _decode_output(exc.output)
if output:
print(output)
else:
print("No subprocess output captured before timeout.")
raise
output = _decode_output(proc.stdout)
print(output)
return proc, output
@pytest.mark.parametrize("model", MODELS)
@patch.dict(os.environ, {"HCCL_BUFFSIZE": "500"})
def test_qwen3_external_launcher(model):
env = os.environ.copy()
# TODO: Change to 2 when ci machine has 4 cards
cmd = [
sys.executable,
str(EXTERNAL_LAUNCHER_SCRIPT),
"--model",
model,
"--tp-size",
"1",
"--node-size",
"1",
"--node-rank",
"0",
"--proc-per-node",
"2",
"--trust-remote-code",
]
proc, output = _run_external_launcher(cmd, env)
assert "TP RANKS: [0]" in output
assert "TP RANKS: [1]" in output
assert "Generated text:" in output
assert proc.returncode == 0
@pytest.mark.parametrize("model", MOE_MODELS)
@wait_until_npu_memory_free(target_free_percentage=0.7)
def test_qwen3_moe_external_launcher_ep_tp2(model):
env = os.environ.copy()
# TODO: Change to 2 when ci machine has 4 cards
cmd = [
sys.executable,
str(EXTERNAL_LAUNCHER_SCRIPT),
"--model",
model,
"--tp-size",
"2",
"--node-size",
"1",
"--node-rank",
"0",
"--proc-per-node",
"2",
"--trust-remote-code",
"--enable-expert-parallel",
]
proc, output = _run_external_launcher(cmd, env)
assert "TP RANKS: [0, 1]" in output
assert "Generated text:" in output
assert proc.returncode == 0
@patch.dict(os.environ, {"VLLM_ASCEND_ENABLE_NZ": "0"})
@wait_until_npu_memory_free(target_free_percentage=0.7)
def test_qwen3_external_launcher_with_sleepmode():
env = os.environ.copy()
# TODO: Change to 2 when ci machine has 4 cards
cmd = [
sys.executable,
str(EXTERNAL_LAUNCHER_SCRIPT),
"--model",
"Qwen/Qwen3-8B",
"--tp-size",
"1",
"--node-size",
"1",
"--node-rank",
"0",
"--proc-per-node",
"2",
"--trust-remote-code",
"--enable-sleep-mode",
"--temperature",
"0",
"--model-weight-gib",
"16",
]
proc, output = _run_external_launcher(cmd, env)
assert "Generated text:" in output
assert "Sleep and wake up successfully!!" in output
assert proc.returncode == 0
@patch.dict(os.environ, {"VLLM_ASCEND_ENABLE_NZ": "0"})
@wait_until_npu_memory_free(target_free_percentage=0.7)
def test_qwen3_external_launcher_with_sleepmode_level2():
env = os.environ.copy()
model_path = snapshot_download(
"Qwen/Qwen3-8B",
local_files_only=huggingface_hub.constants.HF_HUB_OFFLINE,
)
# TODO: Add moe model test
cmd = [
sys.executable,
str(EXTERNAL_LAUNCHER_SCRIPT),
"--model",
model_path,
"--tp-size",
"1",
"--node-size",
"1",
"--node-rank",
"0",
"--proc-per-node",
"2",
"--trust-remote-code",
"--enable-sleep-mode",
"--temperature",
"0",
"--model-weight-gib",
"16",
"--sleep-mode-level",
"2",
]
proc, output = _run_external_launcher(cmd, env)
assert "Generated text:" in output
assert "Sleep and wake up successfully!!" in output
assert proc.returncode == 0
@pytest.mark.skipif(
DEVICE_NAME != "Ascend910B",
reason="This test is only for Ascend910B devices.",
)
@pytest.mark.parametrize("model", MODELS)
@wait_until_npu_memory_free(target_free_percentage=0.7)
@patch.dict(os.environ, {"VLLM_ASCEND_ENABLE_MATMUL_ALLREDUCE": "1", "HCCL_BUFFSIZE": "500"})
def test_qwen3_external_launcher_with_matmul_allreduce(model):
env = os.environ.copy()
cmd = [
sys.executable,
str(EXTERNAL_LAUNCHER_SCRIPT),
"--model",
model,
"--trust-remote-code",
]
proc, output = _run_external_launcher(cmd, env)
assert "Generated text:" in output
assert proc.returncode == 0