Handle extreme diagonal values in CPU Trilu - #32013
Merged
Akshay Sonawane (apsonawane) merged 1 commit intoAug 13, 2026
Merged
Conversation
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 12, 2026 06:01
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 12, 2026 06:02
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request hardens the CPU implementation of the ONNX Trilu operator against extreme diagonal (k) values (e.g., int64_t min/max) by short-circuiting cases where the requested diagonal is fully out of bounds, and adds targeted unit tests to validate those edge conditions.
Changes:
- Add early-exit handling in the CPU
TriluImplto correctly return identity/all-zero outputs whenkis far outside the matrix bounds (avoiding problematic arithmetic with extreme values). - Add new CPU-only tests covering
k = std::numeric_limits<int64_t>::min()andk = std::numeric_limits<int64_t>::max()for both upper and lower triangular modes. - Update test includes to support extreme
int64_tconstants.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| onnxruntime/test/providers/cpu/tensor/trilu_op_test.cc | Adds CPU-only unit tests for extreme k values using std::numeric_limits<int64_t>::min/max(). |
| onnxruntime/core/providers/cpu/tensor/trilu.cc | Adds bounds checks/short-circuits in TriluImpl to handle out-of-range diagonals safely and deterministically. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ti-Tai Wang (titaiwangms)
approved these changes
Aug 13, 2026
Akshay Sonawane (apsonawane)
deleted the
fix/trilu-extreme-diagonal-overflow
branch
August 13, 2026 17:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request improves the robustness of the
Triluoperator implementation and its test coverage, particularly for edge cases involving extreme diagonal values. The main changes include handling out-of-bounds diagonal indices in the implementation and adding new tests to ensure correct behavior for these cases.Implementation robustness:
TriluImplintrilu.ccto handle extreme values ofk_val(diagonal index), ensuring the output is correctly set or skipped whenk_valis out of bounds for both upper and lower triangular cases.Test coverage improvements:
trilu_op_test.ccto verify behavior whenkis set to the minimum and maximum possibleint64_tvalues, ensuring the operator's correctness for these edge cases.<limits>header to facilitate the use of extreme integer values in tests.