Skip to content

[2026春季][T2-1-2] CearX#502

Open
CearX wants to merge 1 commit into
InfiniTensor:mainfrom
CearX:2026-spring-CearX-T2-1-2
Open

[2026春季][T2-1-2] CearX#502
CearX wants to merge 1 commit into
InfiniTensor:mainfrom
CearX:2026-spring-CearX-T2-1-2

Conversation

@CearX

@CearX CearX commented Jul 12, 2026

Copy link
Copy Markdown

Summary

通过 Chunked Prefill、KV Cache 准入水位与请求/SSE 热路径优化,显著提升了单卡 8B 在高并发、长输出场景下的服务吞吐,同时保持小规模性能基本不变。

Motivation

T2-1-2 赛题需求多并发、长文本服务场景下的输出吞吐和总 token 吞吐,同时要求小规模性能无明显下降。

在单张 NVIDIA GeForce RTX 5090 32 GiB、Qwen3-8B BF16、TP=1 环境中,最终实现完成官方 8B 的 30 个测试点,所有请求均成功,输出长度严格命中,errors=0。在基线与最终实现共同有效的 27 个测试点上:

  • output throughput 几何平均提升 13.56%
  • total-token throughput 几何平均提升 13.56%
  • 按并发数分组:C1 -0.09%、C4 +5.44%、C16 +19.81%、C64 +87.14%
  • 按输出长度分组:o256 +7.50%、o1024 +5.20%、o4096 +29.50%
  • c64/i32/o4096:361.93 -> 661.13 output tok/s,提升 82.67%
  • c16/i256/o4096:293.68 -> 515.95 output tok/s,提升 75.69%
  • c1/i32/o256:92.34 -> 91.77 output tok/s,变化 -0.62%,无明显小规模回退。

附件赛题报告包含完整 30 点最终矩阵与 27 点基线对比,包括所有负收益点。

Type of Change

  • feat — new configurable service and benchmark entry points
  • fix — exact LENGTH termination and OpenAI-compatible field handling
  • perf — performance improvement
  • refactor — code restructuring without behavior change
  • test — reproducible official-style benchmark client
  • docs — documentation only
  • build / ci — build system or CI configuration
  • chore — tooling, formatting, or other non-code changes
  • Breaking change

Test Results of Involved Models on Supported Platforms (Please attach screenshots)

平台 模型 测试 结果
NVIDIA GeForce RTX 5090 32 GiB Qwen3-8B BF16,TP=1 官方服务矩阵 30/30 点完成;输出长度精确;errors=0
NVIDIA GeForce RTX 5090 32 GiB Qwen3-8B BF16,TP=1 基线对比 27 个共同点几何平均 +13.56%
image

Benchmark / Performance Impact

  • 硬件:NVIDIA GeForce RTX 5090 32 GiB。
  • 模型与数据类型:Qwen3-8B,BF16。
  • 并行配置:TP=1,单卡。
  • 服务接口:OpenAI /v1/chat/completions,streaming SSE。
  • 负载:burst,request_rate=infnum_prompts=max_concurrency
  • 生成配置:ignore_eos=true,客户端校验输出长度精确命中。
  • 复现 seed:0
  • 矩阵:官方单卡 8B 共 30 个组合。
  • 对比方法:只在基线与最终实现均有效的 27 个点上计算几何平均。
场景 基线 output tok/s 最终 output tok/s 变化
c64/i32/o256 1443.47 3092.98 +114.27%
c64/i32/o1024 1005.39 1683.44 +67.44%
c64/i32/o4096 361.93 661.13 +82.67%
c16/i256/o4096 293.68 515.95 +75.69%
c1/i32/o256 92.34 91.77 -0.62%

Notes for Reviewers

  • chunked prefill 的中间 prompt chunk 只更新 KV 状态,不向客户端发送采样 token。
  • KV 安全水位只延后新请求入场,不降低配置的最大 batch size。
  • stream_interval 保证首 token 立即发送,之后只合并 SSE 事件,不丢失模型 token。
  • 非流式请求使用 completion event 等待完成,最终文本只 decode 一次。
  • LENGTH 终止路径保留最后一个采样 token。

PR 附件:

赛题报告.pdf
HONOR_CODE.md
REFERENCE.md

CI / ChatOps


Checklist

Every contributor must verify every item below before requesting
review. Tick each box only after the check has actually been performed.

Title, Branch, and Commits

  • PR title follows Conventional Commits (e.g. feat(nvidia): …, fix(cuda/gemm): …).
  • Branch name follows <type>/xxx-yyyy-zzzz where <type> matches the PR title's Conventional Commits type and words are joined with hyphens (see CONTRIBUTING.md §Branches).
  • Each commit message follows Conventional Commits.
  • Small PR is a single squashable commit; or, for a large PR, every commit is meaningful, well-formed, and independently reviewable (see CONTRIBUTING.md §Pull Requests).
  • No stray merge commits from main — the branch is rebased cleanly on top of the audited main.
  • No fixup! / squash! / wip commits remain.
  • Existing PR/branch/commit that followed the legacy issue format.

Scope and Design

  • Changes are minimal — nothing unrelated to the stated motivation was added (CONTRIBUTING.md §Code/General).
  • No dead code, commented-out blocks, debug prints, printf/std::cout/print(...) left behind, or TODO without an owner and issue link.
  • No unrelated formatting churn that would obscure the diff.
  • Public API changes (if any) are intentional, documented, and reflected in affected callers/tests.

General Code Hygiene (applies to all languages)

  • The code is self-explanatory; comments were added only where the why is non-obvious (CONTRIBUTING.md §Code/General).
  • Every modified or added file ends with a single trailing newline (CONTRIBUTING.md §Code/General).
  • No trailing whitespace, tab/space mixing, or stray BOMs.
  • Identifiers in comments and error messages are wrapped in backticks (e.g. the `seqlens_k` tensor) (CONTRIBUTING.md §Code/General).
  • All comments and error messages are in English (CONTRIBUTING.md §Code/General).
  • Comments and error messages are complete sentences — capitalized first letter, terminal punctuation — unless the language/framework convention says otherwise (CONTRIBUTING.md §Code/General; §Python).

C++ Specific (if C++ files changed)

  • Code follows the Google C++ Style Guide strictly.
  • Error and warning message wording follows the LLVM Coding Standards (CONTRIBUTING.md §C++).
  • Constructor initializer list order matches member declaration order (CONTRIBUTING.md §C++).
  • No raw new/delete; RAII / smart pointers / existing allocators are used.
  • Changed files are formatted by scripts/format.py.
  • No changes/reference to csrc/models/llama_legacy/.

Python Specific (if Python files changed)

  • Code is PEP 8 compliant.
  • Comments are complete English sentences, starting with a capital letter and ending with punctuation; Markdown backticks are used for code references (CONTRIBUTING.md §Python).
  • Docstrings (if any) follow PEP 257 (CONTRIBUTING.md §Python).
  • Changed files are formatted by scripts/format.py.
  • No changes/reference to python/infinilm/auto_config.py.

Testing

  • For any platform that could not be tested, an explicit reason is given in the table and a reviewer with access has been tagged.
  • Passed single request test (examples/test_infer.py), or specify the reason for skipping.
  • Passed offline performance test (examples/bench.py), or specify the reason for skipping.
  • Passed sanity test (test/bench/test_benchmark.py), or specify the reason for skipping.
  • Passed service test (python/infinilm/server/inference_server.py + scripts/test_perf.py), or specify the reason for using scripts/competition/official_client_bench.py: the competition requires the official burst service matrix and exact output-length validation.

Build, CI, and Tooling

  • The project builds cleanly from a fresh directory on at least one affected platform.
  • CI has been triggered manually (Actions -> CI on this branch), or /retest was requested.

Documentation

  • README.md, CONTRIBUTING.md, or inline docs updated when behavior, build flags, or developer workflow changed.
  • Any user-visible breaking change is called out explicitly under "Motivation" and in the commit/PR title with a ! or BREAKING CHANGE: footer.

Security and Safety

  • No secrets, access tokens, internal URLs, customer data, or personal hardware identifiers have been committed.
  • Third-party code is license-compatible and attributed.
  • No unsafe pointer arithmetic, uninitialized reads, or missing bounds checks were introduced.

@CearX
CearX requested a review from a team July 12, 2026 21:13
@CearX

CearX commented Jul 26, 2026

Copy link
Copy Markdown
Author

复测实验矩阵与结论

一句话结论

单卡 RTX 5090 的复测表明,优化收益具有明显的负载选择性:SSE 合并发送在 13 个直接 A/B 点中 12 胜 1 负(总体 +3.36%、C64 +6.36%、代表点最高 +9.37%),而 chunked prefill 与 KV safety 将完整矩阵成功率从 27/30 提升到 30/30,但当前静态及隐式 KV admission headroom 会牺牲部分高并发吞吐。

GPU 与 CUDA

  • GPU:NVIDIA GeForce RTX 5090 32 GiB
  • CUDA:12.8
  • Python:3.12.3
  • PyTorch:2.8.0+cu128
  • vLLM:0.11.2
  • 测试参数:seed=0request-rate=infnum-prompts=max-concurrency

官方测试矩阵

并发数 输入长度(tokens) 输出长度(tokens) 测试点数
1、4 32、256、4096 256、1024、4096 18
16、64 32、256 256、1024、4096 12
每套配置合计 30

共测试三套完整配置:基线、完整优化、SSE-only,即 3 × 30 = 90 个矩阵点;另完成 13 组同代码 SSE 直接 A/B。

矩阵结果对比

配置 成功点 对比范围 输出吞吐变化 总吞吐变化 说明
基线 27/30 参考组 C4/I4096 三点失败
完整优化:chunk + safety + SSE 30/30 27 个共同有效点 -4.10% -4.16% 长文本全部成功,但固定安全水位过于保守
SSE-only 26/30 26 个共同有效点 +2.14% +2.09% 24 胜 2 负,但未达到全矩阵稳定
SSE 直接 A/B:interval 1 → 16 13/13 配对 同代码,仅改变 SSE 间隔 +3.36% +3.36% 12 胜 1 负;C64 提升 +6.36%

分组分析

优化收益并非均匀分布,而是集中在 SSE 事件处理开销占比较高的多并发场景。为避免仅依赖全矩阵平均值,我们对同一最终代码、仅切换 stream_interval=1/16 的直接 A/B 结果进行了分组:

分组 共同成功点 Output throughput 几何平均
全部 13 +3.36%
C64 5 +6.36%
C16 6 +1.87%
C4 2 +0.53%

代表性高并发点:

场景 Interval 1 Interval 16 变化
C64/I32/O1024 1587.38 1736.12 +9.37%
C64/I256/O1024 1086.51 1182.70 +8.85%
C64/I256/O4096 568.84 603.60 +6.11%
C64/I32/O4096 671.27 710.39 +5.83%

13 个直接配对点中有 12 点提升、1 点回退。低并发场景基本持平,而高并发场景收益更明显,符合 SSE 合并发送减少序列化、队列操作和 HTTP 事件发送开销的设计目标。+9.37% 为单点最高收益,13 点整体几何平均为 +3.36%

SSE-only 最终版与父提交在 26 个共同成功点上取得 +2.14% 的 output-throughput 几何平均提升,其中 24 点提升、2 点回退。全矩阵平均收益较低,主要因为矩阵同时包含大量计算受限、SSE 开销占比较低的小并发点,以及 C64/I256/O1024 的 -18.78% admission 限流回退。

完整 chunked prefill + KV safety + SSE 配置解决了三个 C4/I4096 长输入失败点,使成功率由 27/30 提升至 30/30。固定 KV safety 8/64 同时在部分高并发场景限制请求入场,形成可服务性与吞吐之间的权衡。

回退与失败点原因

测试点 现象 原因
SSE-only C64/I256/O1024 相对父提交 -18.78% 同一最终代码的 interval 16/1 对比在该点为 +8.85%。Parent→Final 对比还包含 scheduler admission 变化:最终调度器会为超过 block size 的 prompt 增加 fragmentation headroom,即使显式 KV safety 为 0 仍会生效;对应日志持续出现 Insufficient KV cache blocks ... deferring,导致实际入场 batch 降低。
Full C16/I256/O4096、C64/I256/* -29.56% 至 -36.31% 在 fragmentation headroom 之外,完整配置固定预留 KV_SAFETY_BLOCKS=8LONG_PROMPT_KV_SAFETY_BLOCKS=64。block size 为 256 时,静态水位在这些负载下预留较多 KV 容量,进一步降低实际 batch 并发。
SSE-only C64/I256/O256 测试失败 C64 服务依次完成三个 I32 shape 后,在该点发生 cudaGraphLaunch error,服务随后重启。两版连续多 shape 运行中均观察到同类 CUDA Graph 状态问题。
Parent 与 SSE-only C4/I4096 三点 均失败 关闭 chunked prefill 后,长 prompt 需要一次性 prefill/分配,日志出现 cudaMallocRankWorker stopped。开启 chunked prefill 后,完整配置中的三个点均 4/4 完成。

这些点分别反映三类瓶颈:scheduler admission headroom、固定 KV safety 水位,以及连续多 shape 下的 CUDA Graph 状态。SSE 的独立影响由同代码 interval 1/16 A/B 表示。

完整逐点矩阵

SSE-only 最终版与父提交

展开全部 30 个测试点
C I O Parent 成功 Parent output Parent total SSE 成功 SSE output SSE total Δoutput Δtotal
1 32 256 1/1 88.36 99.45 1/1 88.71 99.80 +0.40% +0.35%
1 32 1024 1/1 85.31 87.98 1/1 85.56 88.23 +0.29% +0.28%
1 32 4096 1/1 80.82 81.45 1/1 80.94 81.58 +0.15% +0.16%
1 256 256 1/1 86.28 172.89 1/1 86.49 172.99 +0.24% +0.06%
1 256 1024 1/1 83.66 104.59 1/1 83.71 104.64 +0.06% +0.05%
1 256 4096 1/1 79.73 84.71 1/1 80.51 85.55 +0.98% +0.99%
1 4096 256 1/1 77.51 1322.50 1/1 78.86 1340.61 +1.74% +1.37%
1 4096 1024 1/1 78.41 392.35 1/1 78.77 393.84 +0.46% +0.38%
1 4096 4096 1/1 78.39 156.80 1/1 79.29 158.59 +1.15% +1.14%
4 32 256 4/4 327.92 369.08 4/4 333.55 375.24 +1.72% +1.67%
4 32 1024 4/4 322.29 332.37 4/4 324.68 334.82 +0.74% +0.74%
4 32 4096 4/4 286.82 289.06 4/4 287.99 290.24 +0.41% +0.41%
4 256 256 4/4 315.44 632.13 4/4 317.49 634.97 +0.65% +0.45%
4 256 1024 4/4 315.37 394.37 4/4 328.83 411.04 +4.27% +4.23%
4 256 4096 4/4 281.69 299.30 4/4 283.05 300.74 +0.48% +0.48%
4 4096 256 失败 失败
4 4096 1024 失败 失败
4 4096 4096 失败 失败
16 32 256 16/16 1057.33 1189.99 16/16 1203.10 1353.49 +13.79% +13.74%
16 32 1024 16/16 921.55 950.37 16/16 1181.38 1218.30 +28.19% +28.19%
16 32 4096 16/16 525.97 530.08 16/16 549.86 554.16 +4.54% +4.54%
16 256 256 16/16 1050.79 2105.70 16/16 1059.79 2119.58 +0.86% +0.66%
16 256 1024 16/16 1126.89 1408.92 16/16 1125.87 1407.34 -0.09% -0.11%
16 256 4096 16/16 518.30 550.70 16/16 537.97 571.59 +3.80% +3.79%
64 32 256 64/64 2949.42 3319.61 64/64 2950.48 3319.29 +0.04% -0.01%
64 32 1024 64/64 1649.32 1700.92 64/64 1736.12 1790.37 +5.26% +5.26%
64 32 4096 64/64 667.41 672.63 64/64 710.39 715.94 +6.44% +6.44%
64 256 256 64/64 2226.30 4461.06 失败
64 256 1024 64/64 1456.19 1820.60 64/64 1182.70 1478.38 -18.78% -18.80%
64 256 4096 64/64 579.28 615.49 64/64 603.60 641.33 +4.20% +4.20%

完整配置与父提交

展开全部 30 个测试点
C I O Parent 成功 Parent output Parent total Full 成功 Full output Full total Δoutput Δtotal
1 32 256 1/1 88.36 99.45 1/1 88.46 99.52 +0.11% +0.07%
1 32 1024 1/1 85.31 87.98 1/1 85.19 87.86 -0.14% -0.14%
1 32 4096 1/1 80.82 81.45 1/1 80.74 81.37 -0.10% -0.10%
1 256 256 1/1 86.28 172.89 1/1 86.46 172.92 +0.21% +0.02%
1 256 1024 1/1 83.66 104.59 1/1 83.36 104.20 -0.36% -0.37%
1 256 4096 1/1 79.73 84.71 1/1 80.42 85.44 +0.87% +0.86%
1 4096 256 1/1 77.51 1322.50 1/1 78.84 1340.26 +1.72% +1.34%
1 4096 1024 1/1 78.41 392.35 1/1 78.75 393.76 +0.43% +0.36%
1 4096 4096 1/1 78.39 156.80 1/1 79.21 158.43 +1.05% +1.04%
4 32 256 4/4 327.92 369.08 4/4 333.80 375.52 +1.79% +1.74%
4 32 1024 4/4 322.29 332.37 4/4 324.34 334.47 +0.64% +0.63%
4 32 4096 4/4 286.82 289.06 4/4 287.33 289.57 +0.18% +0.18%
4 256 256 4/4 315.44 632.13 4/4 314.92 629.85 -0.16% -0.36%
4 256 1024 4/4 315.37 394.37 4/4 317.13 396.41 +0.56% +0.52%
4 256 4096 4/4 281.69 299.30 4/4 281.65 299.25 -0.01% -0.02%
4 4096 256 失败 4/4 187.26 3183.49
4 4096 1024 失败 4/4 241.12 1205.61
4 4096 4096 失败 4/4 136.71 273.41
16 32 256 16/16 1057.33 1189.99 16/16 1195.02 1344.40 +13.02% +12.98%
16 32 1024 16/16 921.55 950.37 16/16 1174.39 1211.09 +27.44% +27.43%
16 32 4096 16/16 525.97 530.08 16/16 549.72 554.01 +4.52% +4.51%
16 256 256 16/16 1050.79 2105.70 16/16 1074.01 2148.02 +2.21% +2.01%
16 256 1024 16/16 1126.89 1408.92 16/16 1139.56 1424.45 +1.12% +1.10%
16 256 4096 16/16 518.30 550.70 16/16 365.11 387.93 -29.56% -29.56%
64 32 256 64/64 2949.42 3319.61 64/64 2925.30 3290.97 -0.82% -0.86%
64 32 1024 64/64 1649.32 1700.92 64/64 1733.52 1787.70 +5.11% +5.10%
64 32 4096 64/64 667.41 672.63 64/64 616.31 621.12 -7.66% -7.66%
64 256 256 64/64 2226.30 4461.06 64/64 1471.66 2943.31 -33.90% -34.02%
64 256 1024 64/64 1456.19 1820.60 64/64 927.48 1159.35 -36.31% -36.32%
64 256 4096 64/64 579.28 615.49 64/64 393.46 418.05 -32.08% -32.08%

结论

实验结果显示两项相互独立的收益:

  1. SSE 合并发送在多并发场景具有可重复的吞吐提升,C64 分组为 +6.36%,代表点最高为 +9.37%
  2. Chunked prefill 提高了长输入场景的完成能力,使完整配置达到 30/30

综合结果表明,SSE 优化主要作用于事件发送开销明显的高并发负载;chunked prefill 提升长输入可服务性;KV admission 参数需要随并发、输入长度和可用 KV blocks 动态调整。

复现说明:当前 --stream-interval 默认值为 1,复现上述 SSE 合并结果需要在服务启动时显式设置 --stream-interval 16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant