Skip to content

[https://nvbugs/6223556][fix] Propagate gen-first ctx usage via aux buffer to postproc - #15246

Merged
reasonsolo merged 4 commits into
NVIDIA:mainfrom
reasonsolo:repair-bot-bug6223556
Jun 16, 2026
Merged

[https://nvbugs/6223556][fix] Propagate gen-first ctx usage via aux buffer to postproc#15246
reasonsolo merged 4 commits into
NVIDIA:mainfrom
reasonsolo:repair-bot-bug6223556

Conversation

@reasonsolo

@reasonsolo reasonsolo commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Root cause: In gen-first disaggregated scheduling the context and generation requests run concurrently, so the context worker's usage accounting cannot be injected into the request as it is in the context-first path. It is instead delivered to the generation worker through the KV-transfer aux buffer (RxSession.unpack_aux), which sets py_disaggregated_params.ctx_usage. However, that value was never surfaced onto the response, so the postprocessor fell back to the generation worker's local accounting — which treats the entire transferred prompt as cached and over-reports cached_tokens (the full prompt length 17 instead of the reused prompt_tokens-1 = 16). This caused test_disaggregated_overlap_gen_first to fail its cache-reuse usage check.

Fix: Complete the existing aux-buffer transmission pipeline (introduced in #14177) instead of rewriting usage at the orchestrator:

  • Carry ctx_usage on LlmResult.
  • Set it on the response alongside cached_tokens in py_executor (all three response-creation sites: generation, fast-transfer, and streaming emit).
  • Surface it onto the output's disaggregated_params in result.py so the existing postprocessor path (_ctx_usage_from_outputs -> rewrite_usage_info_from_ctx) adopts the context-side accounting.

This keeps the disaggregated orchestrator a thin proxy (consistent with #14177) and fixes both streaming and non-streaming gen-first usage, since the postprocessor already handles both uniformly.

The overlap_gen_first test configs are updated to enable block/partial reuse so the cache-reuse usage check is meaningful, and the corresponding waives are removed.

Test plan

  • test_disaggregated_overlap_gen_first[ctx_pp1-TinyLlama-1.1B-Chat-v1.0] passes (B200). Before fix: every request reported cached_tokens == prompt_tokens (17/17). After fix: first (cold) request reports the context-side count (e.g. cached_tokens: 3), second (reuse) request reports prompt_tokens - 1 (16 for completions, 30 for chat).
  • ctx_pp4 variant — verified by CI (locally blocked by GPU availability; logic is identical and independent of context-side pipeline parallelism).

Links

Summary by CodeRabbit

  • Bug Fixes

    • Fixed disaggregated scheduling test cases for TinyLlama-1.1B-Chat model that were previously waived.
  • Improvements

    • Enhanced context-side usage tracking and accounting in disaggregated execution scheduling modes.
    • Enabled KV-cache block reuse optimization in test configurations for better memory efficiency.

@reasonsolo
reasonsolo requested review from a team as code owners June 11, 2026 06:01
@reasonsolo
reasonsolo requested review from Tabrizian and hchings June 11, 2026 06:01
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds context-worker usage propagation for gen-first disaggregated scheduling. A new ctx_usage field flows from request to response through PyExecutor via a propagation helper, is received by the result processor, and test configurations enable KV-cache reuse flags while removing two previously-waived test entries.

Changes

Gen-first disaggregated context-usage propagation

Layer / File(s) Summary
Response result structure with context-usage field
tensorrt_llm/_torch/pyexecutor/llm_request.py
LlmResult initializes a new ctx_usage attribute to None, documented as context-worker usage transferred via KV auxiliary buffer in disaggregated modes.
PyExecutor context-usage propagation helper and call sites
tensorrt_llm/_torch/pyexecutor/py_executor.py
Introduces _maybe_attach_ctx_usage() static helper to copy py_disaggregated_params.ctx_usage from request onto response. Helper is invoked in three paths: fast KV-transfer completion, early first-token emission, and normal response handling after cached_tokens is set.
Result processing with context-usage storage
tensorrt_llm/executor/result.py
GenerationResultBase._handle_response checks for ctx_usage in response and updates _disaggregated_params via dataclasses.replace, allowing the postprocessor to account for context-side usage in gen-first flows.
Test configuration and validation updates
tests/integration/defs/disaggregated/test_configs/disagg_config_overlap_gen_first.yaml, disagg_config_overlap_gen_first_pp4.yaml, tests/integration/test_lists/waives.txt
Enables enable_block_reuse and enable_partial_reuse in two test configurations (standard and pipeline-parallel-4 variants). Removes two previously-waived test entries for test_disaggregated_overlap_gen_first on TinyLlama with ctx_pp1 and ctx_pp4 that now pass with the context-usage propagation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • yechank-nvidia
  • SimengLiu-nv
  • StanleySun639
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: propagating gen-first context usage via auxiliary buffer to postprocessor, which is the core objective of the PR.
Description check ✅ Passed The PR description comprehensively covers root cause, fix details, implementation approach, test results, and links. It exceeds template requirements with thorough technical context.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch repair-bot-bug6223556

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

@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

🤖 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/_torch/pyexecutor/llm_request.py`:
- Around line 569-574: The LlmResult.__init__ currently sets self.ctx_usage =
None without a type annotation which can be inferred as NoneType; update
LlmResult.__init__ to declare the attribute with the proper optional dict type,
e.g. self.ctx_usage: Optional[Dict[str, Any]] = None, and ensure you import
Optional and Dict/Any in the module if not already present so type checkers
recognize the intended type used elsewhere (ctx_usage.get(...)).
🪄 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: e5ab7d4b-f062-44be-8a06-69ac992fa7e2

📥 Commits

Reviewing files that changed from the base of the PR and between 205920d and e644e79.

📒 Files selected for processing (6)
  • tensorrt_llm/_torch/pyexecutor/llm_request.py
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
  • tensorrt_llm/executor/result.py
  • tests/integration/defs/disaggregated/test_configs/disagg_config_overlap_gen_first.yaml
  • tests/integration/defs/disaggregated/test_configs/disagg_config_overlap_gen_first_pp4.yaml
  • tests/integration/test_lists/waives.txt
💤 Files with no reviewable changes (1)
  • tests/integration/test_lists/waives.txt

Comment thread tensorrt_llm/_torch/pyexecutor/llm_request.py Outdated
@reasonsolo
reasonsolo enabled auto-merge (squash) June 11, 2026 06:10
@reasonsolo

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53496 [ run ] triggered by Bot. Commit: a175926 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53496 [ run ] completed with state SUCCESS. Commit: a175926
/LLM/main/L0_MergeRequest_PR pipeline #42656 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

@reasonsolo

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53584 [ run ] triggered by Bot. Commit: a175926 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53584 [ run ] completed with state SUCCESS. Commit: a175926
/LLM/main/L0_MergeRequest_PR pipeline #42731 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

@reasonsolo
reasonsolo force-pushed the repair-bot-bug6223556 branch from a175926 to bb645c2 Compare June 12, 2026 01:11
@reasonsolo

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

1 similar comment
@reasonsolo

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53737 [ run ] triggered by Bot. Commit: 741a294 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53739 [ run ] triggered by Bot. Commit: 741a294 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53737 [ run ] completed with state SUCCESS. Commit: 741a294
/LLM/main/L0_MergeRequest_PR pipeline #42863 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

@reasonsolo

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53739 [ run ] completed with state SUCCESS. Commit: 741a294
/LLM/main/L0_MergeRequest_PR pipeline #42865 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

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53852 [ run ] triggered by Bot. Commit: e615062 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53852 [ run ] completed with state SUCCESS. Commit: e615062
/LLM/main/L0_MergeRequest_PR pipeline #42960 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

@reasonsolo
reasonsolo force-pushed the repair-bot-bug6223556 branch from e615062 to 1bca389 Compare June 15, 2026 03:31
@reasonsolo

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54205 [ run ] triggered by Bot. Commit: 1bca389 Link to invocation

@reasonsolo
reasonsolo force-pushed the repair-bot-bug6223556 branch from 1bca389 to 6b6953d Compare June 15, 2026 08:53
@reasonsolo

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54271 [ run ] triggered by Bot. Commit: 6b6953d Link to invocation

@reasonsolo

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54299 [ run ] triggered by Bot. Commit: 6b6953d Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54271 [ run ] completed with state ABORTED. Commit: 6b6953d

Link to invocation

@fredricz-20070104 fredricz-20070104 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved

@reasonsolo

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54396 [ run ] triggered by Bot. Commit: 6b6953d Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54299 [ run ] completed with state ABORTED. Commit: 6b6953d

Link to invocation

@lancelly lancelly left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

…uffer to postproc

In gen-first disaggregated scheduling the context and generation requests
run concurrently, so the context worker's usage cannot be injected into the
request as in the context-first path. It is instead delivered to the
generation worker through the KV-transfer aux buffer
(RxSession.unpack_aux), which sets py_disaggregated_params.ctx_usage. That
value was never surfaced onto the response, so the postprocessor fell back
to the generation worker's local accounting, which treats the entire
transferred prompt as cached and over-reports cached_tokens (e.g. the whole
prompt length 17 instead of the reused prompt_tokens-1 = 16).

Carry ctx_usage on LlmResult, set it on the response alongside cached_tokens
in the executor, and surface it onto the output's disaggregated_params so
the existing postprocessor path (_ctx_usage_from_outputs ->
rewrite_usage_info_from_ctx) adopts the context-side accounting. This keeps
the orchestrator a thin proxy and fixes both streaming and non-streaming.

Enable block/partial reuse in the overlap_gen_first test configs so the
cache-reuse usage check is meaningful, and remove the related waives.

Signed-off-by: Lizhi Zhou <1432185+reasonsolo@users.noreply.github.com>
Signed-off-by: Lizhi Zhou <1432185+reasonsolo@users.noreply.github.com>
…ttribute access

Both py_disaggregated_params and ctx_usage are unconditionally initialized
in their respective __init__ methods, so getattr fallbacks are unnecessary.

Signed-off-by: Lizhi Zhou <1432185+reasonsolo@users.noreply.github.com>
response_result in _handle_response can be the raw C++
bindings.executor.Result (non-disagg / benchmark path), which has no
ctx_usage attribute -- only the Python LlmResult wrapper sets it. The
previous direct attribute access therefore raised AttributeError on the
non-disagg path (e.g. trtllm-bench). Fall back to None via getattr, the
same pattern the adjacent cached_tokens line already uses.

Signed-off-by: Lizhi Zhou <1432185+reasonsolo@users.noreply.github.com>
@reasonsolo
reasonsolo force-pushed the repair-bot-bug6223556 branch from 6b6953d to aa306ca Compare June 16, 2026 04:51
@reasonsolo

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54464 [ run ] triggered by Bot. Commit: aa306ca Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54396 [ run ] completed with state ABORTED. Commit: 6b6953d

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54464 [ run ] completed with state SUCCESS. Commit: aa306ca
/LLM/main/L0_MergeRequest_PR pipeline #43528 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

@reasonsolo

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54580 [ run ] triggered by Bot. Commit: aa306ca Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54580 [ run ] completed with state SUCCESS. Commit: aa306ca
/LLM/main/L0_MergeRequest_PR pipeline #43623 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

Link to invocation

@reasonsolo

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54603 [ run ] triggered by Bot. Commit: aa306ca Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54603 [ run ] completed with state SUCCESS. Commit: aa306ca
/LLM/main/L0_MergeRequest_PR pipeline #43639 completed with status: 'SUCCESS'

CI Report

Link to invocation

@reasonsolo
reasonsolo merged commit 163be83 into NVIDIA:main Jun 16, 2026
7 checks passed
xinhe-nv pushed a commit to tensorrt-cicd/TensorRT-LLM that referenced this pull request Jun 23, 2026
…uffer to postproc (NVIDIA#15246)

Signed-off-by: Lizhi Zhou <1432185+reasonsolo@users.noreply.github.com>
Signed-off-by: GitLab CI Bot <gitlab-ci@nvidia.com>
xinhe-nv pushed a commit to tensorrt-cicd/TensorRT-LLM that referenced this pull request Jun 24, 2026
…uffer to postproc (NVIDIA#15246)

Signed-off-by: Lizhi Zhou <1432185+reasonsolo@users.noreply.github.com>
Signed-off-by: GitLab CI Bot <gitlab-ci@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.

6 participants