`einsum` can't sum ellipsis axes
See original GitHub issueDescription
In numpy, when optimized is set to True, einsum can sum ellipses (…). However, it seems cupy einsum doesn’t have an optimized parameter, and it can’t sum ellipses.
To Reproduce
an einsum
calculation in Numpy behaves as expected:
import numpy as xp
grad=xp.random.randn(5,2,8)
x=xp.random.randn(5,2,8)
y=xp.einsum('...j,...k->jk', grad, x, optimize=True)
print(y.shape) # --> (8, 8)
However, in Cupy it produces error:
import cupy as xp
grad=xp.random.randn(5,2,8)
x=xp.random.randn(5,2,8)
y=xp.einsum('...j,...k->jk', grad, x, optimize=True)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_15756/3125293176.py in <module>
2 grad=xp.random.randn(5,2,8)
3 x=xp.random.randn(5,2,8)
----> 4 y=xp.einsum('...j,...k->jk', grad, x, optimize=True)
~\anaconda3\lib\site-packages\cupy\linalg\_einsum.py in einsum(*operands, **kwargs)
527 if not options['sum_ellipsis']:
528 if '@' not in output_subscript and -1 in dimension_dict:
--> 529 raise ValueError(
530 'output has more dimensions than subscripts '
531 'given in einstein sum, but no \'...\' ellipsis '
ValueError: output has more dimensions than subscripts given in einstein sum, but no '...' ellipsis provided to broadcast the extra dimensions.
Installation
Wheel (pip install cupy-***
)
Environment
OS : Windows-10-10.0.19044-SP0
Python Version : 3.9.7
CuPy Version : 10.3.1
CuPy Platform : NVIDIA CUDA
NumPy Version : 1.22.3
SciPy Version : 1.7.1
Cython Build Version : 0.29.28
Cython Runtime Version : 0.29.24
CUDA Root : C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5
nvcc PATH : C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\bin\nvcc.EXE
CUDA Build Version : 11050
CUDA Driver Version : 11050
CUDA Runtime Version : 11030
cuBLAS Version : (available)
cuFFT Version : 10402
cuRAND Version : 10204
cuSOLVER Version : (11, 1, 1)
cuSPARSE Version : (available)
NVRTC Version : (11, 3)
Thrust Version : 101301
CUB Build Version : 101301
Jitify Build Version : 4a37de0
cuDNN Build Version : 8302
cuDNN Version : 8200
NCCL Build Version : None
NCCL Runtime Version : None
cuTENSOR Version : None
cuSPARSELt Build Version : None
Device 0 Name : NVIDIA GeForce GTX 965M
Device 0 Compute Capability : 52
Device 0 PCI Bus ID : 0000:01:00.0
Additional Information
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top Results From Across the Web
einsum with ellipses "..." (indefinite number of axes) #5443
The documentation for einsum says to look at the numpy documentation as it provides the same api. It is not exactly the same,...
Read more >Ellipsis broadcasting in numpy.einsum - Stack Overflow
It's while constructing op_axes for the nditer that einsum raises this error. I don't know if the test criteria is too tight (...
Read more >A basic introduction to NumPy's einsum - ajcr
sum this new array along particular axes, and/or; transpose the axes of the array in a particular order. Then there's a good chance...
Read more >core/tests/test_einsum.py · aaronreidsmith/numpy - Gemfury
a, optimize=do_opt) assert_(b.base is a) b = np.einsum(a, [Ellipsis], ... np.sum(a, axis=0).astype(dtype)) assert_equal(np.einsum(a, [0, Ellipsis], ...
Read more >Einstein Summation Convention - HE Tao
The rules of numpy.einsum can be summarized as: Repeating subscript between input arrays means that values along those axes will be multiplied.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I left
'sum_ellipsis'
in order to see how https://github.com/numpy/numpy/issues/10926 would be resolved.Now it might be better allowing to sum over ellipsis axes regardless of the
optimize
option becauseoptimize
for CuPy (GPU) should be the same as NumPy.Well… sure… There are many ways to do the same math problem right? 😉 If the goal here is to stay within
einsum
as much as possible, perhaps you can also do this:at the cost of storing a lager intermediate array (
y
).