[Kernel] Fix bug in Einsum implementation when a lone operand had a reduction operation#27225
[Kernel] Fix bug in Einsum implementation when a lone operand had a reduction operation#27225hariharans29 merged 12 commits intomainfrom
Conversation
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_typed_compute_processor.cc
Outdated
Show resolved
Hide resolved
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_typed_compute_processor.cc
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the Einsum implementation that occurred when a single input operand underwent both a reduction and transpose operation. The issue manifested as a shape mismatch error where the candidate output rank didn't match the number of subscript indices.
Changes:
- Fixed the rank mismatch issue by ensuring all dimensions (including reduced ones with value 1) are tracked when calling FinalizeOutput for single-input cases
- Added an ORT_ENFORCE check to catch this type of internal bug earlier in FinalizeOutput
- Added a test case covering the specific bug scenario ("ijk->ki" equation)
- Improved comment clarity by adding "relative" to describe order preservation in IsTransposeReshapeForEinsum
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| onnxruntime/core/providers/cpu/math/einsum_utils/einsum_typed_compute_processor.cc | Fixed single-input reduction bug by changing from preserved_dims to all_dims, added validation check, improved comment |
| onnxruntime/test/providers/cpu/math/einsum_test.cc | Added test case for the reduce-with-transpose scenario that was previously failing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_typed_compute_processor.cc
Outdated
Show resolved
Hide resolved
…compute_processor.cc Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…compute_processor.cc Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…compute_processor.cc Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_typed_compute_processor.cc
Outdated
Show resolved
Hide resolved
…compute_processor.cc Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_typed_compute_processor.cc
Outdated
Show resolved
Hide resolved
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_typed_compute_processor.cc
Outdated
Show resolved
Hide resolved
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_typed_compute_processor.cc
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_compute_preprocessor.h
Show resolved
Hide resolved
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_typed_compute_processor.cc
Outdated
Show resolved
Hide resolved
…compute_processor.cc Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…runtime into hari/einsum_fix_1
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
When the lone operand had a reduction operation in Einsum, there was a mis-management in the shape which led to a mis-match in terms of the subscript indices in the output as deciphered from the Einsum equation and the rank of the candidate output being produced after the reduction operation which caused issues while finalizing the output of the Einsum op.
This change fixes the bug and adds a test
Motivation and Context
Resolve #18654