Skip to content

Fix PIL backend fallback when torchvision is unavailable#45060

Open
ErenAta16 wants to merge 2 commits intohuggingface:mainfrom
ErenAta16:fix/pil-backend-torchvision-regression-45042
Open

Fix PIL backend fallback when torchvision is unavailable#45060
ErenAta16 wants to merge 2 commits intohuggingface:mainfrom
ErenAta16:fix/pil-backend-torchvision-regression-45042

Conversation

@ErenAta16
Copy link
Copy Markdown

This PR fixes a regression where PIL-based image/video processors were incorrectly treated as requiring torchvision.

As a result, AutoProcessor / AutoImageProcessor could fail in environments without torchvision, even though a valid PIL fallback exists.

What changed

  • Updated import-structure backend resolution in import_utils so PIL modules do not inherit torchvision requirements:
    • image_processing_pil_*
    • video_processing_pil_*
  • Added a normalization step to prevent torchvision from being attached to PIL-only modules during backend aggregation.
  • Added regression tests for:
    • PIL import-structure backend correctness
    • Auto-backend fallback to PIL when torchvision is unavailable

Fixes #45042

Tests

  • python -m pytest tests/utils/test_import_structure.py -k "pil_import_structure_does_not_require_torchvision" -q
  • python -m pytest tests/models/auto/test_image_processing_auto.py -k "auto_backend_falls_back_to_pil_when_torchvision_is_unavailable or backend_kwarg_pil" -q

Prevent PIL image/video processor classes from inheriting torchvision backend requirements in the import structure so AutoProcessor/AutoImageProcessor can correctly fall back to PIL when torchvision is unavailable. Add regression tests to lock the import-structure behavior and the auto-backend fallback path.

Made-with: Cursor
Patch the AutoImageProcessor fallback regression test to mock the backend resolution helper used by image_processing_auto, so it correctly simulates a no-torchvision environment in CI.

Made-with: Cursor
@ErenAta16 ErenAta16 force-pushed the fix/pil-backend-torchvision-regression-45042 branch from 039b93f to 9350f48 Compare March 27, 2026 14:37
@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: auto

@github-actions
Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45060&sha=9350f4

@ErenAta16
Copy link
Copy Markdown
Author

Thanks for the run. The current failure is in
tests/models/prophetnet/test_modeling_prophetnet.py::ProphetNetModelTest::test_encoder_decoder_model_generate,
which is outside this PR scope.

This PR only changes PIL backend import-structure/fallback logic:

  • src/transformers/utils/import_utils.py
  • tests/utils/test_import_structure.py
  • tests/models/auto/test_image_processing_auto.py

Could we rerun tests_torch once? If the same ProphetNet test is consistently failing, I can help track it separately.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PIL backend image processors incorrectly require torchvision in v5.4.0

1 participant