Skip to content

[https://nvbugs/6438658][fix] Account for resume utilization in KV constraints#16484

Merged
jiaganc merged 1 commit into
NVIDIA:mainfrom
jiaganc:codex/kv-constraints-resume-util
Jul 20, 2026
Merged

[https://nvbugs/6438658][fix] Account for resume utilization in KV constraints#16484
jiaganc merged 1 commit into
NVIDIA:mainfrom
jiaganc:codex/kv-constraints-resume-util

Conversation

@jiaganc

@jiaganc jiaganc commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Improved KV cache capacity planning to reserve sufficient headroom for resuming cached requests.
    • Prevented constraint-based allocations from reaching utilization levels that could block cache resumption.
  • Tests

    • Added coverage verifying that constrained KV caches can resume successfully, including after being reduced to minimal capacity.

Description

Constraint-derived pool floors currently reserve the exact slot count required by each constrained batch. However, _KVCache.resume() rejects a resume when projected utilization exceeds max_util_for_resume, so a supposedly supported constraint can still fail before the pool is full.

Pass max_util_for_resume into StorageManager and scale constraint-derived minimum slot counts by the inverse utilization threshold. This preserves sufficient headroom for constrained batches to resume. Explicit user-provided pool ratios continue to take precedence over inferred constraints.

Test Coverage

  • Added test_constraint_reserves_resume_headroom to exercise a complete constrained batch at max_util_for_resume=0.95.
  • python3 -m py_compile passed for all changed files.
  • Relevant pre-commit checks passed.
  • The focused pytest test was not run locally because pytest is not installed in this checkout's Python environment.

PR Checklist

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

@jiaganc
jiaganc marked this pull request as ready for review July 16, 2026 08:16
@jiaganc
jiaganc requested a review from a team as a code owner July 16, 2026 08:16
@jiaganc
jiaganc requested review from nvpohanh and thorjohnsen July 16, 2026 08:16
@jiaganc

jiaganc commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator Author

Hi, @lowsfer could you please review this PR?

@jiaganc
jiaganc requested a review from lowsfer July 16, 2026 08:17
@jiaganc

jiaganc commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Constraint-derived KV cache slot floors now reserve headroom based on max_util_for_resume. KVCacheManager forwards the setting to StorageManager, and a unit test verifies constrained caches can resume successfully.

Changes

KV cache resume headroom

Layer / File(s) Summary
Constraint slot headroom calculation
tensorrt_llm/runtime/kv_cache_manager_v2/_storage_manager.py
StorageManager accepts max_util_for_resume and scales constraint-derived slot minima using ceiling division before applying pool-group floors.
Manager wiring and validation
tensorrt_llm/runtime/kv_cache_manager_v2/_core/_kv_cache_manager.py, tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py
KVCacheManager forwards the utilization limit, and the test verifies constrained caches can resume with reserved capacity.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • NVIDIA/TensorRT-LLM#16426: Changes the same constraint-derived minimum-slot sizing path with a different slot-floor calculation.

Suggested reviewers: lowsfer

Sequence Diagram(s)

sequenceDiagram
  participant TestInitRatioConfig
  participant KVCacheManager
  participant StorageManager
  participant KVCache
  TestInitRatioConfig->>KVCacheManager: create constrained KV caches
  KVCacheManager->>StorageManager: pass max_util_for_resume
  StorageManager-->>KVCacheManager: reserve scaled slot capacity
  KVCacheManager->>KVCache: resume cache
  KVCache-->>TestInitRatioConfig: resume succeeds
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the PR scope, includes the nvbugs ticket and fix type, and clearly states the main change.
Description check ✅ Passed The description follows the template and includes the issue, solution, test coverage, and checklist.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py (1)

2446-2470: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider adding a negative/boundary companion test.

The new test verifies the success path once headroom scaling is applied. As per path instructions for tests/**, coverage should be assessed for sufficiency: since without the scaling, min_slots=32 would put utilization at exactly 1.0 > 0.95, this test would likely already catch a regression that removes scaling entirely — coverage is sufficient for that case. Optionally, add a companion test asserting resume() returns False at max_util_for_resume=1.0 (or with an even tighter constraint) to make the headroom mechanism's necessity explicit and pin the boundary behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py` around
lines 2446 - 2470, Add a boundary companion test for the resume headroom
behavior around KVCacheManager and max_util_for_resume, configuring utilization
at the threshold (for example, 1.0 or a tighter constraint) and asserting
kv_cache.resume(stream) returns False. Reuse the existing setup symbols such as
BatchDesc, KVCacheManager, and _make_config, and ensure resources are closed and
the manager is shut down.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tensorrt_llm/runtime/kv_cache_manager_v2/_storage_manager.py`:
- Around line 943-947: Validate max_util_for_resume before the scaling
calculation in the constraints flow around _compute_slots_for_batch, enforcing 0
< max_util_for_resume <= 1.0. Update KVCacheManagerConfig.__post_init__ if
appropriate so invalid values are rejected before division, while preserving the
existing max_slots calculation for valid values.

---

Nitpick comments:
In `@tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py`:
- Around line 2446-2470: Add a boundary companion test for the resume headroom
behavior around KVCacheManager and max_util_for_resume, configuring utilization
at the threshold (for example, 1.0 or a tighter constraint) and asserting
kv_cache.resume(stream) returns False. Reuse the existing setup symbols such as
BatchDesc, KVCacheManager, and _make_config, and ensure resources are closed and
the manager is shut down.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 16c0f58a-2645-44d5-9bfe-f75034311daa

📥 Commits

Reviewing files that changed from the base of the PR and between 4188dbe and f240f4f.

📒 Files selected for processing (3)
  • tensorrt_llm/runtime/kv_cache_manager_v2/_core/_kv_cache_manager.py
  • tensorrt_llm/runtime/kv_cache_manager_v2/_storage_manager.py
  • tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_manager_v2.py

Comment thread tensorrt_llm/runtime/kv_cache_manager_v2/_storage_manager.py
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59674 [ run ] triggered by Bot. Commit: f240f4f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59674 [ run ] completed with state SUCCESS. Commit: f240f4f
/LLM/main/L0_MergeRequest_PR pipeline #48107 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@jiaganc
jiaganc force-pushed the codex/kv-constraints-resume-util branch from f240f4f to 4cebd09 Compare July 17, 2026 03:05
@jiaganc

jiaganc commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59854 [ run ] triggered by Bot. Commit: 4cebd09 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59854 [ run ] completed with state SUCCESS. Commit: 4cebd09
/LLM/main/L0_MergeRequest_PR pipeline #48259 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@jiaganc

jiaganc commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59882 [ run ] triggered by Bot. Commit: 4cebd09 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59882 [ run ] completed with state SUCCESS. Commit: 4cebd09
/LLM/main/L0_MergeRequest_PR pipeline #48285 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@jiaganc

jiaganc commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59987 [ run ] triggered by Bot. Commit: 4cebd09 Link to invocation

@jiaganc
jiaganc enabled auto-merge (squash) July 17, 2026 15:58
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59987 [ run ] completed with state FAILURE. Commit: 4cebd09
/LLM/main/L0_MergeRequest_PR pipeline #48381 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

Signed-off-by: Jiagan Cheng <jiaganc@nvidia.com>
@jiaganc
jiaganc force-pushed the codex/kv-constraints-resume-util branch from 4cebd09 to ff4f191 Compare July 20, 2026 03:19
@jiaganc

jiaganc commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60247 [ run ] triggered by Bot. Commit: ff4f191 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60247 [ run ] completed with state SUCCESS. Commit: ff4f191
/LLM/main/L0_MergeRequest_PR pipeline #48608 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@jiaganc

jiaganc commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60314 [ run ] triggered by Bot. Commit: ff4f191 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60314 [ run ] completed with state SUCCESS. Commit: ff4f191
/LLM/main/L0_MergeRequest_PR pipeline #48660 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@jiaganc

jiaganc commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60374 [ run ] triggered by Bot. Commit: ff4f191 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60374 [ run ] completed with state SUCCESS. Commit: ff4f191
/LLM/main/L0_MergeRequest_PR pipeline #48713 completed with status: 'SUCCESS'

CI Report

Link to invocation

@jiaganc
jiaganc merged commit 445742c into NVIDIA:main Jul 20, 2026
7 checks passed
@jiaganc
jiaganc deleted the codex/kv-constraints-resume-util branch July 21, 2026 03:02
lowsfer added a commit to lowsfer/TensorRT-LLM that referenced this pull request Jul 21, 2026
Port the Python-side fix from PR NVIDIA#16484 (nvbugs/6438658) to the C++
StorageManager so both backends behave identically: thread max_util_for_resume
from KVCacheManagerConfig through the StorageManager constructor, and scale each
constraint-derived min-slot floor by 1/max_util_for_resume in
computeMinSlotsFromConstraints so a declared batch stays below the utilization
gate checked by KvCache::resume.

This mirrors main's behavior exactly: an explicit initial_pool_ratio still
overrides constraints for min-slots (the gating is kept), and the scale factor
is applied unconditionally (no clamping).

Signed-off-by: Yao Yao <lowsfer@users.noreply.github.com>
lowsfer added a commit to lowsfer/TensorRT-LLM that referenced this pull request Jul 21, 2026
REVIEW NOTE: this is the cpp-branch behavior delta on top of the previous commit
(which mirrors main's PR NVIDIA#16484). It is isolated so it can be reviewed or dropped
independently. If we decide to match main exactly, revert just this commit.

Diverges from main's resume-utilization fix in two ways, on both the Python and
C++ backends:
- Constraints stay feasibility floors even under an explicit initial_pool_ratio
  (main drops them): a declared batch that needs more than its target pool-group
  share clamps that share up instead of starving during warmup. Follows Lanyu's
  C++ commit 15a90e1 (which cited PR NVIDIA#16269).
- Clamp max_util_for_resume to the binding (0, 1) range before scaling, so a
  degenerate 0 can't divide-by-zero and a value >= 1 can't shrink floors.

Renames test_initial_pool_ratio_overrides_typical_step_and_constraints to
test_constraint_floor_overrides_infeasible_initial_pool_ratio to assert the new
behavior (main's test_constraint_reserves_resume_headroom is kept as-is).

Signed-off-by: Yao Yao <lowsfer@users.noreply.github.com>
lowsfer added a commit to lowsfer/TensorRT-LLM that referenced this pull request Jul 21, 2026
Port the Python-side fix from PR NVIDIA#16484 (nvbugs/6438658) to the C++
StorageManager so both backends behave identically: thread max_util_for_resume
from KVCacheManagerConfig through the StorageManager constructor, and scale each
constraint-derived min-slot floor by 1/max_util_for_resume in
computeMinSlotsFromConstraints so a declared batch stays below the utilization
gate checked by KvCache::resume.

This mirrors main's behavior exactly: an explicit initial_pool_ratio still
overrides constraints for min-slots (the gating is kept), and the scale factor
is applied unconditionally (no clamping).

Signed-off-by: Yao Yao <lowsfer@users.noreply.github.com>
lowsfer added a commit to lowsfer/TensorRT-LLM that referenced this pull request Jul 21, 2026
REVIEW NOTE: this is the cpp-branch behavior delta on top of the previous commit
(which mirrors main's PR NVIDIA#16484). It is isolated so it can be reviewed or dropped
independently. If we decide to match main exactly, revert just this commit.

Diverges from main's resume-utilization fix in two ways, on both the Python and
C++ backends:
- Constraints stay feasibility floors even under an explicit initial_pool_ratio
  (main drops them): a declared batch that needs more than its target pool-group
  share clamps that share up instead of starving during warmup. Follows Lanyu's
  C++ commit 15a90e1 (which cited PR NVIDIA#16269).
- Clamp max_util_for_resume to the binding (0, 1) range before scaling, so a
  degenerate 0 can't divide-by-zero and a value >= 1 can't shrink floors.

Renames test_initial_pool_ratio_overrides_typical_step_and_constraints to
test_constraint_floor_overrides_infeasible_initial_pool_ratio to assert the new
behavior (main's test_constraint_reserves_resume_headroom is kept as-is).

Signed-off-by: Yao Yao <lowsfer@users.noreply.github.com>
lowsfer added a commit to lowsfer/TensorRT-LLM that referenced this pull request Jul 21, 2026
Port the Python-side fix from PR NVIDIA#16484 (nvbugs/6438658) to the C++
StorageManager so both backends behave identically: thread max_util_for_resume
from KVCacheManagerConfig through the StorageManager constructor, and scale each
constraint-derived min-slot floor by 1/max_util_for_resume in
computeMinSlotsFromConstraints so a declared batch stays below the utilization
gate checked by KvCache::resume.

This mirrors main's behavior exactly: an explicit initial_pool_ratio still
overrides constraints for min-slots (the gating is kept), and the scale factor
is applied unconditionally (no clamping).

Signed-off-by: Yao Yao <lowsfer@users.noreply.github.com>
lowsfer added a commit to lowsfer/TensorRT-LLM that referenced this pull request Jul 21, 2026
REVIEW NOTE: this is the cpp-branch behavior delta on top of the previous commit
(which mirrors main's PR NVIDIA#16484). It is isolated so it can be reviewed or dropped
independently. If we decide to match main exactly, revert just this commit.

Diverges from main's resume-utilization fix in two ways, on both the Python and
C++ backends:
- Constraints stay feasibility floors even under an explicit initial_pool_ratio
  (main drops them): a declared batch that needs more than its target pool-group
  share clamps that share up instead of starving during warmup. Follows Lanyu's
  C++ commit 15a90e1 (which cited PR NVIDIA#16269).
- Clamp max_util_for_resume to the binding (0, 1) range before scaling, so a
  degenerate 0 can't divide-by-zero and a value >= 1 can't shrink floors.

Renames test_initial_pool_ratio_overrides_typical_step_and_constraints to
test_constraint_floor_overrides_infeasible_initial_pool_ratio to assert the new
behavior (main's test_constraint_reserves_resume_headroom is kept as-is).

Signed-off-by: Yao Yao <lowsfer@users.noreply.github.com>
lowsfer added a commit to lowsfer/TensorRT-LLM that referenced this pull request Jul 21, 2026
Port the Python-side fix from PR NVIDIA#16484 (nvbugs/6438658) to the C++
StorageManager so both backends behave identically: thread max_util_for_resume
from KVCacheManagerConfig through the StorageManager constructor, and scale each
constraint-derived min-slot floor by 1/max_util_for_resume in
computeMinSlotsFromConstraints so a declared batch stays below the utilization
gate checked by KvCache::resume.

This mirrors main's behavior exactly: an explicit initial_pool_ratio still
overrides constraints for min-slots (the gating is kept), and the scale factor
is applied unconditionally (no clamping).

Signed-off-by: Yao Yao <lowsfer@users.noreply.github.com>
lowsfer added a commit to lowsfer/TensorRT-LLM that referenced this pull request Jul 21, 2026
REVIEW NOTE: this is the cpp-branch behavior delta on top of the previous commit
(which mirrors main's PR NVIDIA#16484). It is isolated so it can be reviewed or dropped
independently. If we decide to match main exactly, revert just this commit.

Diverges from main's resume-utilization fix in two ways, on both the Python and
C++ backends:
- Constraints stay feasibility floors even under an explicit initial_pool_ratio
  (main drops them): a declared batch that needs more than its target pool-group
  share clamps that share up instead of starving during warmup. Follows Lanyu's
  C++ commit 15a90e1 (which cited PR NVIDIA#16269).
- Clamp max_util_for_resume to the binding (0, 1) range before scaling, so a
  degenerate 0 can't divide-by-zero and a value >= 1 can't shrink floors.

Renames test_initial_pool_ratio_overrides_typical_step_and_constraints to
test_constraint_floor_overrides_infeasible_initial_pool_ratio to assert the new
behavior (main's test_constraint_reserves_resume_headroom is kept as-is).

Signed-off-by: Yao Yao <lowsfer@users.noreply.github.com>
lowsfer added a commit to lowsfer/TensorRT-LLM that referenced this pull request Jul 21, 2026
Port the Python-side fix from PR NVIDIA#16484 (nvbugs/6438658) to the C++
StorageManager so both backends behave identically: thread max_util_for_resume
from KVCacheManagerConfig through the StorageManager constructor, and scale each
constraint-derived min-slot floor by 1/max_util_for_resume in
computeMinSlotsFromConstraints so a declared batch stays below the utilization
gate checked by KvCache::resume.

This mirrors main's behavior exactly: an explicit initial_pool_ratio still
overrides constraints for min-slots (the gating is kept), and the scale factor
is applied unconditionally (no clamping).

Signed-off-by: Yao Yao <lowsfer@users.noreply.github.com>
lowsfer added a commit to lowsfer/TensorRT-LLM that referenced this pull request Jul 21, 2026
REVIEW NOTE: this is the cpp-branch behavior delta on top of the previous commit
(which mirrors main's PR NVIDIA#16484). It is isolated so it can be reviewed or dropped
independently. If we decide to match main exactly, revert just this commit.

Diverges from main's resume-utilization fix in two ways, on both the Python and
C++ backends:
- Constraints stay feasibility floors even under an explicit initial_pool_ratio
  (main drops them): a declared batch that needs more than its target pool-group
  share clamps that share up instead of starving during warmup. Follows Lanyu's
  C++ commit 15a90e1 (which cited PR NVIDIA#16269).
- Clamp max_util_for_resume to the binding (0, 1) range before scaling, so a
  degenerate 0 can't divide-by-zero and a value >= 1 can't shrink floors.

Renames test_initial_pool_ratio_overrides_typical_step_and_constraints to
test_constraint_floor_overrides_infeasible_initial_pool_ratio to assert the new
behavior (main's test_constraint_reserves_resume_headroom is kept as-is).

Signed-off-by: Yao Yao <lowsfer@users.noreply.github.com>
lowsfer added a commit to lowsfer/TensorRT-LLM that referenced this pull request Jul 21, 2026
Port the Python-side fix from PR NVIDIA#16484 (nvbugs/6438658) to the C++
StorageManager so both backends behave identically: thread max_util_for_resume
from KVCacheManagerConfig through the StorageManager constructor, and scale each
constraint-derived min-slot floor by 1/max_util_for_resume in
computeMinSlotsFromConstraints so a declared batch stays below the utilization
gate checked by KvCache::resume.

This mirrors main's behavior exactly: an explicit initial_pool_ratio still
overrides constraints for min-slots (the gating is kept), and the scale factor
is applied unconditionally (no clamping).

Signed-off-by: Yao Yao <lowsfer@users.noreply.github.com>
lowsfer added a commit to lowsfer/TensorRT-LLM that referenced this pull request Jul 21, 2026
REVIEW NOTE: this is the cpp-branch behavior delta on top of the previous commit
(which mirrors main's PR NVIDIA#16484). It is isolated so it can be reviewed or dropped
independently. If we decide to match main exactly, revert just this commit.

Diverges from main's resume-utilization fix in two ways, on both the Python and
C++ backends:
- Constraints stay feasibility floors even under an explicit initial_pool_ratio
  (main drops them): a declared batch that needs more than its target pool-group
  share clamps that share up instead of starving during warmup. Follows Lanyu's
  C++ commit 15a90e1 (which cited PR NVIDIA#16269).
- Clamp max_util_for_resume to the binding (0, 1) range before scaling, so a
  degenerate 0 can't divide-by-zero and a value >= 1 can't shrink floors.

Renames test_initial_pool_ratio_overrides_typical_step_and_constraints to
test_constraint_floor_overrides_infeasible_initial_pool_ratio to assert the new
behavior (main's test_constraint_reserves_resume_headroom is kept as-is).

Signed-off-by: Yao Yao <lowsfer@users.noreply.github.com>
eopXD added a commit to eopXD/TensorRT-LLM that referenced this pull request Jul 22, 2026
…verage

Add a Python-only per-iteration suspend/resume (preemption) observability
counter to KVCacheManagerV2 -- iterSuspendedRequests / iterResumedRequests,
surfaced via get_stats() -- together with the tests that exercise it. This
coverage is genuinely new on main: no existing test can assert on the counter
because the counter did not exist, and there is no end-to-end suspend/resume
integration cell for GPT-OSS on the V2 manager. (Overlapping bring-up cells --
eagle3-1gpu, chunked-prefill -- already exist on main and are deliberately
NOT re-added here.)

Stat (mirrors the NVIDIA#15633 offload/onboard path; no C++/nanobind change):
incremented at _KVCache.suspend() and on a successful resume(), gated on
_should_record_stats(), drained once per iteration-stats fetch into
KVCacheV2IterationStatsReport and emitted as top-level iteration keys.

Coverage added:
- tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_stats_behavior.py:
  the counters increment on suspend+resume and surface via
  get_iteration_stats() (model-free, deterministic).
- tests/unittest/executor/test_stats_serializer.py: the serializer emits the
  top-level counters (not nested inside the per-pool-group breakdown).
- tests/integration/defs/accuracy/test_llm_api_pytorch.py::TestGPTOSS::
  test_w4_1gpu_suspend_resume -- V2-only ACTIVE<->SUSPENDED->resume round trip
  with page-index reconnect; gates on iterSuspendedRequests>0 and
  iterResumedRequests>0, no crash/deadlock, and a >=3-token deterministic
  prefix vs the uncontended reference.

Verification: the suspend/resume unit + serializer tests and I-10 passed on the
rc21 build (main ef6ebc2 + NVIDIA#15633): I-10 suspended=31/resumed=35,
offload/onboard=0, prefixes 17/11/19/8; api_stability 64/64. The unit tests are
model-free and base-insensitive. I-10's workload sizing was tuned on rc21 and
has NOT yet been re-run on this later main; the resume-utilization change
(NVIDIA#16484) can shift when suspension fires, so retune max_tokens if the gate-(2)
counters come back 0.

Signed-off-by: Yueh-Ting Chen <yuehtingc@nvidia.com>
eopXD added a commit to eopXD/TensorRT-LLM that referenced this pull request Jul 22, 2026
…verage

Add a Python-only per-iteration suspend/resume (preemption) observability
counter to KVCacheManagerV2 -- iterSuspendedRequests / iterResumedRequests,
surfaced via get_stats() -- together with the tests that exercise it. This
coverage is genuinely new on main: no existing test can assert on the counter
because the counter did not exist, and there is no end-to-end suspend/resume
integration cell for GPT-OSS on the V2 manager. (Overlapping bring-up cells --
eagle3-1gpu, chunked-prefill -- already exist on main and are deliberately
NOT re-added here.)

Stat (mirrors the NVIDIA#15633 offload/onboard path; no C++/nanobind change):
incremented at _KVCache.suspend() and on a successful resume(), gated on
_should_record_stats(), drained once per iteration-stats fetch into
KVCacheV2IterationStatsReport and emitted as top-level iteration keys.

Coverage added:
- tests/unittest/kv_cache_manager_v2_tests/test_kv_cache_stats_behavior.py:
  the counters increment on suspend+resume and surface via
  get_iteration_stats() (model-free, deterministic).
- tests/unittest/executor/test_stats_serializer.py: the serializer emits the
  top-level counters (not nested inside the per-pool-group breakdown).
- tests/integration/defs/accuracy/test_llm_api_pytorch.py::TestGPTOSS::
  test_w4_1gpu_suspend_resume -- V2-only ACTIVE<->SUSPENDED->resume round trip
  with page-index reconnect; gates on iterSuspendedRequests>0 and
  iterResumedRequests>0, no crash/deadlock, and a >=3-token deterministic
  prefix vs the uncontended reference. Registered in
  tests/integration/test_lists/test-db/l0_b200.yml (1-GPU B200, pre-merge).

Verification: the suspend/resume unit + serializer tests and I-10 passed on the
rc21 build (main ef6ebc2 + NVIDIA#15633): I-10 suspended=31/resumed=35,
offload/onboard=0, prefixes 17/11/19/8; api_stability 64/64. The unit tests are
model-free and base-insensitive. I-10's workload sizing was tuned on rc21 and
has NOT yet been re-run on this later main; the resume-utilization change
(NVIDIA#16484) can shift when suspension fires, so retune max_tokens if the gate-(2)
counters come back 0.

Signed-off-by: Yueh-Ting Chen <yuehtingc@nvidia.com>
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.

3 participants