-
Couldn't load subscription status.
- Fork 25.7k
[package] Introduce BaseImporter to manage module namespace collisions. #51975
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
See comments in code. [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit 1bf3670 (more details on the Dr. CI page):
🕵️ 2 new failures recognized by patternsThe following CI failures do not appear to be due to upstream breakages:
|
…ollisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…ollisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…ollisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
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 have a bunch of somewhat disparate minor comments to try to clean up the API.
…ollisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…ollisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…ollisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…ollisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…e collisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…e collisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…e collisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…e collisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…e collisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…e collisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
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.
Cool! Just a couple minor things inline.
| ObjNotFoundError: we couldn't retrieve `obj by name. | ||
| ObjMisMatchError: we found a different object with the same name as `obj`. | ||
| """ | ||
| if name is None and obj and _Pickler.dispatch.get(type(obj)) is None: |
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.
Because this is the start of this function, and because it is only called in one place from our custom pickler, I think it should go in that function and not here. I can see this accidentally firing for weird objects in other places.
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.
Does that make sense or am I not understanding what the string version of reduce does?
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.
afaict we need this here, because __reduce__ -> str is one way that objects can signal that they want to be global'd as a different name than what the pickler might infer. I ran across this when trying to package references to typing.List and friends in FX.
We can put equivalent logic in the import string formatter in GraphModule, but it made more sense to put it here and leave clients of the code unaware of this detail.
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.
ok, I get it now. Given that definition of what it does, then it is in the right place.
| return importer.get_name(obj, name) | ||
| except ObjNotFoundError as err: | ||
| last_err = err | ||
|
|
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.
we don't need it for this patch, but if you catch a ObjMismatchError here, then you can keep looking for the object, and if you succeed, you can report that the earlier importer shadowed the importer that you needed.
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.
Yeah good idea. Right now we use the package mangling as an implementation detail to give a good message, but it would be better to do it without that knowledge.
…e collisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…e collisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…e collisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…e collisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…e collisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…e collisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…e collisions." See comments in code. Differential Revision: [D26340592](https://our.internmc.facebook.com/intern/diff/D26340592) [ghstack-poisoned]
…ytorch#51975) Summary: Pull Request resolved: pytorch#51975 See comments in code. Test Plan: Imported from OSS Reviewed By: zdevito Differential Revision: D26340592 Pulled By: suo fbshipit-source-id: 61b16bafad15e19060710ad2d8487c776d672847
…ytorch#51975) Summary: Pull Request resolved: pytorch#51975 See comments in code. Test Plan: Imported from OSS Reviewed By: zdevito Differential Revision: D26340592 Pulled By: suo fbshipit-source-id: 61b16bafad15e19060710ad2d8487c776d672847
…ytorch#51975) Summary: Pull Request resolved: pytorch#51975 See comments in code. Test Plan: Imported from OSS Reviewed By: zdevito Differential Revision: D26340592 Pulled By: suo fbshipit-source-id: 61b16bafad15e19060710ad2d8487c776d672847
Stack from ghstack:
See comments in code.
Differential Revision: D26340592