-
Notifications
You must be signed in to change notification settings - Fork 24.3k
[dynamo][not ready] polyfill infra for classes #146678
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ed39b4a
[dynamo][not ready] polyfill infra for classes
anijain2305 0103e2e
Update on "[dynamo][not ready] polyfill infra for classes"
anijain2305 1730aed
Update on "[dynamo][not ready] polyfill infra for classes"
anijain2305 5c005d6
Update on "[dynamo][not ready] polyfill infra for classes"
anijain2305 2414be8
Update on "[dynamo][not ready] polyfill infra for classes"
anijain2305 0bde592
Update on "[dynamo][not ready] polyfill infra for classes"
anijain2305 198dd8c
Update on "[dynamo][not ready] polyfill infra for classes"
anijain2305 6eaf290
Update on "[dynamo][not ready] polyfill infra for classes"
anijain2305 f770084
Update on "[dynamo][not ready] polyfill infra for classes"
anijain2305 7bd428d
Update on "[dynamo][not ready] polyfill infra for classes"
anijain2305 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Can't we use closure to implement class-like objects?
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.
In the case of
partial
, it could be ok. But, I am thinking in terms of more complicated C classes that have many methods. We can still use closure and add method names as attributes to the returned function object. But, I think its more intuitive for the user to have one-to-one mapping for their C++ class to Python class.Another discussion point (which is not a class vs closure discussion) is how to reconstruct the value. For example, in your above example, if we want to reconstruct the
partial
object, it will be of type function (and notfunctools.partial
). This causes silent correctness issues because the following code could depend on the returned obj being of typefunctools.partial
. This is not a class vs closure issue though.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 C++ pytree functions can return a C++ object
PyTreeSpec
. The pytree polyfills return a Python object with analog methods while settingcan_constant_fold_through=False
.See also:
pytorch/torch/_dynamo/polyfills/pytree.py
Lines 119 to 121 in 91c4bf3
pytorch/torch/_dynamo/polyfills/pytree.py
Lines 322 to 334 in 91c4bf3
Uh oh!
There was an error while loading. Please reload this page.
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.
For
functools.partial
:One drawback for polyfills is the
isinstance(...)
andissubclass(...)
checks for polyfilled instances. Neither function-polyfill-with-closure or class-polyfill can resolve this issue elegantly. We also need to provide polyfilledis_partial_instance
functions.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.
These are really good pointers. I think it makes sense to just polyfill
functools.partial.__new__
and provide a helper to convert the already created functools.partial objects to polyfill'd partial objects.Let me think more about the reconstruction part.