Skip to content

Conversation

bogdansalyp
Copy link
Collaborator

@bogdansalyp bogdansalyp commented Feb 9, 2025

Context

What is the purpose of this PR? Is it to

Please link to any issues this PR addresses.

Changelog

Additional check added that torch and torchvision packages are installed with corresponding error messages.

Test plan

Please make sure to do each of the following if applicable to your PR. If you're unsure about any one of these just ask and we will happily help. We also have a contributing page for some guidance on contributing.

  • run pre-commit hooks and linters (make sure you've first installed via pre-commit install)
  • add unit tests for any new functionality
  • update docstrings for any new or updated methods or classes
  • run unit tests via pytest tests
  • run recipe tests via pytest tests -m integration_test
  • manually run any new or modified recipes with sufficient proof of correctness
  • include relevant commands and any other artifacts in this summary (pastes of loss curves, eval results, etc.)

UX

If your function changed a public API, please add a dummy example of what the user experience will look like when calling it.
Here is a docstring example
and a tutorial example

  • I did not change any public API
  • I have added an example to docs or docstrings

Copy link

pytorch-bot bot commented Feb 9, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/2368

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 52e5709 with merge base fb52557 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot
Copy link

Hi @bogdansalyp!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@bogdansalyp bogdansalyp marked this pull request as draft February 9, 2025 04:45
@bogdansalyp bogdansalyp changed the title fix: torch and torchvision check alongside torchao one fix: torch and torchvision import check Feb 9, 2025
Copy link
Contributor

@ebsmothers ebsmothers left a comment

Choose a reason for hiding this comment

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

Thanks for creating the PR. I agree that the try/except ImportError just on torchao was a bit too much of a hammer to solve this specific problem (and I am to blame.. if you haven't already, you can see the backstory in #1452). So I think checking the torch import first makes just so that we can give a more helpful error message.

I am on the fence about doing the same for torchvision though -- it is actually not a hard dependency for many of our components (e.g. from torchtune import training should succeed even if you don't have torchvision installed). The main reason for taking this approach with ao is that it's pretty tightly-integrated into our low-level components, and it's a painful experience to only hit the import error when you're ready train a model or something. (E.g. the same import will fail without ao installed because of our LoRA components.) For torchvision I claim it's actually OK to not be so aggressive about it -- it's only relevant for those who are training multimodal models, and most components should work without it, so we don't need to push installation up front to the same degree.

@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 Feb 10, 2025
@bogdansalyp bogdansalyp marked this pull request as ready for review February 10, 2025 22:31
@pbontrager
Copy link
Contributor

Probably the right way to do this is to have a pip install torchtune[mm] that installs/requires the additional multimodal dependencies. But I agree with Evan that I think for now, torchvision shouldn't be required for every user. Though our install instructions in the README and the docs should be updated to mention installing torch-vision if you intend to use VLMs.

Another option is that this PR could just print a warning for a missing torchvision dependency instead of throwing an error.

@InflectionAI InflectionAI closed this by deleting the head repository Apr 18, 2025
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.

Misleading import error message for torchao

5 participants