[2026春季][T2-1-3] surprisely#498
Open
surprisely wants to merge 13 commits into
Open
Conversation
Expose auto, legacy, and fused policies. Auto selects fused only for non-quantized CUDA FP16/BF16 qwen3_moe workloads and preserves explicit legacy behavior elsewhere.
Propagate max_batch_size through the Python and C++ cache configuration so Paged CUDA Graph captures only scheduler-reachable batch shapes.
Keep exact graphs for batches 1 through 16 and coarse exact buckets above 16. Missing shapes retain the existing eager fallback and the configured maximum remains captured.
Use a 4096-token scheduler admission default only for high-concurrency Paged qwen3_moe serving. Explicit overrides, other models, and small capacities keep their prior behavior.
Project normal single-request prefill logits only at the sampled final position. sample_all_positions callers and decode retain complete logits semantics.
Shard the non-quantized Qwen3-MoE vocabulary projection across tensor-parallel ranks. Preserve complete-logit fallbacks for raw and non-greedy callers.
Skip recursive runtime-state reset only when the model is explicitly non-quantized. Quantized Marlin lock and workspace resets remain unchanged.
Derive the decode capture set from the current PagedKVCacheConfig on every compile so cache resets cannot retain stale batch limits or permanently discard larger buckets.
Exercise automatic backend gating, explicit compatibility overrides, quantization fallback, and the high-concurrency prefill budget boundaries.
There was a problem hiding this comment.
Pull request overview
This PR extends InfiniLM’s Qwen3-MoE serving stack with an auto|legacy|fused MoE backend policy, tighter paged CUDA Graph capture based on max_batch_size, and several Qwen3-MoE-specific performance/memory optimizations (prefill budgeting, last-token logits projection, vocab-parallel LM head/logits handling), alongside new tests, docs, and reproduction scripts.
Changes:
- Add MoE backend policy resolution (
auto|legacy|fused) and expose it via server CLI/API, with compatibility handling for the legacy boolean switch. - Propagate
max_batch_sizeinto paged KV/cache config and paged Graph compiler to limit captured shapes and reduce resident memory. - Optimize Qwen3-MoE inference paths (prefill admission defaulting, last-token logits, vocab-parallel logits for distributed greedy), plus add contest benchmark scripts and policy boundary tests.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/llm/test_moe_policy.py | Adds policy/budget boundary tests for moe_backend=auto and Qwen3-MoE prefill budgeting. |
| scripts/run_vllm_bench_serve_client.py | Adds a lightweight launcher for vLLM serving benchmark client with --extra-body support. |
| scripts/run_qwen3_moe_contest.sh | Adds a one-command entrypoint to run correctness + contest-style serving benchmarks. |
| README.md | Documents --moe-backend=auto|legacy|fused behavior for Qwen3-MoE. |
| python/infinilm/server/inference_server.py | Threads moe_backend into the server’s AsyncLLMEngine construction. |
| python/infinilm/llm/model_runner/model_runner.py | Passes max_batch_size into paged KV cache config creation. |
| python/infinilm/llm/llm.py | Implements _resolve_moe_backend, adds Qwen3-MoE prefill budget defaulting, and updates LLM/AsyncLLMEngine args. |
| python/infinilm/infer_engine.py | Adds allow_local_vocab_logits plumbing for distributed-greedy local logits consumption. |
| python/infinilm/cache/cache.py | Extends PagedKVCacheConfig Python wrapper to include max_batch_size. |
| python/infinilm/base_config.py | Adds --moe-backend CLI option and adjusts MoE-related argument wiring. |
| examples/test_infer.py | Updates example to use new MoE policy parameters (skip_legacy_moe=None, moe_backend). |
| csrc/pybind11/engine/engine.hpp | Exposes allow_local_vocab_logits to Python bindings. |
| csrc/pybind11/cache/cache.hpp | Extends PagedKVCacheConfig binding to include max_batch_size. |
| csrc/models/infinilm_model.hpp | Adds fields for last-token logits and vocab-parallel logits control; adds uses_vocab_parallel_logits(). |
| csrc/models/infinilm_model.cpp | Skips module-tree runtime reset for non-quantized Qwen3-MoE. |
| csrc/layers/causal_lm_templates/text_causal_lm.hpp | Implements last-token-only logits path and vocab-parallel LM head + allgather as needed. |
| csrc/engine/rank_worker.hpp | Adds allow_local_vocab_logits and greedy detection helper. |
| csrc/engine/rank_worker.cpp | Adds distributed greedy over sharded vocab logits; adjusts graph usage gating. |
| csrc/engine/infer_engine.cpp | Enforces CPU residency for input_offsets and computes last-token indices for packed prefill. |
| csrc/engine/compiler/static_batching_compiler.cpp | Marks compiled inputs as local-vocab-logits-capable and rejects incompatible requests. |
| csrc/engine/compiler/paged_compiler.cpp | Limits captured decode batch shapes by max_batch_size and sparsifies high-batch buckets. |
| csrc/cache/kv_cache.hpp | Adds max_batch_size to PagedKVCacheConfig API. |
| csrc/cache/kv_cache.cpp | Implements max_batch_size plumbing and preserves legacy 2-arg ctor default. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
191
to
199
| self.engine = AsyncLLMEngine( | ||
| model_path=self.model_path, | ||
| device=self.device, | ||
| dtype=self.dtype, | ||
| tensor_parallel_size=self.tensor_parallel_size, | ||
| moe_ep_backend=self.moe_ep_backend, | ||
| moe_ep_size=self.moe_ep_size, | ||
| moe_backend=self.moe_backend, | ||
| cache_type=self.cache_type, |
Comment on lines
+120
to
+127
| export INFINI_ROOT | ||
| export CUDA_VISIBLE_DEVICES | ||
| export LD_LIBRARY_PATH="$INFINI_ROOT/lib:${LD_LIBRARY_PATH:-}" | ||
| if [ -n "$INFINICORE_DIR" ]; then | ||
| export PYTHONPATH="$INFINICORE_DIR/python:$REPO_DIR/python:${PYTHONPATH:-}" | ||
| else | ||
| export PYTHONPATH="$REPO_DIR/python:${PYTHONPATH:-}" | ||
| fi |
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
摘要
auto|legacy|fusedMoE 后端策略;auto仅对受支持的 CUDA、FP16/BF16、非量化 Qwen3-MoE 选择 Fused MoE。max_batch_size贯通到 Paged CUDA Graph compiler,只捕获 scheduler 可达 batch,并稀疏化高 batch Graph;未捕获 shape 保留 eager fallback。scripts/run_qwen3_moe_contest.sh一键复现入口。动机
Qwen3-30B-A3B-Thinking-2507 在 4×RTX 4090D、BF16、TP=4 的多并发/长文本服务中,主要受 Graph capture 常驻显存、packed-prefill 激活峰值和重复/全位置词表投影限制。未修改上游在 c64 长点会出现大量 server timeout。
服务端均为 InfiniLM,客户端均为 vLLM 0.9.2
openai-chat,request-rate=inf。同点使用相同模型、TP、tokenizer、目标长度和 KV 容量;c64 短点使用 128 blocks,c64 长点使用 120 blocks 与 4096-token prefill budget。未修改上游使用在 4×24 GiB 上可运行的 Paged eager,优化侧使用 Fused MoE + Paged Attention + device CUDA Graph。以下是端到端可服务栈对比,不冒充任一新增补丁的独立收益。
优化值均来自最终 HEAD
4a44bd3、seed 714 的 vLLM 0.9.2openai-chat重跑;c64 长点为三次运行的中位数,三次 output throughput 为 592.49 / 586.13 / 576.82 tok/s。c64 长点上游与优化侧实际输入均为 16335 tokens;优化侧三次均为 64/64 达到至少 1000 输出 tokens,上游仅 20/64 达到该长度,其余 44 个因 server timeout 提前结束。因此长点不视为等输出 token 数的延迟对比。保留补丁的隔离结果:
max_batch_size裁剪 Graph:b1/in32/out256 稳态延迟降低 3.87%,初始化降低 38.35%,峰值显存减少 2276~2284 MiB/GPU。变更类型
feat— 新增功能/APIfix— cache 重配置后重建 Graph bucketperf— 性能优化refactor— 仅重构test— 新增测试docs— 更新文档build/cichore涉及模型在支持平台上的测试结果
auto -> fused、真模型 smoke性能影响与测试口径
Qwen3-30B-A3B-Thinking-2507,BF16,128 experts,top-8。request-rate=inf,num-prompts=max-concurrency,seed 714;c1/c64 短点为最终 HEAD 单次值,c64 长点为最终 HEAD 三次中位数。评审说明
moe_backend=auto保留显式 Legacy override,仅对 CUDA FP16/BF16、非量化qwen3_moe选择 fused。input_offsets前检查 CPU residency,避免解引用 device 地址。REFERENCE.md。CI / ChatOps
创建 PR 后手动触发 Actions CI,或请维护者使用
/retest。提交前检查
标题、分支与提交
[2026春季][T2-1-3] surprisely。2026-spring-surprisely-T2-1-3。upstream/main,无 merge commit、fixup!、squash!或wip。<type>/...分支规则。范围与代码质量
git diff --check通过。C++ / Python
python scripts/format.py --ref upstream/main --check和 Ruff 检查通过。csrc/models/llama_legacy/或python/infinilm/auto_config.py。测试、构建与文档
examples/test_infer.py等价单请求真模型 smoke 通过。test/llm/test_moe_policy.py:7/7 通过。examples/bench.py和test/bench/test_benchmark.py;本 PR 的性能口径为赛题参考的 vLLM HTTP 服务 benchmark。scripts/test_perf.py;使用赛题参考的 vLLM 0.9.2 客户端。--moe-backend=auto|legacy|fused,无 breaking change。/retest。安全与合规
REFERENCE.md披露。