question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

einops does not support torch.jit.script ?

See original GitHub issue

Describe the bug Thanks for this great work. In recent updates, it is mentioned that einops supports torch.jit.script for PyTorch layers. I and @yiheng-wang-nv have been looking into this to support TorchScript for a number of models. However, we are not able to utilize this functionality for simple operations such as Rearrange.

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:

check einops

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

Based on this, I believe einops does not support torch.jit.script, unless we are missing something. Appreciate your inputs here.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alexfanqicommented, Aug 23, 2022

@arogozhnikov Thanks for the kind tips. My mind was not in a proper state yesterday. The bug is indeed fixed in another issue. It is now so embarrassing to recall my moment yesterday.

0reactions
arogozhnikovcommented, Aug 22, 2022

Also regarding this deleted comment:

It seems I am able to work around the issue by decorating TransformRecipe with torch.jit.script. But I have no idea how to incorporate this into einops.

@torch.jit.script
class TransformRecipe:

If that is true (again, strange, as torch should do that for you), you should be able to use hot-patching:

from einops import einops as _einops
_einops.TransformRecipe = torch.jit.script(_einops.TransformRecipe)
Read more comments on GitHub >

github_iconTop Results From Across the Web

PyTorch jit.script interoperability #115 - arogozhnikov/einops
I'm not sure if this is the expected behavior, but not being able to script modules that use einops would be very unfortunate....
Read more >
TorchScript Unsupported Pytorch Constructs
Below are listed the modules that TorchScript does not support, and an incomplete list of PyTorch classes that are not supported. For unsupported...
Read more >
Deep Learning Operations Reinvented for Tensorflow & Pytorch
In this tutorial, we will share a repository of Einops: Deep learning ... torch.jit.script is supported for pytorch layers; powerful EinMix added to...
Read more >
Pytorch - Dan MacKinlay
Of course the overhead is not truly zero; rather they have shifted the user ... use @torch.jit.script , e.g. esp to fuse long...
Read more >
Logits Ensemble : Transformer - Kaggle
It supports both of shifted and non-shifted window. ... x): for blk in self.blocks: if not torch.jit.is_scripting() and self.use_checkpoint: x ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found