Giter Site home page Giter Site logo

Comments (3)

janeyx99 avatar janeyx99 commented on May 20, 2024

cc @jbschlosser

from pytorch.

jbschlosser avatar jbschlosser commented on May 20, 2024

From what I can tell, the __file__ attribute is only intended to be present on module objects and not type objects. For a type object, I think inspect.getfile(test_class_type) (which is used for the repro command) will check the __file__ attribute of the module referenced by the type's __module__ attribute.

For this particular example, the __module__ attribute is inherited from the parent class by the metaprogrammed class via dct:

return type(
orig_cls.__name__ + "WithCompiledAutograd",
orig_cls.__bases__,
dct,
)

This results in the wrong path being reported by the repro command.

>>> sys.modules[TestAutogradWithCompiledAutograd.__module__].__file__
'/home/jbschlosser/pytorch/test/test_autograd.py'
>>> inspect.getfile(TestAutogradWithCompiledAutograd)
'/home/jbschlosser/pytorch/test/test_autograd.py'

I'd suggest ensuring __module__ is correct for the metaprogrammed class, but idk if this is possible since the file it's defined in may not be related to a loaded module.

from pytorch.

ezyang avatar ezyang commented on May 20, 2024

Huh, I guess it checks __file__ anyway. Fixing __module__ should work. Using the original cls module seems like the ticket.

from pytorch.

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.