Repository navigation
[https://nvbugs/6953985][fix] Check the KV window crossing before the logger level - #20650
Conversation
… logger level KVCacheManagerV2._log_window_crossing runs for every generation request on every step. Its guard called logger.is_debug_enabled() before the integer crossing test, and is_debug_enabled() walks the call stack to resolve the caller's module. At a 1024-request decode batch that cost about 1.6 ms of host time per step in the V2 scheduler. Test the crossing first and consult the logger only when a window is crossed. Signed-off-by: trtllm-agent <[email protected]>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Detect crossings before checking debug logging tensorrt_llm/_torch/pyexecutor/kv_cache/kv_cache_manager_v2.py, tests/unittest/_torch/pyexecutor/kv_cache/test_kv_cache_v2_capacity_only.py, tests/unittest/_torch/pyexecutor/kv_cache/test_kvcm2_integration.py |
The method returns when capacity does not increase and checks debug logging only after it finds a window crossing. Tests initialize the windowed-layer mapping and verify that non-crossing cases do not query debug severity or emit a message. |
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix
Suggested reviewers: schetlur-nv, lori-ren
Merge Risk: 
Minimal · up to 0a52d
-
The optimization preserves window-crossing logging behavior and adds coverage for non-crossing cases, with no confirmed merge-blocking defect.
Pre-merge checks: 
5
-
Full details: Description check
-
Explanation
The description clearly explains the issue, solution, rationale, test coverage, performance results, and known test limitations. It uses equivalent headings instead of the template headings and does not include the PR checklist, but it is mostly complete.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 3 files.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
|
[by Claude Code] @eopXD Could you review this PR? Thanks! |
|
Bug engineer ownership @chenfeiz0326, as the engineer assigned to the linked bug, you are responsible for driving this bot PR to resolution. Please coordinate review, address feedback and required code changes, get CI passing, and verify the original failure before driving it to merge. If the PR is obsolete or superseded, close it with a reason. Keep this PR updated with blockers and the next step. |
Signed-off-by: chenfeiz0326 <[email protected]>
…ger a window map
_log_window_crossing now runs the integer crossing test before asking the
logger, so try_allocate_generation reads the windowed layer groups on every
growth. The KVCacheManagerV2 that test_kv_cache_v2_capacity_only.py builds
with __new__ had no _windowed_layer_group_sizes, and 28 of its 44 tests
raised AttributeError. Set it to {} as
test_generation_allocation_reserves_dynamic_width does.
Signed-off-by: chenfeiz0326 <[email protected]>
|
/bot run --disable-fail-fast |
|
Updated this PR for review:
@eopXD @SimengLiu-nv, could one of you review this as a kv-cache-manager code owner? The production change is the reordered guard in |
|
PR_Github #81164 [ run ] triggered by Bot. Commit: |
|
PR_Github #81164 [ run ] completed with state Resource maintenance in LLM/main/L0_Test-x86_64-Single-GPU #4116: L40S-PyTorch-2 is temporarily paused due to Kubernetes agent provisioning and node issues.
|
|
/bot run --disable-fail-fast |
|
PR_Github #81192 [ run ] triggered by Bot. Commit: |
|
PR_Github #81192 [ run ] completed with state Resource maintenance in LLM/main/L0_Test-x86_64-Single-GPU #9105: L40S-PyTorch-2 is temporarily paused due to Kubernetes agent provisioning and node issues. |
|
CI is green on 817392d: L0_MergeRequest_PR #66886 passed (PR_Github #81192). The first run, #66859, failed on three tests. All three passed when that run's failed stages were re-run on the same commit:
The PR still needs an approval from a kv-cache-manager code owner. |
|
[by Claude Code] @eopXD Could you review this PR? Thanks! |
|
Gentle ping for a code-owner review: CI is green on 817392d and BowenFu has approved, so one approval from |
Signed-off-by: chenfeiz0326 <[email protected]>
|
/bot run --disable-fail-fast |
|
PR_Github #81816 [ run ] triggered by Bot. Commit: |
|
PR_Github #81816 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #81826 [ run ] triggered by Bot. Commit: |
|
PR_Github #81826 [ run ] completed with state |
|
Merged CI is green on 0a52d44: L0_MergeRequest_PR #67479 passed. The first run, #67470, failed only The PR still needs one approval from |
|
Friendly ping: this is ready to merge except for one approval from |
|
Still looking for one approval from |
|
This still needs one approval from |
yizhang-nv
left a comment
There was a problem hiding this comment.
Reviewed at 0a52d44 (merge-base 2d1a7d1). The method is unchanged on current main.
The reordered guard is correct and behavior-preserving. I ran the base and head _log_window_crossing source against the real logger.py and compared the emitted debug lines. The runs covered:
- every global level from trace to error, plus runtime
set_level; TLLM_LOG_LEVEL_BY_MODULEoverrides that enable_torch, disable it, or touch only another module;- no growth, shrinking, growth without a crossing, a single crossing, and several windows crossed in one call.
The output was identical in every case, and the head consults the logger only on an actual crossing.
Reading _get_windowed_layer_group_sizes() on every growth is safe in production. __init__ initializes the cache before any allocation, and every V2 subclass chains to it. The new test fails on the old guard for the two growth cases.
However, I'm not approving this as the fix for NVBug 6953985. This branch already contains b6d1a06. Since that commit, is_debug_enabled() no longer walks the stack unless per-module levels are set. In the bug's configuration on the current base, this change therefore saves only about 10–25 µs per 1024 calls on x86 (details below).
I'd suggest closing it. Alternatively, keep it as a retitled cleanup for runs that set TLLM_LOG_LEVEL_BY_MODULE. If it stays, there is a docstring nit inline.
My numbers come from CPU-only microbenchmarks of the unmodified method source with the real logger. I did not rerun on GB200.
On current main, this change no longer removes a meaningful cost for the NVBug 6953985 case, so I don't think it should merge as that bug's fix. I'd suggest closing it, or retitling it as a small cleanup without Fixes.
The saving described here came from Logger.is_debug_enabled(), which resolved the caller's module through _get_caller_module() on every call. b6d1a06 (#19646) changed that: when no per-module levels are configured, is_debug_enabled() is now a plain level comparison, and log() returns before the stack walk for filtered messages.
This branch has contained that commit since its latest merge of main (0a52d44). The NVBug case sets only TLLM_LOG_LEVEL=INFO for its workers (worker_env_var in tests/scripts/perf-sanity/disaggregated/gb200_gpt-oss-120b-fp4_8k1k_con1024_ctx1_tp1_gen1_tp4_eplb0_mtp0_ccb-NIXL.yaml), so it already takes the fast path. The GB200 numbers in the description were measured on the 10-19 base (066332a), before that change.
I benchmarked the real logger.py with the unmodified _log_window_crossing source from base and head, on CPU:
- 1024 non-crossing decode calls, one windowed layer group;
- x86, Python 3.12;
- results in µs per 1024 calls, as the range across independent harnesses.
| logger | old guard | this PR |
|---|---|---|
| before b6d1a06 | ~437–454 | ~130–148 |
| current base | ~154–159 | ~131–146 |
What this means for each configuration:
- Default configuration: on the current base, the PR saves about 10–25 µs per 1024 calls on x86, down from ~300 µs with the old logger. The ~1.6 ms GB200 figure in the description is about 4× the ~0.44 ms I measure for the old guard on x86. Scaled by that factor, the saving is at most about 0.1 ms per step, below 1% of a ~15 ms step.
- More than one windowed layer group: the two orders are about even, and the new one gets slower as groups are added.
TLLM_LOG_LEVEL_BY_MODULEset: the change still removes the stack walk (~450–470 → ~115–150 µs per 1024 calls), so it keeps some value for runs that use per-module levels.
Three other points bear on the NVBug:
- #21463 is also open against this NVBug. It reports a ~0.6 ms gap on recent
main, which already includes b6d1a06, and attributes that gap to step stalls and the periodic response burst. - The description here notes that the ~100 ms stalls aren't addressed.
- Main's L0 post-merge perf sanity no longer runs this case (#20163), so CI wouldn't confirm a fix after merge.
If you want to keep the change for the per-module-level case, could you:
- retitle it (e.g.
[None][perf]or[None][chore]); - drop
Fixes https://nvbugs/6953985; - refresh the description: the perf section, and the
tests/unittest/_torch/executor/kv_cache/...path, which #20669 moved totests/unittest/_torch/pyexecutor/kv_cache/?
|
Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements. |
- Squashed commits in cc63e66..d4f4cd2f - Bump up version to 1.4.0rc0.post1 Includes the GPT-OSS-120B serving optimizations and EAGLE3 min_length fix. Preserves the source tree's FlashInfer and CUTLASS attribution notices. Backports include #19857 (chenfeiz0326), #20244 and #20650 (jthomson04). Co-authored-by: chenfeiz0326 <[email protected]> Co-authored-by: jthomson04 <[email protected]> Signed-off-by: Matthias Maiterth <[email protected]> Signed-off-by: Yanchao Lu <[email protected]>
Summary
KVCacheManagerV2._log_window_crossingruns for every generation request on every decode step, fromtry_allocate_generationin the V2 scheduler. Its early-return guard waslogger.is_debug_enabled()resolves the caller's module by walking the stack (_get_caller_module), so the guard paid that cost on every call. During decodenew_capacity > pre_capacityholds on every call, so the integer short-circuit never fired. The sliding-window crossing it guards happens at most once per request per pool.This change runs the integer crossing test first and asks the logger only when a window is actually crossed. The debug output is unchanged: the same line is logged under the same conditions, including per-module
TLLM_LOG_LEVEL_BY_MODULEoverrides.Why it matters
Since KV cache manager V2 became the default (#17495), the gen worker of
disagg-gen_only-gb200_gpt-oss-120b-fp4_8k1k_con1024_ctx1_tp1_gen1_tp4_eplb0_mtp0_ccb-NIXLruns the V2 scheduler. That case regressed from 16.45 to 17.13 ms Mean Gen Worker Per-Iter Device Step Time (https://nvbugs/6953985). At 1024 decode requests the host loop (~15 ms) is about as long as the device step, so extra host time shows up as device idle time. Measured on the gen worker:_log_window_crossingaccounted for ~1.6 ms of the ~5.8 ms per step spent in V2 scheduling.Test plan
test_window_crossing_does_not_query_the_logger_without_a_crossing: ordinary decode growth below and above the window, and no growth, must not callis_debug_enabled(). It fails before this change and passes after. The existing window-crossing tests are unchanged and still pass: crossing logged once with capacity and blocks, silent without a crossing, severity order, per-module levels, unreadable page indices.test_generation_allocation_reserves_dynamic_widthbuilds a bare manager withobject.__new__. It now sets_windowed_layer_group_sizes = {}, because the window map is read on every growth instead of only when debug logging is on.tests/unittest/_torch/executor/kv_cache/test_kvcm2_integration.py: 166 passed.test_world_ranks_converge_on_host_failure(an MPI pool test) timed out under the 120 s per-test limit in both the patched and the unpatched run.test_kv_cache_v2_scheduler.py: 327 passed.test_kv_connector_v2_prefix.py: 54 passed.test_kv_cache_v2_first_new_block_probe.py: 37 passed.kv_cache_manager_v2_tests/test_kv_cache_stats_behavior.py: 24 passed.aggr-gen_only_no_contextof the same config), 5 reps per arm: unfixed 16.93, 15.43, 16.10, 16.25, 16.77; fixed 15.49, 15.86, 16.00, 15.30, 16.01; base withuse_kv_cache_manager_v2: false15.72, 15.29, 16.22, 15.96, 15.57. The fixed median sits within 1% of the V1 run; unfixed is 3.4% above it.disagg-gen_onlycase, 2 nodes, three jobs: median per-iteration step time 15.97-16.19 ms fixed (8 reps) vs 16.74-17.42 ms unfixed (9 reps); every fixed rep is below every unfixed rep. The V1 run measured 15.95-15.98 ms. Median host step time per iteration: 15.7-16.0 ms fixed vs 16.6-17.0 ms unfixed. The mean also contains occasional ~100 ms stalls that are present without the change too and are not addressed here.Fixes https://nvbugs/6953985
Dev Engineer Review
KVCacheManagerV2._log_window_crossingnow checks capacity growth and window crossings before querying debug-log severity. This avoids the logger’s stack-resolution cost when no crossing occurs. The change preserves crossing diagnostics and the existing per-module log-level check.The capacity-only fixture now initializes
_windowed_layer_group_sizes, which the reordered guard reads during growth. No public API or configuration changes are reported.QA Engineer Review
Two test files changed. The integration test adds checks that non-crossing growth and no growth do not query the logger, while crossing still logs diagnostics; the capacity-only file updates its manager fixture. The existing capacity-only test file is listed in
test-db/l0_a10.yml. The integration test file has an existing specific test entry intest-db/l0_b200.yml, but the new test is not listed there by name. No manual-QA entry was found in the supplied list search.Coverage verdict: sufficient. Reported results include 44 passing capacity-only tests after the fixture update and passing focused test suites. The integration run also had a timeout reported as intermittent on both patched and unpatched runs.
Per-File QA Perspective
tensorrt_llm/_torch/pyexecutor/kv_cache/kv_cache_manager_v2.py— Verify that a crossing still emits the expected diagnostic at applicable log levels. Verify that non-crossing growth skips the logger severity query on generation and context paths.tests/unittest/_torch/pyexecutor/kv_cache/test_kv_cache_v2_capacity_only.py— The fixture now models no windowed pools. This test file is listed in CI attests/integration/test_lists/test-db/l0_a10.yml.tests/unittest/_torch/pyexecutor/kv_cache/test_kvcm2_integration.py— New parameterized cases cover no growth and growth before or after a window, plus existing crossing and diagnostic fallback behavior. The file has an existing CI entry for a different test intests/integration/test_lists/test-db/l0_b200.yml; the new test is not individually listed.