Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Updated: einops does not support torch.jit.script #165

Closed
ahatamiz opened this issue Jan 7, 2022 · 6 comments
Closed

[BUG] Updated: einops does not support torch.jit.script #165

ahatamiz opened this issue Jan 7, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@ahatamiz
Copy link

ahatamiz commented Jan 7, 2022

Updated
The original issue was closed, despite the fact that provided snippet still uses a module, as opposed to a function and tested with newer and older PyTorch versions. Opening the issue here in hope of restarting the conversation and finding possible solutions.

Describe the bug
The einops package does not support torch.jit.script. The following snippet tries a simple Rearrange operation, using a module to test this. It is observed that the operation is not supported.

Reproduction steps
The following snippet should illustrate a concise way of reproducing this issue:

import torch
import torch.nn as nn
from einops.layers.torch import Rearrange

class SimpleRearrange(nn.Module):
    def __init__(self):
        super().__init__()
        self.layer = nn.Sequential(Rearrange('b c h w -> b h w c'))
    
    def forward(self, x):
        result = self.layer(x)
        return result
    
net = SimpleRearrange()
net.eval()
with torch.no_grad():
    torch.jit.script(net)

Expected behavior
This is the expected output:
148459117-250414c0-3b85-46d1-a227-bcc92745efb1

Your platform
einops version: 0.3.2
Python version: 3.8.12
PyTorch version: 1.10.0
CUDA version: 10.2

@ahatamiz ahatamiz added the bug Something isn't working label Jan 7, 2022
@arogozhnikov
Copy link
Owner

arogozhnikov commented Jan 9, 2022

Hey, thanks for bringing up

This is strange, but I can't reproduce this on mac, and I can't reproduce this on linux.
There is also test in CI

model1 = create_torch_model(use_reduce=True, add_scripted_layer=script_layer)

I've tested 0.3.2 and my local master

I think following things should be checked:

  1. einops.__file__ and einops.einops.__file__ point to the right location
  2. verify that simple command is scriptable, like
torch.jit.script(Rearrange('b c h w -> b h w c'))
  1. I have observed previously strange behavior when torch.jit.script for some reason fails on the first run of scripting, but after catching exception and running the same command again, it succeeds. Please check if this is the case, like
try:
    torch.jit.script(net) # fails
except:
    torch.jit.script(net) # succeeds, while nothing has changed

@arogozhnikov
Copy link
Owner

I mean - your snippet ran successfully for me in all cases

@ahatamiz
Copy link
Author

Hi @arogozhnikov

Thanks for the reply. Again, I have tested the code snippet and getting the same error consistently. It would be great if this can be tested by another person.

@arogozhnikov
Copy link
Owner

added one more point to check to my previous comment ^

@ahatamiz
Copy link
Author

Hi @arogozhnikov

It seems that TorchScript support is made available in this commit which is not included in 0.3.2.

Considering this, would it be possible to release a new version and include it ?

Thanks again
Ali

@arogozhnikov
Copy link
Owner

Hi Ali, thanks for tracking this down. I've published a new version to pypi, it contains this commit, please try it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants