Skip to content

feat(pd): balance heterogeneous prefill load by input tokens - #1425

Open
sufubao wants to merge 1 commit into
ModelTC:mainfrom
sufubao:pd-prefill-dp-token-balancer
Open

feat(pd): balance heterogeneous prefill load by input tokens#1425
sufubao wants to merge 1 commit into
ModelTC:mainfrom
sufubao:pd-prefill-dp-token-balancer

Conversation

@sufubao

@sufubao sufubao commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

背景

bs_balancer 这个 DP 均衡器用「请求数」度量每个 dp rank 的负载。在 prefill 节点上,如果 prompt 长短差异大(异构),按请求数均衡会出现:某个 dp rank 被分到一个超长 prompt,其它 rank 按人头看是均衡的、实则近乎空闲,prefill 延迟被拉长。

改动

DpBsBalancer 加一个 balance_by_input_tokens 模式:负载按「剩余 input token 数」度量,即 max(1, input_len - max(0, shm_cur_kv_len))(已命中 KV cache 的部分不计入)。

  • get_dp_balancerrun_mode == "prefill" 时启用该模式;decode 节点保持原有按请求数的行为,不受影响。
  • 默认值 balance_by_input_tokens=False,行为完全等价于改动前。

测试

新增 unit_tests/server/router/req_queue/test_dp_bs_balancer.py

  • test_prefill_balancer_uses_remaining_input_tokens:dp0 已有一个 160k(已缓存 20k → 剩余 140k)的大请求,dp1 有两个 1k 请求;新来一个 10k 请求,按 input-token 均衡应分给 dp1(而不是按人头分给 dp0)。
  • test_decode_balancer_keeps_request_count_behavior:默认(decode)模式下仍按请求数均衡,大请求不影响选点。

2 passed

The bs dp balancer measures load by request count. On a prefill node
that is fine when prompts are similar size, but with a heterogeneous
mix one dp rank can be assigned a very long prompt while the others sit
near-idle headcount-balanced, stretching prefill latency.

Add a balance_by_input_tokens mode that measures load as remaining
input tokens (input_len minus already-cached kv length). get_dp_balancer
enables it for run_mode == "prefill"; decode keeps the request-count
behavior unchanged.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

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