Skip to content

[CB] Scale the per-token memory estimate by the TP size - #48566

Open
qgallouedec wants to merge 11 commits into
mainfrom
cb-tp-aware-pool
Open

qgallouedec wants to merge 11 commits into
mainfrom
cb-tp-aware-pool

Conversation

@qgallouedec

@qgallouedec qgallouedec commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

CPU CI GPU run-slow

Rebased on #47809, which already divides the KV heads by tp_size for the page size. What remained: the PagedAttentionMemoryHandler per-token activation estimate (query projection, new K/V, repeated KV at the attention peak) still used the unsharded head counts, so under TP it reserved tp_size times too much per batch token and the pool came out smaller than it could be.

The cache now passes the TP size the KV heads are sharded over (1 when they are not) and the handler scales the head counts with it. A rank holding 1/tp_size of the heads predicts the footprint of a model with that many heads; the new test checks exactly that against a handler built on the halved config.

qgallouedec and others added 2 commits September 5, 2026 14:56
…elism

PagedAttentionMemoryHandler estimated bytes per block and the activation peak with the unsharded head counts, while each rank only holds num_heads // tp_size of them, so under TP the pool came out tp x too small: Qwen3-32B at tp4 got 221k tokens and used 36 of 80 GiB per GPU, 14B at tp2 365k. The handler now takes the TP size when the KV projections are in the TP plan and divides both counts by it. Qwen3-32B tp4, 1024 short prompts, hub kernels: 6,523 -> 11,277 tok/s (pool 221k -> 884k tokens, 450 -> 672 concurrent requests); 14B tp2 365k -> 731k tokens.
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@qgallouedec
qgallouedec requested a review from remi-or September 11, 2026 03:23
@qgallouedec qgallouedec changed the title [CB] Size the KV pool with the per-rank head count under TP [CB] Scale the per-token memory estimate by the TP size Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 37495197592:1
Result: success | Jobs: 2 | Tests: 2 | Failures: 0 | Duration: 9s

@qgallouedec

Copy link
Copy Markdown
Member Author

Still needed: PagedAttentionMemoryHandler uses the unsharded head counts. @remi-or @ArthurZucker could you take a look?

This branch has not been deployed

No deployments
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.

2 participants