Read code changes as Git diffs. Identifying strings are masked; binary files are listed by their full relative names.
vllm_ascend · 4 changed files
Base commit: 7c254c14e2f2db1185d739075ee3cdc1da3cfde2
diff --git a/vllm_ascend/deployment/README.md b/vllm_ascend/deployment/README.mdnew file mode 100644index 0000000000000000000000000000000000000000..55058ef8c4e59fbd73a3ee6a118355cbcfe75bdf--- /dev/null+++ b/vllm_ascend/deployment/README.md@@ -0,0 +1,114 @@+# Qwen3-30B-A3B on two Ascend 910B devices++`qwen3_30b_a3b.py` implements the framework deployment entrypoint for the+two-device BF16 serving workload. It accepts the host's model, tokenizer,+model name, endpoint, device allocation, and runtime directory arguments.+The host supplies the visible-device environment and runtime working directory.+The entrypoint replaces itself with the standard vLLM server using `os.execv`,+so the normal API server, scheduler, workers, and signal handling own the service.++The deployment uses tensor parallelism of two with expert parallelism, BF16+weights and KV cache, a 4,096-token context limit, and at most 64 active requests.+Prefix caching stays disabled and generation uses vLLM's request defaults.++## Execution choices++- Pack BF16 matrices into Ascend's NZ layout once during model loading using+ the existing `weight_nz_mode=2` option.+- Use full graphs for decode and piecewise graphs for mixed prefill/decode.+ Attention and KV updates retain the backend's dynamic metadata handling.+- Capture prefill shapes every 256 tokens through 8,192 tokens, then every+ 1,024 tokens through the batch token limit. For batches of at least 2,048+ tokens, padding adds at most 12.5% to the token count. This avoids doubling+ matrix work when a long prompt is combined with a few decode tokens.+- Allow 32,768 tokens per scheduling step and use a memory utilization target+ of 0.75 to accommodate larger prefill batches and graph storage.+- Keep matmul/all-reduce/RMS fusion disabled to retain the reference's fusion+ configuration when selecting the piecewise compiler.++All routing, expert evaluation, sampling, response construction, and cleanup+remain in the supplied vLLM and vLLM-Ascend implementations. The entrypoint+does not inspect requests or maintain request-dependent state.++## Validation++Use the task-owned formal input bundle and a fresh `TASK_HOME` and+`TASK_OUTPUT_DIR` for each service run. The input directory must contain the+supplied `manifest.json` and `formal-inputs.json`.++```bash+TASK_MODE=describe bash "$TASK_DIR/run/describe.sh"+TASK_MODE=dry_run bash "$TASK_DIR/run/smoke.sh"+bash "$TASK_DIR/run/correctness.sh"+bash "$TASK_DIR/run/benchmark_once.sh"+bash "$TASK_DIR/run/cleanup.sh"+```++Set `TASK_EXTERNAL_INPUT_ROOT` to that formal input directory and put the+vLLM `.venv/bin` directory first on `PATH` when invoking these scripts.+Compare each correctness group's `computed_output_digest` exactly with the+unmodified reference, following `workloads/formal/check_policy.json`.++The selected deployment passed the task's description, formal correctness,+full measurement, and smoke commands. A final explicit cleanup command also+confirmed that the service stopped and its port was released.++The deployment tests cover argument handling, the foreground process handoff,+model and endpoint forwarding, the device ceiling, and prefill padding bounds.+They are colocated here to stay within the task's editable source scope.++```bash+/vllm-workspace/vllm/.venv/bin/python -B -m pytest \+ vllm_ascend/deployment/tests/test_qwen3_30b_a3b.py \+ tests/ut/compilation/a2/test_acl_graph.py \+ -k 'deployment or test_call_with_none_runtime_mode or test_call_capture_graph_first_time or test_call_replay_graph' -q++/vllm-workspace/vllm/.venv/bin/python -B -m pytest \+ tests/ut/ops/test_linear.py \+ -k process_weights_after_loading_with_nz -q+```++No native sources or build inputs are changed. The task's candidate build+command reports a successful skipped build for these Python changes.++The launcher tests and three targeted upstream tests for graph capture,+replay, and eager execution passed together (15 tests). Three upstream+`process_weights_after_loading_with_nz` tests also passed. Python parsing,+the 88-character Python line limit, and whitespace checks passed. Pre-commit+was unavailable; no Python packages were installed under the fixed runtime+contract.++## Measurement evidence++These measurements use the supplied formal workload on two Ascend 910B1+devices with the fixed vLLM 0.23.0 runtime. Throughput is in output tokens per+second. The aggregate is the square root of steady decode throughput times+the geometric mean of the four shifted-prefill phase throughputs.++| Configuration | Steady decode | Shifted prefill | Aggregate |+| --- | ---: | ---: | ---: |+| Unmodified reference | 1,642.69 | 425.76 | 836.30 |+| Unmodified reference, repeated | 1,606.63 | 426.92 | 828.19 |+| NZ packing, reference compiler | 1,732.31 | 437.93 | 870.99 |+| NZ packing, coarse piecewise graphs | 1,808.88 | 407.44 | 858.49 |+| **Selected: NZ, fine piecewise graphs, 32,768-token budget** | **1,784.64** | **433.88** | **879.95** |+| **Selected configuration, repeated** | **1,803.11** | **435.11** | **885.75** |+| NZ packing, decode-only fusion compiler | 1,669.63 | 430.95 | 848.25 |++The layout experiment improved both throughput components. Piecewise graphs+improved decode, but coarse prefill graph shapes reduced prefill throughput.+Finer shapes and a larger batch budget recovered that loss. The selected+configuration improved aggregate throughput by 5.22% and 5.91% in two full runs+against the first reference. It used 4.37 GiB of graph memory, took 65-66 seconds+to capture graphs, and peaked at 52,245 MiB HBM per device. Restricting the fusion+compiler to decode graphs reduced memory use but produced a lower aggregate.++Every measured run above completed all 1,152 measured requests and 96 warmup+requests, reported NPU activity without telemetry errors, and passed cleanup.+The NZ, piecewise, and decode-only fusion candidates matched all four required+correctness group digests and all 21 per-request digests against the reference.++The longer performance generations are sensitive to runtime batching: even+the unchanged reference repeat differed on 299 of 384 long-generation digests+and seven of 768 prefill-generation digests. The exact correctness checks+follow the task's declared comparison policy.diff --git a/vllm_ascend/deployment/__init__.py b/vllm_ascend/deployment/__init__.pynew file mode 100644index 0000000000000000000000000000000000000000..052c32ba57080df0946d5db85bfd7c78f32d19fa--- /dev/null+++ b/vllm_ascend/deployment/__init__.py@@ -0,0 +1,2 @@+# SPDX-License-Identifier: Apache-2.0+"""Framework-owned serving configurations."""diff --git a/vllm_ascend/deployment/qwen3_30b_a3b.py b/vllm_ascend/deployment/qwen3_30b_a3b.pynew file mode 100644index 0000000000000000000000000000000000000000..41e201ed9c6a78702f3a75647ad77f3e83f8afbd--- /dev/null+++ b/vllm_ascend/deployment/qwen3_30b_a3b.py@@ -0,0 +1,124 @@+# SPDX-License-Identifier: Apache-2.0+"""Serve BF16 Qwen3-30B-A3B on a pair of Ascend 910B devices.++The launcher supplies the visible devices and runtime directories. Replace+this process with the standard vLLM server so its signal handling, worker+lifecycle, and OpenAI API remain responsible for the entire service.+"""++import argparse+import json+import os+import sys+from collections.abc import Sequence++DEVICE_COUNT = 2+MAX_MODEL_LEN = 4096+MAX_NUM_SEQS = 64+MAX_BATCHED_TOKENS = 32768+GPU_MEMORY_UTILIZATION = 0.75+PREFILL_GRAPH_STEP = 256+LARGE_PREFILL_GRAPH_STEP = 1024+DENSE_CAPTURE_LIMIT = 8192+# Mixed batches can contain a long prompt plus a few decode tokens. Closely+# spaced prefill graphs bound padding work while retaining full decode graphs.+GRAPH_CAPTURE_SIZES = (+ (8, 16, 32, 64, 128)+ + tuple(range(PREFILL_GRAPH_STEP, DENSE_CAPTURE_LIMIT + 1, PREFILL_GRAPH_STEP))+ + tuple(+ range(+ DENSE_CAPTURE_LIMIT + LARGE_PREFILL_GRAPH_STEP,+ MAX_BATCHED_TOKENS + 1,+ LARGE_PREFILL_GRAPH_STEP,+ )+ )+)+++def device_ids(value: str) -> tuple[int, ...]:+ """Validate the device allocation for this two-device deployment."""+ try:+ devices = tuple(int(item) for item in value.split(","))+ except ValueError as exc:+ raise argparse.ArgumentTypeError("device IDs must be integers") from exc+ if len(devices) != DEVICE_COUNT or len(set(devices)) != DEVICE_COUNT:+ raise argparse.ArgumentTypeError("exactly two distinct devices are required")+ if any(device < 0 for device in devices):+ raise argparse.ArgumentTypeError("device IDs must be nonnegative")+ return devices+++def parse_args(argv: Sequence[str] | None = None) -> argparse.Namespace:+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--model-path", required=True)+ parser.add_argument("--tokenizer-path", required=True)+ parser.add_argument("--served-model-name", required=True)+ parser.add_argument("--host", required=True)+ parser.add_argument("--port", required=True, type=int)+ parser.add_argument("--device-ids", required=True, type=device_ids)+ parser.add_argument("--runtime-dir", required=True)+ args = parser.parse_args(argv)+ if not 0 < args.port < 65536:+ parser.error("port must be between 1 and 65535")+ return args+++def server_argv(args: argparse.Namespace) -> list[str]:+ """Build the vLLM command with BF16 weights and prefill graph coverage."""+ compilation = {+ "cudagraph_mode": "FULL_AND_PIECEWISE",+ "cudagraph_capture_sizes": GRAPH_CAPTURE_SIZES,+ }+ # NZ packs BF16 matrices once when loading the model. Weight and KV cache+ # dtypes, accumulator precision, and expert placement are unchanged.+ additional = {+ "weight_nz_mode": 2,+ "ascend_compilation_config": {"fuse_allreduce_rms": False},+ }+ return [+ sys.executable,+ "-B",+ "-m",+ "vllm.entrypoints.cli.main",+ "serve",+ args.model_path,+ "--tokenizer",+ args.tokenizer_path,+ "--served-model-name",+ args.served_model_name,+ "--host",+ args.host,+ "--port",+ str(args.port),+ "--dtype",+ "bfloat16",+ "--max-model-len",+ str(MAX_MODEL_LEN),+ "--tensor-parallel-size",+ str(len(args.device_ids)),+ "--enable-expert-parallel",+ "--gpu-memory-utilization",+ str(GPU_MEMORY_UTILIZATION),+ "--max-num-seqs",+ str(MAX_NUM_SEQS),+ "--max-num-batched-tokens",+ str(MAX_BATCHED_TOKENS),+ "--enable-chunked-prefill",+ "--no-enable-prefix-caching",+ "--generation-config",+ "vllm",+ "--compilation-config",+ json.dumps(compilation),+ "--additional-config",+ json.dumps(additional),+ ]+++def main(argv: Sequence[str] | None = None) -> None:+ args = parse_args(argv)+ command = server_argv(args)+ os.execv(command[0], command)+++if __name__ == "__main__":+ main()diff --git a/vllm_ascend/deployment/tests/test_qwen3_30b_a3b.py b/vllm_ascend/deployment/tests/test_qwen3_30b_a3b.pynew file mode 100644index 0000000000000000000000000000000000000000..37a015cb56d1e5fb1067a725a5f911e27125d8e1--- /dev/null+++ b/vllm_ascend/deployment/tests/test_qwen3_30b_a3b.py@@ -0,0 +1,94 @@+# SPDX-License-Identifier: Apache-2.0+"""Tests for the deployment ABI, independent of model weights and hardware."""++import json+import sys+from bisect import bisect_left+from unittest.mock import patch++import pytest++from vllm_ascend.deployment import qwen3_30b_a3b as deployment+++@pytest.fixture+def launch_args():+ return [+ "--model-path",+ "/models/qwen weights",+ "--tokenizer-path",+ "/models/tokenizer",+ "--served-model-name",+ "Qwen/Qwen3-30B-A3B",+ "--host",+ "127.0.0.1",+ "--port",+ "28161",+ "--device-ids",+ "0,1",+ "--runtime-dir",+ "/runtime/service",+ ]+++def test_server_preserves_model_and_public_endpoint(launch_args):+ command = deployment.server_argv(deployment.parse_args(launch_args))+ assert command[:6] == [+ sys.executable,+ "-B",+ "-m",+ "vllm.entrypoints.cli.main",+ "serve",+ "/models/qwen weights",+ ]+ for option, value in (+ ("--tokenizer", "/models/tokenizer"),+ ("--served-model-name", "Qwen/Qwen3-30B-A3B"),+ ("--host", "127.0.0.1"),+ ("--port", "28161"),+ ("--dtype", "bfloat16"),+ ("--tensor-parallel-size", "2"),+ ("--generation-config", "vllm"),+ ):+ assert command[command.index(option) + 1] == value+ assert "--enable-expert-parallel" in command+ assert "--no-enable-prefix-caching" in command+ config = json.loads(command[command.index("--additional-config") + 1])+ assert config["weight_nz_mode"] == 2+++def test_prefill_graph_padding_is_bounded(launch_args):+ command = deployment.server_argv(deployment.parse_args(launch_args))+ compilation = json.loads(command[command.index("--compilation-config") + 1])+ sizes = compilation["cudagraph_capture_sizes"]+ budget = int(command[command.index("--max-num-batched-tokens") + 1])+ assert sizes == sorted(set(sizes))+ assert sizes[-1] == budget+ # A long prompt mixed with decode tokens must not double its matrix work+ # merely because the batch crosses a power-of-two boundary.+ for tokens in range(2048, budget + 1):+ padded = sizes[bisect_left(sizes, tokens)]+ assert tokens <= padded <= tokens * 1.125+++@pytest.mark.parametrize("devices", ["", "0", "0,0", "0,1,2", "-1,0", "0,x"])+def test_invalid_device_allocation_is_rejected(launch_args, devices):+ launch_args[launch_args.index("--device-ids") + 1] = devices+ with pytest.raises(SystemExit):+ deployment.parse_args(launch_args)+++@pytest.mark.parametrize("port", ["0", "-1", "65536"])+def test_invalid_port_is_rejected(launch_args, port):+ launch_args[launch_args.index("--port") + 1] = port+ with pytest.raises(SystemExit):+ deployment.parse_args(launch_args)+++def test_server_replaces_foreground_process(launch_args):+ with patch.object(deployment.os, "execv") as execute:+ deployment.main(launch_args)+ execute.assert_called_once()+ executable, command = execute.call_args.args+ assert executable == sys.executable == command[0]+ assert command[2:5] == ["-m", "vllm.entrypoints.cli.main", "serve"]