-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[jit] fix @property #28395
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
[jit] fix @property #28395
Conversation
Currently `@property` methods are broken in TorchScript because we basically treat it as an attribute in the existing path: we'll evaluate the method once and store that as the value forever. This PR fixes it so that `@property` actually behaves correctly: 1. Added `properties` as part of `ConcreteModuleType`. 2. Added a `PropertyValue` `SugaredValue` that behaves exactly like a method but it can be used as a value. 3. `ModuleValue::attr` now checks wheter a method is a property, and returns a `PropertyValue` if so. This approach has the disadvantage of making `ModuleValue` more special. But it has the advantage of not leaking the concept of properties deeper into the type system.
Currently `@property` methods are broken in TorchScript because we basically treat it as an attribute in the existing path: we'll evaluate the method once and store that as the value forever. This PR fixes it so that `@property` actually behaves correctly: 1. Added `properties` as part of `ConcreteModuleType`. 2. Added a `PropertyValue` `SugaredValue` that behaves exactly like a method but it can be used as a value. 3. `ModuleValue::attr` now checks wheter a method is a property, and returns a `PropertyValue` if so. This approach has the disadvantage of making `ModuleValue` more special. But it has the advantage of not leaking the concept of properties deeper into the type system. ghstack-source-id: a13523d Pull Request resolved: #28395
Currently `@property` methods are broken in TorchScript because we basically treat it as an attribute in the existing path: we'll evaluate the method once and store that as the value forever. This PR fixes it so that `@property` actually behaves correctly: 1. Added `properties` as part of `ConcreteModuleType`. 2. Added a `PropertyValue` `SugaredValue` that behaves exactly like a method but it can be used as a value. 3. `ModuleValue::attr` now checks wheter a method is a property, and returns a `PropertyValue` if so. This approach has the disadvantage of making `ModuleValue` more special. But it has the advantage of not leaking the concept of properties deeper into the type system. Differential Revision: [D18054946](https://our.internmc.facebook.com/intern/diff/D18054946)
Currently `@property` methods are broken in TorchScript because we basically treat it as an attribute in the existing path: we'll evaluate the method once and store that as the value forever. This PR fixes it so that `@property` actually behaves correctly: 1. Added `properties` as part of `ConcreteModuleType`. 2. Added a `PropertyValue` `SugaredValue` that behaves exactly like a method but it can be used as a value. 3. `ModuleValue::attr` now checks wheter a method is a property, and returns a `PropertyValue` if so. This approach has the disadvantage of making `ModuleValue` more special. But it has the advantage of not leaking the concept of properties deeper into the type system. Differential Revision: [D18054946](https://our.internmc.facebook.com/intern/diff/D18054946)
Currently `@property` methods are broken in TorchScript because we basically treat it as an attribute in the existing path: we'll evaluate the method once and store that as the value forever. This PR fixes it so that `@property` actually behaves correctly: 1. Added `properties` as part of `ConcreteModuleType`. 2. Added a `PropertyValue` `SugaredValue` that behaves exactly like a method but it can be used as a value. 3. `ModuleValue::attr` now checks wheter a method is a property, and returns a `PropertyValue` if so. This approach has the disadvantage of making `ModuleValue` more special. But it has the advantage of not leaking the concept of properties deeper into the type system. Differential Revision: [D18054946](https://our.internmc.facebook.com/intern/diff/D18054946)
Currently `@property` methods are broken in TorchScript because we basically treat it as an attribute in the existing path: we'll evaluate the method once and store that as the value forever. Since lack of `@property` support is easily worked around (just make it a method), I've opted to just explicitly error to avoid confusion. If people want it, they can file an issue and we can look at their use case. This also helps us nicely clean up some parts of the ScriptModule conversion path. ghstack-source-id: d318663 Pull Request resolved: #28395
torch/jit/_recursive.py
Outdated
| # original function => [(mangled overload name, overload function)] | ||
| overloads = {} | ||
|
|
||
| # TODO: should this be dir(type(mod))? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably?
Currently `@property` methods are broken in TorchScript because we basically treat it as an attribute in the existing path: we'll evaluate the method once and store that as the value forever. Since lack of `@property` support is easily worked around (just make it a method), I've opted to just explicitly error to avoid confusion. If people want it, they can file an issue and we can look at their use case. This also helps us nicely clean up some parts of the ScriptModule conversion path. Pull Request resolved: #28395 Differential Revision: [D18054946](https://our.internmc.facebook.com/intern/diff/D18054946)
Currently `@property` methods are broken in TorchScript because we basically treat it as an attribute in the existing path: we'll evaluate the method once and store that as the value forever. Since lack of `@property` support is easily worked around (just make it a method), I've opted to just explicitly error to avoid confusion. If people want it, they can file an issue and we can look at their use case. This also helps us nicely clean up some parts of the ScriptModule conversion path. Pull Request resolved: #28395 Differential Revision: [D18054946](https://our.internmc.facebook.com/intern/diff/D18054946)
CircleCI build failures summaryAs of commit 2fe2634:
Here are the reasons each build failed. This comment was automatically generated by Dr. CI. Please report bugs/suggestions on the GitHub issue tracker. This comment has been revised 3 time(s). |
Currently `@property` methods are broken in TorchScript because we basically treat it as an attribute in the existing path: we'll evaluate the method once and store that as the value forever. Since lack of `@property` support is easily worked around (just make it a method), I've opted to just explicitly error to avoid confusion. If people want it, they can file an issue and we can look at their use case. This also helps us nicely clean up some parts of the ScriptModule conversion path. Pull Request resolved: #28395 Differential Revision: [D18054946](https://our.internmc.facebook.com/intern/diff/D18054946)
Currently `@property` methods are broken in TorchScript because we basically treat it as an attribute in the existing path: we'll evaluate the method once and store that as the value forever. Since lack of `@property` support is easily worked around (just make it a method), I've opted to just explicitly error to avoid confusion. If people want it, they can file an issue and we can look at their use case. This also helps us nicely clean up some parts of the ScriptModule conversion path. Pull Request resolved: #28395 Differential Revision: [D18054946](https://our.internmc.facebook.com/intern/diff/D18054946)
Currently `@property` methods are broken in TorchScript because we basically treat it as an attribute in the existing path: we'll evaluate the method once and store that as the value forever. Since lack of `@property` support is easily worked around (just make it a method), I've opted to just explicitly error to avoid confusion. If people want it, they can file an issue and we can look at their use case. This also helps us nicely clean up some parts of the ScriptModule conversion path. Pull Request resolved: #28395 Differential Revision: [D18054946](https://our.internmc.facebook.com/intern/diff/D18054946)
Currently `@property` methods are broken in TorchScript because we basically treat it as an attribute in the existing path: we'll evaluate the method once and store that as the value forever. Since lack of `@property` support is easily worked around (just make it a method), I've opted to just explicitly error to avoid confusion. If people want it, they can file an issue and we can look at their use case. This also helps us nicely clean up some parts of the ScriptModule conversion path. Pull Request resolved: #28395 Differential Revision: [D18054946](https://our.internmc.facebook.com/intern/diff/D18054946)
Currently `@property` methods are broken in TorchScript because we basically treat it as an attribute in the existing path: we'll evaluate the method once and store that as the value forever. Since lack of `@property` support is easily worked around (just make it a method), I've opted to just explicitly error to avoid confusion. If people want it, they can file an issue and we can look at their use case. This also helps us nicely clean up some parts of the ScriptModule conversion path. ghstack-source-id: 7ea6dab Pull Request resolved: #28395
Stack from ghstack:
Currently
@propertymethods are broken in TorchScript because webasically treat it as an attribute in the existing path: we'll evaluate
the method once and store that as the value forever.
Since lack of
@propertysupport is easily worked around (just make ita method), I've opted to just explicitly error to avoid confusion. If
people want it, they can file an issue and we can look at their use
case.
This also helps us nicely clean up some parts of the ScriptModule conversion
path.
Pull Request resolved: #28395
Differential Revision: D18054946