Giter Club home page Giter Club logo

Comments (6)

arogozhnikov avatar arogozhnikov commented on June 8, 2024 1

Hi @befelix , thank you for reporting, there is a circular import problem that we need to address.

step-by-step what happens in python -W "error" -c 'import einops; import torch._dynamo'

  1. einops is imported
  2. torch._dynamo is imported, it detects that einops is imported, and calls https://github.com/pytorch/pytorch/blob/88a71594933b2464d9d8b6b3533c5a945a4ac2ff/torch/_dynamo/decorators.py#L322
  3. ... which imports from einops._torch_specific ...
  4. einops._torch_specific tries to register ops by using allow_in_graph, that is needs to import first from torch._dynamo. That's where we run in circular imports

cc @wconstab @jansel

from einops.

arogozhnikov avatar arogozhnikov commented on June 8, 2024

Seems this torch PR was trying to address the problem, but that didn't quite work:
https://github.com/pytorch/pytorch/pull/111835/files

Fix wouldn't work it seems: einops needs allow_in_graph being importable, meaning that hook can only be called after _dynamo was imported. Currently hook is called during the import.

from einops.

jansel avatar jansel commented on June 8, 2024

Should we delete the special einops handling from torch._dynamo?

from einops.

arogozhnikov avatar arogozhnikov commented on June 8, 2024

it is preferrable to defer that logic to 'on first compile' (or when torch._dynamo is fully imported)

Otherwise, we better just delete that handling code - it wouldn't work as intended

from einops.

jansel avatar jansel commented on June 8, 2024

Can you check if this fixes it: pytorch/pytorch#124084

from einops.

arogozhnikov avatar arogozhnikov commented on June 8, 2024

Thank you @jansel for merging that. I can confirm nightly torch==2.4.0.dev20240420+cpu does not have this issue.

Before fix comes live users need to use manual registration of functions:
https://github.com/arogozhnikov/einops/wiki/Using-torch.compile-with-einops

from einops.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.