Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Einsum error msg improvement#2690

Merged
awni merged 4 commits intoml-explore:mainfrom
Maalvi14:2677-einsum-error-msg-improvement
Oct 27, 2025
Merged

Einsum error msg improvement#2690
awni merged 4 commits intoml-explore:mainfrom
Maalvi14:2677-einsum-error-msg-improvement

Conversation

@Maalvi14
Copy link
Contributor

@Maalvi14 Maalvi14 commented Oct 21, 2025

Proposed changes

Modified the error message logic of einsum() mentioned on #2677 to clearly identify which operand is problematic, show its shape and the specific subscript pattern that's causing the issue.

import mlx.core as mx
y = mx.ones((6, 10))
x = mx.ones((6,))
mx.einsum("...i,ij->...j", x[0], y)

New Error Message

Traceback (most recent call last):
  File "/Users/mv/repos/mlx/einsum_test.py", line 4, in <module>
    mx.einsum("...i,ij->...j", x[0], y)
ValueError: [einsum] Operand 0 with shape {} has insufficient dimensions for subscript '...i'.
The ellipsis requires at least 1 dimensions but the operand has 0 dimensions.

Example on the same error in PyTorch:
einsum(): the number of subscripts in the equation (1) is more than the number of dimensions (0) for operand 0

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works -> Not necessary
  • I have updated the necessary documentation (if needed) -> Not necessary

@Maalvi14
Copy link
Contributor Author

@awni noticed usually you have to change some of the format on my PRs, and I think that's caused by pre-commit run --all-files before I submit, don't know if you or other are experiencing the same situation.

@awni awni force-pushed the 2677-einsum-error-msg-improvement branch from 24e063c to 3752c12 Compare October 24, 2025 16:49
@awni
Copy link
Member

awni commented Oct 24, 2025

Maybe try running pre-commit install?

Copy link
Member

@awni awni left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@awni awni merged commit 0cfeeb6 into ml-explore:main Oct 27, 2025
7 checks passed
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