Skip to content

[Kernel] Fix einsum operator for empty inputs #27226

Merged
hariharans29 merged 12 commits intomainfrom
hari/einsum_fix_3
Feb 5, 2026
Merged

[Kernel] Fix einsum operator for empty inputs #27226
hariharans29 merged 12 commits intomainfrom
hari/einsum_fix_3

Conversation

@hariharans29
Copy link
Member

@hariharans29 hariharans29 commented Feb 3, 2026

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

@hariharans29 hariharans29 changed the title WIP: Dupe of #23379 Fix einsum operator for empty inputs Feb 3, 2026
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit the suggested changes from lintrunner.

hariharans29 and others added 3 commits February 2, 2026 20:38
…compute_processor.cc

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit the suggested changes from lintrunner.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit the suggested changes from lintrunner.

hariharans29 and others added 3 commits February 3, 2026 11:00
…iary_ops.cc

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@hariharans29 hariharans29 changed the title Fix einsum operator for empty inputs [Kernel] Fix einsum operator for empty inputs Feb 4, 2026
Copy link
Contributor

Copilot AI left a comment

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 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 Zeroing device 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
edgchen1 previously approved these changes Feb 5, 2026
@hariharans29 hariharans29 merged commit 46b587c into main Feb 5, 2026
90 checks passed
@hariharans29 hariharans29 deleted the hari/einsum_fix_3 branch February 5, 2026 23:05
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.

2 participants