[Kernel] Fix einsum operator for empty inputs #27226
Merged
hariharans29 merged 12 commits intomainfrom Feb 5, 2026
Merged
Conversation
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>
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_typed_compute_processor.cc
Outdated
Show resolved
Hide resolved
onnxruntime/core/providers/cuda/math/einsum_utils/einsum_auxiliary_ops.cc
Outdated
Show resolved
Hide resolved
…iary_ops.cc Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…runtime into hari/einsum_fix_3
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a segmentation fault in the einsum operator when handling empty input tensors. The fix implements an early return path that detects empty inputs and zero-fills the output tensor, avoiding the crash that occurred when the main computation path attempted to process empty tensors.
Changes:
- Added
Zeroingdevice helper functions for CPU and CUDA providers to zero-fill tensor buffers - Implemented empty input detection logic in the einsum compute processor
- Added 5 comprehensive test cases covering various empty input scenarios (outer product, transpose, vanishing dimensions in 2D and 3D)
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
onnxruntime/test/providers/cpu/math/einsum_test.cc |
Added 5 test cases for empty input scenarios with expected outputs |
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_auxiliary_ops.h |
Added Zeroing function declaration for CPU provider |
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_auxiliary_ops.cc |
Implemented CPU Zeroing function using memset |
onnxruntime/core/providers/cuda/math/einsum_utils/einsum_auxiliary_ops.h |
Added Zeroing function declaration for CUDA provider |
onnxruntime/core/providers/cuda/math/einsum_utils/einsum_auxiliary_ops.cc |
Implemented CUDA Zeroing function using cudaMemsetAsync |
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_typed_compute_processor.h |
Added zero_input_buffer_func_ member and updated SetDeviceHelpers signature |
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_typed_compute_processor.cc |
Implemented empty input detection and early return logic |
onnxruntime/core/providers/cpu/math/einsum.cc |
Updated SetDeviceHelpers calls to include Zeroing function |
onnxruntime/core/providers/cuda/math/einsum.cc |
Updated SetDeviceHelpers calls to include Zeroing function |
onnxruntime/core/providers/cpu/cpu_provider_shared.h |
Updated shared provider interface with Zeroing parameter |
onnxruntime/core/providers/cpu/cpu_provider_shared.cc |
Updated shared provider implementation with Zeroing parameter |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
edgchen1
previously approved these changes
Feb 5, 2026
onnxruntime/core/providers/cpu/math/einsum_utils/einsum_typed_compute_processor.cc
Outdated
Show resolved
Hide resolved
edgchen1
approved these changes
Feb 5, 2026
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.
Description
Dupe of #23379 - opening new PR to debug pending build issues before merging
Motivation and Context
Fix Einsum handling of empty inputs
Bug identification credit: @neNasko1