Skip to content

feat(metrics): export KV held by deferred frees - #3238

Open
MengqingCao wants to merge 1 commit into
mengqing/pd-admission-watermarkfrom
mengqing/deferred-free-metrics
Open

MengqingCao wants to merge 1 commit into
mengqing/pd-admission-watermarkfrom
mengqing/deferred-free-metrics

Conversation

@MengqingCao

@MengqingCao MengqingCao commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Split out of #3173 on review: these are P-side metrics and do not depend on decode admission. The PR sits on top of the stack only for ordering; it touches none of the admission code.

Every scheduler exports two gauges, summed across DP ranks:

  • atom:requests_deferred_free: finished or aborted requests kept allocated as a whole until every connector releases them.
  • atom:kv_cache_blocks_deferred_free: the physical KV blocks those requests hold, shared prefix blocks counted once.

On P/D prefill this is the source KV decode has not pulled yet. An offload save that defers the whole request is counted the same way. Early-release offload leases are not included: those blocks return once every rank has finished reading them, before the store completes.

Both are computed in EngineUtilityHandler.collect_metrics at snapshot time, not per step. physical_block_count marks a boolean mask over the pool from each block table's buffer instead of building a Python set of every id. collect_metrics reads scheduler.deferred_free_blocks directly; Scheduler.__init__ always sets it, and RapidServe's PrefillScheduler has no block manager, so it never reaches this branch.

Both gauges are listed under "Engine aggregate state" in docs/metrics_guide.md.

Test plan

  • CPU, at this head: tests/test_pd*.py, tests/test_mooncake*.py, tests/test_kv_connector*.py, tests/test_disagg*.py, tests/test_model_runner*.py, tests/test_scheduler*.py, tests/test_engine_core*.py, tests/entrypoints/test_metrics.py, tests/test_gpu_metrics.py, tests/test_observability_report.py: 1320 passed, 22 skipped. New here: test_deferred_free_counts_shared_blocks_once[list] and [new_block_table], the second over the array('i') a real block table is.
  • Black and Ruff on the changed Python files.

Stack created with GitHub Stacks CLI • Give Feedback 💬

@MengqingCao
MengqingCao added this pull request to stack #3174 November 12, 2026 09:16
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every eligible PR before approval:

  • ✅ Pre Checkin: Black, Ruff, catalog schema validation, non-GPU unit tests

Heavy model tests:

  • ✅ Run after the PR is approved and Pre Checkin passes
  • ✅ Run immediately when an approval review is submitted
  • ✅ Can be requested before approval with labels
Label Tests
ci:full Run all heavy PR model tests: native ATOM, vLLM, and SGLang
ci:atom Run native ATOM model accuracy tests
ci:vllm Run ATOM vLLM OOT model accuracy tests
ci:sglang Run ATOM SGLang model accuracy tests

Heavy jobs are skipped when the PR is not approved and no matching ci:* label is present.
Add labels via the sidebar or gh pr edit 3238 --add-label <label>

@MengqingCao

Copy link
Copy Markdown
Contributor Author

@valar-cop

@valar-cop

Copy link
Copy Markdown

@MengqingCao LGTM, reading each table into one mask over the pool is the right call instead of a python set. one thing: did you see it move on a real pd pair, prefill holding source kv until the send completes, or only the cpu tests? hold before pre-checkin and atom test pass.

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

ci green.

@MengqingCao
MengqingCao force-pushed the mengqing/deferred-free-metrics branch 2 times, most recently from 2c03991 to 655fcbb Compare November 12, 2026 15:29
@MengqingCao
MengqingCao force-pushed the mengqing/deferred-free-metrics branch 2 times, most recently from 16fdeab to 30d4fe6 Compare November 12, 2026 16:38
Add atom:requests_deferred_free and atom:kv_cache_blocks_deferred_free:
finished or aborted requests the scheduler keeps allocated as a whole until
every connector releases them, and the physical blocks they hold, shared
prefixes counted once. On P/D prefill this is the source KV decode has not
pulled yet. Early-release offload leases are not included.

Both are computed with the metrics snapshot, from the block tables'
buffers rather than a Python set.
@MengqingCao
MengqingCao force-pushed the mengqing/deferred-free-metrics branch from 30d4fe6 to 13a2e8b Compare November 12, 2026 16:44

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