Skip to content

[https://nvbugs/6127669][fix] Fix layer-wise benchmarks performance alignment test#16212

Open
kaiyux wants to merge 3 commits into
NVIDIA:mainfrom
kaiyux:user/kaiyu/bug_lw_bench_6127669
Open

[https://nvbugs/6127669][fix] Fix layer-wise benchmarks performance alignment test#16212
kaiyux wants to merge 3 commits into
NVIDIA:mainfrom
kaiyux:user/kaiyu/bug_lw_bench_6127669

Conversation

@kaiyux

@kaiyux kaiyux commented Jul 10, 2026

Copy link
Copy Markdown
Member

Description

Fixes unittest/tools/test_layer_wise_benchmarks.py::test_performance_alignment[1] (https://nvbugs/6127669) and removes the stale waives of the other single-GPU layer-wise benchmark tests (https://nvbugs/6162541, https://nvbugs/6153575).

test_performance_alignment[1] had several independent problems that stacked up on the 26.04 CI stack:

  • Executor hang under nsys (the CI failure). Draining the in-flight batch through progressively smaller CUDA graph batch sizes with nsys attached wedges the device stream: the executor blocks in SamplerEvent.synchronize() until the CI timeout kills the test (reproduced deterministically on B200 at the first batch-4 graph replay; the same workload passes without nsys). sample_performance_alignment.sh now sizes max_num_tokens so that all requests prefill — and therefore finish — at the same iteration. This removes the drain phase entirely and also matches the steady-state batch assumption of the correlation methodology.
  • Traces unusable with recent nsys. Recent nsys exports kernels launched by CUDA graphs that were instantiated before the collection session opened without runtime correlation (correlationId = 0), so parse_e2e.py's CUPTI_ACTIVITY_KIND_RUNTIME join dropped all graph kernels (10 kernels/iter seen instead of ~915). The engine captures its CUDA graphs during warmup, before any -c cudaProfilerApi capture range can open, so Steps 1–2 now trace the whole benchmark process, and parse_e2e.py gets explicit --start-iter/--stop-iter bounds to select the analyzed window.
  • Replay window off by one. The calibrator collects the TLLM_PROFILE_START_STOP iterations [start, stop), but Step 3 replayed up to the stop iteration, raising KeyError once the earlier steps were fixed.
  • NVTX regex rot. The [Executor] _forward_step NVTX text gained a "ctx tokens" field ([None][chore] log KV cache utilization and context tokens per iter #14206) that parse_e2e.py's regex did not accept; the segment is now matched optionally so both old and new traces parse.
  • Profiler-stop ordering in PyExecutor. Calibration data is now persisted and the device synchronized before cudaProfilerStop(), so profiling tools that stop collecting (or end the process, e.g. nsys --capture-range-end=stop-shutdown) at the range close cannot lose the calibration file or end the capture with in-flight async copies.

The waives of test_nemotron_gen_dep[1], test_qwen3_next_gen_tep[1], and test_deepseek_r1_ctx_dep[1] are removed as stale: the underlying failures no longer reproduce on the 26.04 stack. test_deepseek_r1_ctx_dep[1] remains skipped in-code pending https://nvbugs/6337228 (see #15497), so its waive removal is a no-op for CI today but lets the test run as soon as that skip is lifted.

Test Coverage

Verified on B200 (single GPU) with the current CI container image:

  • unittest/tools/test_layer_wise_benchmarks.py::test_performance_alignment[1] passes in 281 s (previously hit the 2400 s timeout).
  • unittest/tools/test_layer_wise_benchmarks.py::test_nemotron_gen_dep[1] passes in 226 s.
  • unittest/tools/test_layer_wise_benchmarks.py::test_qwen3_next_gen_tep[1] passes in 62 s.
  • The test_deepseek_r1_ctx_dep[1] benchmark and parser pass when invoked directly (the pytest case is skipped in-code, see above).
  • sample_performance_alignment.sh completes all five steps end to end, including parse_e2e.py and correlation.py.

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • 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.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved CUDA profiling and calibration shutdown sequencing to ensure data is saved reliably.
    • Refined benchmark iteration selection for more accurate eager and CUDA Graph performance comparisons.
  • Documentation

    • Updated profiling instructions, replay windows, and iteration-range guidance.
    • Clarified capture settings and calibration-to-replay alignment.
  • Tests

    • Removed waivers for several layer-wise benchmark alignment test cases, allowing them to run normally.

@kaiyux kaiyux requested review from a team as code owners July 10, 2026 02:48
@kaiyux kaiyux requested review from QiJune, chang-l and joyang-nv July 10, 2026 02:48
@kaiyux kaiyux marked this pull request as draft July 10, 2026 02:49
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Layer-wise profiling now uses explicit iteration windows, updated CUDA Graph tracing commands, aligned replay parameters, and corrected calibration shutdown ordering.

Changes

Layer-wise profiling alignment

Layer / File(s) Summary
Calibration shutdown ordering
tensorrt_llm/_torch/pyexecutor/py_executor.py
Calibration stopping and CUDA synchronization now precede CUDA profiler shutdown in normal and cleanup paths.
Bounded timeline parsing
examples/layer_wise_benchmarks/parse_e2e.py
Adds iteration bounds and applies them when selecting target, eager, and graph iterations.
Profiling and replay workflow
examples/layer_wise_benchmarks/README.md, examples/layer_wise_benchmarks/sample_performance_alignment.sh, tests/integration/test_lists/waives.txt
Updates profiling flags, replay and cache parameters, parser windows, documentation, and related test waivers.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: achartier, brb-nv, PerkzZheng

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required ticket/type format and clearly summarizes the main fix for layer-wise benchmark performance alignment.
Description check ✅ Passed The description includes Description, Test Coverage, and the PR checklist, and it explains the issue, solution, and verification clearly.
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
examples/layer_wise_benchmarks/README.md (1)

310-324: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Align the documented KV-cache length with the replay window.

For the documented --batch-size 32 and replay range, sample_performance_alignment.sh:128 computes 2048 + 32 + 22 = 2102, while the README still says 2090. Following these instructions produces a mismatched replay past length.

Proposed fix
-       --seq-len-kv-cache 2090 \
+       --seq-len-kv-cache 2102 \
🤖 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 `@examples/layer_wise_benchmarks/README.md` around lines 310 - 324, Update the
`--seq-len-kv-cache` argument explanation in the benchmark README from 2090 to
2102, matching the replay window calculation for batch size 32 described by
`sample_performance_alignment.sh`.
examples/layer_wise_benchmarks/sample_performance_alignment.sh (1)

1-3: 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Add the required NVIDIA license header.

This modified shell source has no NVIDIA Apache-2.0 copyright header. Keep the shebang first and add the standard 2026 header immediately after it.

🤖 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 `@examples/layer_wise_benchmarks/sample_performance_alignment.sh` around lines
1 - 3, Add the standard NVIDIA Apache-2.0 copyright and license header
immediately after the shebang in the shell script, preserving the shebang as the
first line and keeping set -euo pipefail unchanged.

Source: Coding guidelines

🤖 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.

Outside diff comments:
In `@examples/layer_wise_benchmarks/README.md`:
- Around line 310-324: Update the `--seq-len-kv-cache` argument explanation in
the benchmark README from 2090 to 2102, matching the replay window calculation
for batch size 32 described by `sample_performance_alignment.sh`.

In `@examples/layer_wise_benchmarks/sample_performance_alignment.sh`:
- Around line 1-3: Add the standard NVIDIA Apache-2.0 copyright and license
header immediately after the shebang in the shell script, preserving the shebang
as the first line and keeping set -euo pipefail unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b0adf1ed-fcb7-496e-9c58-026ab44879d8

📥 Commits

Reviewing files that changed from the base of the PR and between 6b9f6dc and 0cf3072.

📒 Files selected for processing (5)
  • examples/layer_wise_benchmarks/README.md
  • examples/layer_wise_benchmarks/parse_e2e.py
  • examples/layer_wise_benchmarks/sample_performance_alignment.sh
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
  • tests/integration/test_lists/waives.txt
💤 Files with no reviewable changes (1)
  • tests/integration/test_lists/waives.txt

kaiyux added 3 commits July 9, 2026 22:43
…lignment test

The test has been waived since it started failing on the B200 CI pool;
several independent problems stacked up:

- Recent nsys exports kernels launched by CUDA graphs that were
  instantiated before the capture range opened without runtime
  correlation (correlationId 0), which drops them from parse_e2e.py's
  RUNTIME join. The engine captures its CUDA graphs during warmup,
  before any "-c cudaProfilerApi" range can open, so trace the whole
  benchmark process instead and give parse_e2e.py explicit
  --start-iter/--stop-iter bounds for the analyzed window.
- Draining the in-flight batch through progressively smaller CUDA graph
  batch sizes with nsys attached wedges the device stream: the executor
  hangs in SamplerEvent.synchronize() until the CI timeout kills the
  test. Size max_num_tokens so that all requests prefill (and therefore
  finish) at the same iteration; this removes the drain phase and also
  matches the steady-state assumption of the correlation methodology.
- The replay window was off by one: the calibrator collects the
  TLLM_PROFILE_START_STOP iterations [start, stop), but Step 3 replayed
  up to the stop iteration, raising KeyError once the earlier steps were
  fixed.
- The "[Executor] _forward_step" NVTX text gained a "ctx tokens" field
  (NVIDIA#14206) that parse_e2e.py's regex did not accept.
- In PyExecutor, persist calibration data and synchronize before
  cudaProfilerStop(), so profiling tools that stop collecting or end the
  process when the capture range closes cannot lose the calibration file
  or end the capture with in-flight async copies.

Verified on B200 (single GPU): sample_performance_alignment.sh completes
all five steps, and test_performance_alignment[1] passes; remove its
waive.

Signed-off-by: Kaiyu Xie <26294424+kaiyux@users.noreply.github.com>
…U tests

The failures no longer reproduce on the 26.04 stack. Verified on B200
(single GPU):

- test_nemotron_gen_dep[1] (https://nvbugs/6162541): passes in 226 s.
- test_qwen3_next_gen_tep[1] (https://nvbugs/6153575, split off as
  https://nvbugs/6250535): passes in 62 s.
- test_deepseek_r1_ctx_dep[1] (https://nvbugs/6162541): the benchmark
  and parser pass when invoked directly. The pytest case itself stays
  skipped in-code until https://nvbugs/6337228 is resolved, so removing
  the waive is a no-op for CI today but lets the test run as soon as
  that skip is lifted.

Signed-off-by: Kaiyu Xie <26294424+kaiyux@users.noreply.github.com>
Signed-off-by: Kaiyu Xie <26294424+kaiyux@users.noreply.github.com>
@kaiyux kaiyux force-pushed the user/kaiyu/bug_lw_bench_6127669 branch from 7e07ae9 to 0550083 Compare July 10, 2026 05:44
@kaiyux kaiyux marked this pull request as ready for review July 10, 2026 05:44
@kaiyux

kaiyux commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

@Tabrizian Since this touches the changes in #13744, can you help take a look?

@kaiyux

kaiyux commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

/bot run --disable-fail-fast

@nv-guomingz nv-guomingz 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 for doc part

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58608 [ run ] triggered by Bot. Commit: 0550083 Link to invocation

@Tabrizian Tabrizian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Py_executor changes LGTM.

@kaiyux kaiyux enabled auto-merge (squash) July 10, 2026 06:00
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.

4 participants