Skip to content
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

[TorchFix] Add TorchVision pretrained codemod #4559

Merged
merged 2 commits into from
Sep 8, 2023

Conversation

kit1980
Copy link
Member

@kit1980 kit1980 commented Sep 8, 2023

For TorchVision models, pretrained and pretrained_backbone parameters have been deprecated in favor of "Multi-weight support API" - see https://pytorch.org/vision/0.15/models.html

This PR adds a checker/codemod for the deprecated parameters. As the new weights values needs to be imported first, this PR adds a generic mechanism to collect all needed imports and apply them after all local changes.

Also updated version to "0.0.3" as TorchFix 0.0.2 was released recently and this will be eventually released as 0.0.3

@vercel
Copy link

vercel bot commented Sep 8, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
torchci ⬜️ Ignored (Inspect) Visit Preview Sep 8, 2023 0:26am

@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 Sep 8, 2023
@kit1980 kit1980 marked this pull request as ready for review September 8, 2023 00:14
@kit1980 kit1980 requested review from NicolasHug and a team September 8, 2023 00:17
Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @kit1980 , this will be super useful to update other projects' codebases and ultimately get rid of those deprecations for good!

Tagging @pmeier as discussed offline who will take over from me as I'll be on PTO next.

torchvision.models.resnet50(pretrained=False)
torchvision.models.resnet50(False)
torchvision.models.detection.ssdlite320_mobilenet_v3_large(pretrained_backbone=True)
torchvision.models.detection.ssdlite320_mobilenet_v3_large(pretrained=True, pretrained_backbone=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also add a test entry for resnet_fpn_backbone and also one of the quantization models, e.g. resnet_18?

For these we can't really suggest a weight replacement because it can only be determined at runtime, but maybe we can still show a LintViolation?

IIUC you already handled all of that properly, I just want to confirm through a test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now quantization models are not supported - nothing will happen.
I was thinking on dealing with that in a follow-up PR as this one is already large.

resnet_fpn_backbone also not included currently. Do you think it's OK to put this in the follow-up PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is fine.

@kit1980 kit1980 merged commit a0e9138 into main Sep 8, 2023
6 checks passed
kit1980 added a commit that referenced this pull request Sep 11, 2023
… codemod (#4566)

A follow-up to #4559

Meta-internal autodeps feature has issues with imports like `from
torchvision.models import MobileNet_V3_Large_Weights`, so changed the
logic to just do `from torchvision import models` (if not yet imported)
and then use full name from `models` for the weights.
kit1980 added a commit to pytorch-labs/torchfix that referenced this pull request Nov 23, 2023
… codemod (#4566)

A follow-up to pytorch/test-infra#4559

Meta-internal autodeps feature has issues with imports like `from
torchvision.models import MobileNet_V3_Large_Weights`, so changed the
logic to just do `from torchvision import models` (if not yet imported)
and then use full name from `models` for the weights.
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.

6 participants