huangning1995
ce11fd49f3
[Feature] Batch invariant torch.compile (#6107)
### What this PR does / why we need it?
Building upon https://github.com/vllm-project/vllm-ascend/pull/5517 to
enable batch-invariant in vllm-ascend, we observed that the performance
of BI in eager mode remains suboptimal.
This PR further integrates batch-invariant with torch.compile, which
improves inference performance by 350% when tested with Qwen3-0.6B.
### Does this PR introduce _any_ user-facing change?
Previously, enabling both aclgraph and Batch-Invariant would cause an
"ub overflow" error. This occurred because transposed input tensors
could produce incorrect stride() values.
To fix this, we now call .contiguous() on the input tensors before
passing them to Triton kernels. This ensures a contiguous memory layout
and prevents transposed tensors from causing incorrect stride
calculations.
### Test Plan
pytest -sv --durations=0
tests/e2e/singlecard/test_aclgraph_batch_invariant.py
### Test Result
```
============================================================================ slowest durations ============================================================================
87.37s call tests/e2e/singlecard/test_aclgraph_batch_invariant.py::test_v1_generation_is_deterministic_across_batch_sizes_with_needle
77.39s call tests/e2e/singlecard/test_aclgraph_batch_invariant.py::test_logprobs_bitwise_batch_invariance_bs1_vs_bsN
74.04s call tests/e2e/singlecard/test_aclgraph_batch_invariant.py::test_logprobs_without_batch_invariance_should_fail
73.59s call tests/e2e/singlecard/test_aclgraph_batch_invariant.py::test_simple_generation
(8 durations < 0.005s hidden. Use -vv to show these durations.)
================================================================ 4 passed, 3 warnings in 312.45s (0:05:12) ================================================================
```
### Performance
export VLLM_BATCH_INVARIANT=1
vllm serve /home/Qwen3-0.6B \
--served-model-name qwen \
--port 8000 \
--max-num-seqs 256 \
--tensor-parallel-size 1 \
--max-model-len 5500 \
--max-num-batched-tokens 5500 \
--reasoning-parser qwen3 \
--gpu-memory-utilization 0.9 \
--compilation_config '{"cudagraph_mode":"FULL_DECODE_ONLY",
"cudagraph_capture_sizes":[1,2,4,8,16,32]}' \
--additional-config
'{"ascend_scheduler_config":{"enabled":true},"enable_weight_nz_layout":true}'
vllm bench serve --served-model-name qwen --trust-remote-code --backend
vllm --model /home/Qwen3-0.6B/ --endpoint /v1/completions --dataset-name
random --random-input-len 512 --random-output-len 256 --num-prompts 800
--max-concurrency 8
torch.compile batch invariant performance:
```
============ Serving Benchmark Result ============
Successful requests: 800
Failed requests: 0
Maximum request concurrency: 8
Benchmark duration (s): 477.21
Total input tokens: 409600
Total generated tokens: 204800
Request throughput (req/s): 1.68
Output token throughput (tok/s): 429.16
Peak output token throughput (tok/s): 472.00
Peak concurrent requests: 16.00
Total token throughput (tok/s): 1287.48
---------------Time to First Token----------------
Mean TTFT (ms): 285.53
Median TTFT (ms): 312.70
P99 TTFT (ms): 324.22
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms): 17.59
Median TPOT (ms): 17.50
P99 TPOT (ms): 18.44
---------------Inter-token Latency----------------
Mean ITL (ms): 17.59
Median ITL (ms): 17.45
P99 ITL (ms): 18.76
==================================================
```
Eager
```
============ Serving Benchmark Result ============
Successful requests: 800
Failed requests: 0
Maximum request concurrency: 8
Benchmark duration (s): 1694.70
Total input tokens: 409600
Total generated tokens: 204800
Request throughput (req/s): 0.47
Output token throughput (tok/s): 120.85
Peak output token throughput (tok/s): 136.00
Peak concurrent requests: 16.00
Total token throughput (tok/s): 362.54
---------------Time to First Token----------------
Mean TTFT (ms): 164.29
Median TTFT (ms): 129.71
P99 TTFT (ms): 1961.66
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms): 65.81
Median TPOT (ms): 65.15
P99 TPOT (ms): 72.27
---------------Inter-token Latency----------------
Mean ITL (ms): 65.81
Median ITL (ms): 64.64
P99 ITL (ms): 75.72
==================================================
```
- vLLM version: v0.13.0
- vLLM main:
d68209402d
---------
Signed-off-by: huangning1995 <huangning12@huawei.com>
2026-01-26 09:15:06 +08:00
..
2026-01-24 20:16:44 +08:00
2026-01-14 09:18:05 +08:00
2026-01-15 23:22:43 +08:00
2026-01-26 09:00:51 +08:00
2025-06-16 18:32:28 +08:00
2026-01-26 09:00:51 +08:00
2026-01-26 09:15:06 +08:00
2025-12-30 08:32:14 +08:00
2025-12-23 12:47:35 +08:00
2026-01-26 09:03:33 +08:00
2026-01-07 09:11:26 +08:00
2025-12-26 14:17:50 +08:00
2025-12-26 14:17:50 +08:00
2025-12-27 10:21:20 +08:00
2025-12-26 14:17:50 +08:00
2026-01-09 15:57:43 +08:00
2026-01-26 09:00:51 +08:00
2026-01-11 11:38:45 +08:00
2025-12-24 10:41:32 +08:00
2025-09-02 09:02:22 +08:00
2026-01-23 21:09:54 +08:00
2026-01-26 09:00:51 +08:00
2025-12-26 14:17:50 +08:00
2025-12-26 14:17:50 +08:00
2026-01-21 09:26:03 +08:00
2026-01-07 20:58:15 +08:00