einops
einops copied to clipboard
einops.layers.torch.Rearrange does not accept a list[torch.Tensor] as an input
Describe the bug
einops.layers.torch.Rearrange
and einops.rearrange
behave differently with list[torch.Tensor]
.
It is possible to use rearrange
for concatenation, while Rearrange
fails with error:
einops/_torch_specific.py:66, in TorchJitBackend.shape(x) 64 @staticmethod 65 def shape(x): ---> 66 return x.shape AttributeError: 'list' object has no attribute 'shape'
Reproduction steps
import torch
from einops import rearrange
from einops.layers.torch import Rearrange
layer = Rearrange('num b c h w -> b (num c) h w', num=2)
func = lambda x: rearrange(x, 'num b c h w -> b (num c) h w', num=2)
t1 = torch.randn((1, 3, 16, 24))
t2 = torch.rand((1, 3, 16, 24))
y = func([w1, w2]) # OK
y = layer([w1, w2]) # AttributeError: 'list' object has no attribute 'shape'
Expected behavior Expect the same behavior in both cases (hopefully correct operation execution, not raise exception)
Your platform python==3.10.12 torch==2.0.1 einops==0.6.1
Yup, that's how it was supposed to work. Nobody asked for support of lists in layers ... yet :)