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

Disallow missing image libraries during setup? #7151

Open
pmeier opened this issue Jan 30, 2023 · 2 comments
Open

Disallow missing image libraries during setup? #7151

pmeier opened this issue Jan 30, 2023 · 2 comments

Comments

@pmeier
Copy link
Collaborator

pmeier commented Jan 30, 2023

To customize the installation, we have a few environment variables, e.g.

vision/setup.py

Lines 146 to 149 in 6a85ef2

use_png = os.getenv("TORCHVISION_USE_PNG", "1") == "1"
print(f" TORCHVISION_USE_PNG: {use_png}")
use_jpeg = os.getenv("TORCHVISION_USE_JPEG", "1") == "1"
print(f" TORCHVISION_USE_JPEG: {use_jpeg}")

As can be seen above, by default they are set to 1, which indicates that the user wants to build torchvision with PNG and JPEG support. However, we don't require the dependencies, namely libpng and libjpeg to be present:

vision/setup.py

Lines 256 to 259 in 6a85ef2

png_found = libpng is not None or pngfix is not None
use_png = use_png and png_found
if use_png:

vision/setup.py

Lines 291 to 292 in 6a85ef2

else:
print("Building torchvision without PNG image support")

Only if one of the two is present, we simply build the image extension:

vision/setup.py

Lines 332 to 335 in 6a85ef2

if use_png or use_jpeg:
ext_modules.append(
extension(
"torchvision.image",

However, if users import torchvision after successful installation, they are met with this warning:

UserWarning: Failed to load image Python extension: 

Unless they want to use the image functionality from torchvision.io, this is not an issue and #7150 is trying to fix that.

In the mean time, the behavior described above can lead to issues like #7036. Plus, there is also this really long thread in the user forum also reporting this (I'm aware that there are reports of this warning popping up from an official nightly release, but there are also people that face this after building from source).

IMO, we should discuss if we should accept that one of the image libraries is not available during build. Meaning, by default the libraries are required and the setup could simply fail if they are not found. If the user doesn't care about the I/O functionality they need to explicitly set USE_PNG=0 USE_JPEG=0 python setup.py install.

@adamjstewart
Copy link
Contributor

@yichiac and I stumbled on this same issue when installing torchvision from source with Spack, where png/jpeg support is not installed by default.

Is it possible to issue this warning only when torchvision.io is imported, not when torchvision is imported?

Among the optional png, jpeg, nvjpeg, ffmpeg, and video_codec extensions, which would you recommend that Spack install by default? Users can of course toggle individual extensions themselves, just want to know what a good set of defaults is.

@NicolasHug
Copy link
Member

NicolasHug commented Jan 1, 2024

Is it possible to issue this warning only when torchvision.io is imported, not when torchvision is imported?

Yes, we should at least try to. Since it's slightly different from what this issue originally is for, do you mind opening a new issue for that @adamjstewart ?

just want to know what a good set of defaults is

It's going to depend on what they need to do but I would say libjpeg-turbo (or libjpeg, but it's not as fast) would be the bare minimum. I wouldn't recommend spending time trying to get nvjpeg and ffmpeg working at this point as most of our video decoding offering is not completely polished just yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants