-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add Slot type to abstract the raw pointers being used for slots. #18226
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
Conversation
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.
return slot_ == rhs.slot_; | ||
} | ||
private: | ||
at::IValue* slot_; |
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.
an enclosed IValue
always outlives its Slot
?
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.
The IValue* lives as long as the module is alive.
} | ||
private: | ||
at::IValue* slot_; | ||
friend struct std::hash<Slot>; |
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.
I don't know if return std::hash<at::IValue*>{}(&(*s.slot_));
is any better than declaring a friend.
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.
: This particular implementation will only live until a later diff in this stack merges Slot and NamedIValue, so I will keep it as is for now.
IValue* slot() const { | ||
return ivalue.get(); | ||
Slot slot() const { | ||
return Slot(ivalue_.get()); |
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.
Oh, I see now, the lifetimes of IValue
and Slot
are the same unless someone creates the Slot
outside of a NamedValue
. Would it make sense to make Slot
c-tor private, so only NamedValue
s can create Slot
s?
This pull request has been merged in aa20591. |
Summary: Pull Request resolved: #18314 ghimport-source-id: 8cecb76 Stack from [ghstack](https://github.com/ezyang/ghstack): * **#18314 Add ability to specialize class types to ArgumentSpec** * #18226 Add Slot type to abstract the raw pointers being used for slots. Differential Revision: D14574395 fbshipit-source-id: cc3af6e56e9ae52990f4a1ad56ecceaa2d493577
Summary: Pull Request resolved: #18378 ghimport-source-id: 55c29bb Stack from [ghstack](https://github.com/ezyang/ghstack): * #18379 Enforce single parent for script submodules * **#18378 Unify namespace of script::Module** * #18314 Add ability to specialize class types to ArgumentSpec * #18226 Add Slot type to abstract the raw pointers being used for slots. This removes individual OrderedDicts in favor of a single unified namespace for all things in a script::Module. This removes a whole class of bugs where both a method and an parameter could get the same name, for instance. Since we no longer have to expose OrderedDict::Item objects, a lot of downstream code can be simplified. We no longer now double-store names (both in the key of the dictionary, and in the object itself). Differential Revision: D14603723 fbshipit-source-id: b5f7551b3074679623edd6ea70269830353b4d4c
Summary: Pull Request resolved: #18379 ghimport-source-id: 9895ecc Stack from [ghstack](https://github.com/ezyang/ghstack): * **#18379 Enforce single parent for script submodules** * #18378 Unify namespace of script::Module * #18314 Add ability to specialize class types to ArgumentSpec * #18226 Add Slot type to abstract the raw pointers being used for slots. The assumption that a ScriptModule has a single parent is present in our serialization format, and likely a few other places. It is not enforced on creation of script module hierarchies though, meaning that problems associated with (e.g. replicating a module twice in the output format) will not be caught until much later in the development cycle. This patch enforces the property when a submodule is registered. It also removes NamedModule since it is no longer necessary in this regime. This will also allow the easy discover of a modules fully-qualified name without needing to traverse the Module hierarchy. Differential Revision: D14603722 fbshipit-source-id: 63ab5d0cccf7d66c7833e0adf9023024ca9607cb
Summary: Pull Request resolved: #18467 ghimport-source-id: d51bdd6 Stack from [ghstack](https://github.com/ezyang/ghstack): * #18469 Create Object that represents a Module * #18468 slots with explicit value/setValue make more sense in future patches * **#18467 Make Object hold its ClassType** * #18379 Enforce single parent for script submodules * #18378 Unify namespace of script::Module * #18314 Add ability to specialize class types to ArgumentSpec * #18226 Add Slot type to abstract the raw pointers being used for slots. Currently it holds a symbol whose unqualified name is the name of the class. This will get confusing when there are multiple possible registries, and it makes getting the class type from the object difficult. The pointer to the class is only 4 more bytes so this patch just puts it in the object. Reviewed By: suo Differential Revision: D14613510 fbshipit-source-id: b35175ba4be83d2522deaa6dad5070d6ec691fed
…18468) Summary: Pull Request resolved: #18468 ghimport-source-id: d4b41c5 Stack from [ghstack](https://github.com/ezyang/ghstack): * #18469 Create Object that represents a Module * **#18468 slots with explicit value/setValue make more sense in future patches** * #18467 Make Object hold its ClassType * #18379 Enforce single parent for script submodules * #18378 Unify namespace of script::Module * #18314 Add ability to specialize class types to ArgumentSpec * #18226 Add Slot type to abstract the raw pointers being used for slots. Reviewed By: suo Differential Revision: D14613509 fbshipit-source-id: 9f2208d0efd01465c78cebdc3e8365a9e0adf9ff
Summary: Pull Request resolved: #18469 ghimport-source-id: 73cb8b5 Stack from [ghstack](https://github.com/ezyang/ghstack): * **#18469 Create Object that represents a Module** * #18468 slots with explicit value/setValue make more sense in future patches * #18467 Make Object hold its ClassType * #18379 Enforce single parent for script submodules * #18378 Unify namespace of script::Module * #18314 Add ability to specialize class types to ArgumentSpec * #18226 Add Slot type to abstract the raw pointers being used for slots. This changes the underlying storage for script::Module to hold a ivalue::Object which has slots for all the parameters and attributes. NamedIValue and Slot are now merged together into one class Slot that stores the tuple (ivalue::Object, offset) and can be used to read the name, type, or value of the slot and also to set the value. This cleans up a bunch of client uses. This PR does not actually use the module object in any generated code. A future PR will switch how code is generated to treat modules as first class. Differential Revision: D14613508 fbshipit-source-id: d853a7559f58d244de2ef54a781427fcd1060ed0
Summary: Pull Request resolved: pytorch#18467 ghimport-source-id: d51bdd6 Stack from [ghstack](https://github.com/ezyang/ghstack): * pytorch#18469 Create Object that represents a Module * pytorch#18468 slots with explicit value/setValue make more sense in future patches * **pytorch#18467 Make Object hold its ClassType** * pytorch#18379 Enforce single parent for script submodules * pytorch#18378 Unify namespace of script::Module * pytorch#18314 Add ability to specialize class types to ArgumentSpec * pytorch#18226 Add Slot type to abstract the raw pointers being used for slots. Currently it holds a symbol whose unqualified name is the name of the class. This will get confusing when there are multiple possible registries, and it makes getting the class type from the object difficult. The pointer to the class is only 4 more bytes so this patch just puts it in the object. Reviewed By: suo Differential Revision: D14613510 fbshipit-source-id: b35175ba4be83d2522deaa6dad5070d6ec691fed
…ytorch#18468) Summary: Pull Request resolved: pytorch#18468 ghimport-source-id: d4b41c5 Stack from [ghstack](https://github.com/ezyang/ghstack): * pytorch#18469 Create Object that represents a Module * **pytorch#18468 slots with explicit value/setValue make more sense in future patches** * pytorch#18467 Make Object hold its ClassType * pytorch#18379 Enforce single parent for script submodules * pytorch#18378 Unify namespace of script::Module * pytorch#18314 Add ability to specialize class types to ArgumentSpec * pytorch#18226 Add Slot type to abstract the raw pointers being used for slots. Reviewed By: suo Differential Revision: D14613509 fbshipit-source-id: 9f2208d0efd01465c78cebdc3e8365a9e0adf9ff
Summary: Pull Request resolved: pytorch#18469 ghimport-source-id: 73cb8b5 Stack from [ghstack](https://github.com/ezyang/ghstack): * **pytorch#18469 Create Object that represents a Module** * pytorch#18468 slots with explicit value/setValue make more sense in future patches * pytorch#18467 Make Object hold its ClassType * pytorch#18379 Enforce single parent for script submodules * pytorch#18378 Unify namespace of script::Module * pytorch#18314 Add ability to specialize class types to ArgumentSpec * pytorch#18226 Add Slot type to abstract the raw pointers being used for slots. This changes the underlying storage for script::Module to hold a ivalue::Object which has slots for all the parameters and attributes. NamedIValue and Slot are now merged together into one class Slot that stores the tuple (ivalue::Object, offset) and can be used to read the name, type, or value of the slot and also to set the value. This cleans up a bunch of client uses. This PR does not actually use the module object in any generated code. A future PR will switch how code is generated to treat modules as first class. Differential Revision: D14613508 fbshipit-source-id: d853a7559f58d244de2ef54a781427fcd1060ed0
If modules become first-class IValues, then the slots will no longer be raw pointers but (IValue, index) pairs. This commit inserts the Slot abstraction so that this change can be made in later patches.
Stack from ghstack:
Differential Revision: D14542022