Skip to content

Add codemod for TorchNonPublicAliasVisitor #36

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

Merged
merged 3 commits into from
Mar 19, 2024

Conversation

kit1980
Copy link
Contributor

@kit1980 kit1980 commented Mar 18, 2024

This is a continuation of #33

We want to update non-public function calls to public aliases, possibly adding or modifying imports in the process.
The call sites needs to be updated to the same hierarchical level as in the existent code (as much as possible):
collate.default_collate() -> dataloader.default_collate(), but torch.utils.data._utils.collate.default_convert() -> torch.utils.data.dataloader.default_convert().

See the tests for different cases.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 18, 2024
@kit1980 kit1980 marked this pull request as ready for review March 18, 2024 23:08
@seemethere
Copy link
Contributor

seemethere commented Mar 18, 2024

Is my understanding correct here that this basically searches recursively down the node tree for a function with the same name that exists in a public package and then attempts to replace the private function with that new public function?

Might also be good to add a description to the PR / a comment to the code as well to explain some of this logic since it's somewhat hard to grok quickly from reading the code.

@kit1980
Copy link
Contributor Author

kit1980 commented Mar 18, 2024

Is my understanding correct here that this basically searches recursively down the node tree for a function with the same name that exists in a public package and then attempts to replace the private function with that new public function?

There is no recursion.
There is a mapping "non-public" -> "public" defined here https://github.com/pytorch-labs/torchfix/blob/main/torchfix/visitors/nonpublic/__init__.py#L21

A somewhat tricky part is that for example _utils.collate.default_collate() needs to be updated to dataloader.default_collate() and then a new import needs to be added. And in other cases imports need to be modified, and maybe call site needed to be leave as is: see the tests.

@kit1980 kit1980 merged commit c909236 into main Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants