Skip to content

Handle extreme diagonal values in CPU Trilu - #32013

Merged
Akshay Sonawane (apsonawane) merged 1 commit into
mainfrom
fix/trilu-extreme-diagonal-overflow
Aug 13, 2026
Merged

Akshay Sonawane (apsonawane) merged 1 commit into
mainfrom
fix/trilu-extreme-diagonal-overflow

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request improves the robustness of the Trilu operator 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:

  • Updated TriluImpl in trilu.cc to handle extreme values of k_val (diagonal index), ensuring the output is correctly set or skipped when k_val is out of bounds for both upper and lower triangular cases.

Test coverage improvements:

  • Added new tests in trilu_op_test.cc to verify behavior when k is set to the minimum and maximum possible int64_t values, ensuring the operator's correctness for these edge cases.
  • Included <limits> header to facilitate the use of extreme integer values in tests.

Copilot AI 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.

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 TriluImpl to correctly return identity/all-zero outputs when k is far outside the matrix bounds (avoiding problematic arithmetic with extreme values).
  • Add new CPU-only tests covering k = std::numeric_limits<int64_t>::min() and k = std::numeric_limits<int64_t>::max() for both upper and lower triangular modes.
  • Update test includes to support extreme int64_t constants.

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.

@apsonawane
Akshay Sonawane (apsonawane) merged commit 871146e into main Aug 13, 2026
88 checks passed
@apsonawane
Akshay Sonawane (apsonawane) deleted the fix/trilu-extreme-diagonal-overflow branch August 13, 2026 17:54
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.

3 participants