[https://nvbugs/6276842][test] Loosen rtol/atol on encoder CUDA graph logits parity check - #15527
Conversation
📝 WalkthroughWalkthroughThe CUDA-graph vs eager decoder encode logit comparison tolerances in ChangesCUDA-graph tolerance fix and waiver removal
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/integration/defs/accuracy/test_llm_api_pytorch_encode.py (1)
439-439: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick winUpdate misleading comment about "tight numerical bound".
The docstring claims "Tight numerical bound" but the tolerances are now
rtol=5e-2(5%) andatol=0.5, which are quite loose. This will mislead future maintainers about the test's purpose and strictness.📝 Suggested docstring update
- def test_decoder_encode_cuda_graph_matches_eager_logits(self, model_name, model_path): - """Tight numerical bound: decoder single-prefill graph replay must reproduce eager logits.""" + def test_decoder_encode_cuda_graph_matches_eager_logits(self, model_name, model_path): + """Decoder single-prefill CUDA graph replay should produce logits close to eager mode. + + Tolerances are relaxed to account for numerical precision differences from + cuBLAS kernel selection between eager (using sum of sequence lengths) and + CUDA graph (using padded token counts) execution modes. + """🤖 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/integration/defs/accuracy/test_llm_api_pytorch_encode.py` at line 439, The docstring at line 439 claims "Tight numerical bound" but the actual tolerance values used in the test are rtol=5e-2 (5%) and atol=0.5, which are considered loose tolerances. Update the docstring to accurately reflect that the test uses loose tolerances rather than tight ones. This will ensure future maintainers understand the actual strictness level of the numerical comparison without being misled by the current wording.
🧹 Nitpick comments (1)
tests/integration/defs/accuracy/test_llm_api_pytorch_encode.py (1)
456-456: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoffConsider documenting tolerance rationale and adding semantic checks.
The tolerances have been loosened substantially (50x for
rtol, 500x foratol). While the PR objectives provide technical justification, consider:
Document inline why these specific values: Add a comment explaining that these tolerances account for cuBLAS kernel selection differences between eager and CUDA graph modes, similar to the detailed explanation in the PR description.
Consider semantic checks: The
test_decoder_encode_matches_huggingfacetest uses a two-tier approach (top-K overlap + focused numerical check) that may be more robust than pure numerical comparison. Withatol=0.5, logits can differ by 0.5 absolute units—would a top-K semantic check provide better signal that the outputs are functionally equivalent?Verify test effectiveness: Confirm that these tolerances still catch meaningful correctness issues rather than just allowing any output to pass.
💭 Example: Adding tolerance documentation
eager = torch.stack([o.logits.cpu() for o in eager_outs]) graph = torch.stack([o.logits.cpu() for o in graph_outs]) - torch.testing.assert_close(graph, eager, rtol=5e-2, atol=0.5) + # Relaxed tolerances account for numerical precision differences from + # cuBLAS kernel selection (eager uses sum of seq lengths, graph uses + # padded tokens). Differences accumulate across decoder layers. + torch.testing.assert_close(graph, eager, rtol=5e-2, atol=0.5)🤖 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/integration/defs/accuracy/test_llm_api_pytorch_encode.py` at line 456, The torch.testing.assert_close call in the comparison between graph and eager results uses substantially loosened tolerances (rtol=5e-2, atol=0.5) without documentation explaining the rationale. Add an inline comment immediately before the assert_close call to explain why these specific tolerance values are necessary, specifically documenting that they account for cuBLAS kernel selection differences between eager and CUDA graph execution modes. Additionally, consider supplementing this numerical tolerance check with semantic validation checks similar to the two-tier approach used in test_decoder_encode_matches_huggingface (such as top-K overlap validation) to ensure the outputs remain functionally equivalent and that the loosened tolerances do not mask meaningful correctness issues.
🤖 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 `@tests/integration/defs/accuracy/test_llm_api_pytorch_encode.py`:
- Line 439: The docstring at line 439 claims "Tight numerical bound" but the
actual tolerance values used in the test are rtol=5e-2 (5%) and atol=0.5, which
are considered loose tolerances. Update the docstring to accurately reflect that
the test uses loose tolerances rather than tight ones. This will ensure future
maintainers understand the actual strictness level of the numerical comparison
without being misled by the current wording.
---
Nitpick comments:
In `@tests/integration/defs/accuracy/test_llm_api_pytorch_encode.py`:
- Line 456: The torch.testing.assert_close call in the comparison between graph
and eager results uses substantially loosened tolerances (rtol=5e-2, atol=0.5)
without documentation explaining the rationale. Add an inline comment
immediately before the assert_close call to explain why these specific tolerance
values are necessary, specifically documenting that they account for cuBLAS
kernel selection differences between eager and CUDA graph execution modes.
Additionally, consider supplementing this numerical tolerance check with
semantic validation checks similar to the two-tier approach used in
test_decoder_encode_matches_huggingface (such as top-K overlap validation) to
ensure the outputs remain functionally equivalent and that the loosened
tolerances do not mask meaningful correctness issues.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: f40725e7-d967-4861-bff1-c271899c31ed
📒 Files selected for processing (2)
tests/integration/defs/accuracy/test_llm_api_pytorch_encode.pytests/integration/test_lists/waives.txt
💤 Files with no reviewable changes (1)
- tests/integration/test_lists/waives.txt
Signed-off-by: tingyangk <tingyangk@nvidia.com>
4de582c to
b8f1041
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #55087 [ run ] triggered by Bot. Commit: |
|
PR_Github #55087 [ run ] completed with state |
… logits parity check (NVIDIA#15527) Signed-off-by: tingyangk <tingyangk@nvidia.com>
Summary by CodeRabbit
Description
Loosens rtol/atol for the encoder CUDA-graph vs eager logits parity check because cuBLAS picks different GEMM kernels for
o_projanddown_projat the eager-M (sum(seq_lens)) vs graph-M (padded_num_tokens), producing tiny numerical gaps that compound across multiple decoder layers to a final logits diff.Test Coverage
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-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin 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.