Guard against a None video processor class when the backend is unavailable by caiotheodoro · Pull Request #48557 · huggingface/transformers · GitHub
Skip to content

Guard against a None video processor class when the backend is unavailable - #48557

Open
caiotheodoro wants to merge 1 commit into
huggingface:mainfrom
caiotheodoro:fix/video-processor-none-guard
Open

Guard against a None video processor class when the backend is unavailable#48557
caiotheodoro wants to merge 1 commit into
huggingface:mainfrom
caiotheodoro:fix/video-processor-none-guard

Conversation

@caiotheodoro

@caiotheodoro caiotheodoro commented Sep 6, 2026

Copy link
Copy Markdown

CPU CI GPU run-slow

Fixes #48556

AutoProcessor.from_pretrained("OpenGVLab/InternVL3-1B-hf") without torchvision installed raises AttributeError: 'NoneType' object has no attribute '__module__' at video_processing_auto.py:363, instead of the "requires torchvision" error added in #44125.

has_local_code is true when the config type is a key in VIDEO_PROCESSOR_MAPPING, but without torchvision every value in that mapping is None. For InternVL video_processor_class is also None — its image processor is GotOCRImageProcessor and no GotOCRVideoProcessor exists to infer from, which line 330 already handles — so (None or None).__module__ raises. Salesforce/instructblip-vicuna-7b fails the same way, and InstructBLIP is image-only.

This mirrors image_processing_auto.py:655-664, which guards the None and computes explicit_local_code only inside if has_remote_code: — the sole place it is used.

After the change both models reach the intended error:

ValueError: OpenGVLab/InternVL3-1B-hf requires `torchvision` to be installed.

The test mirrors test_unavailable_backend_error_mentions_missing_dependency in tests/models/auto/test_image_processing_auto.py. It uses patch.dict(VIDEO_PROCESSOR_MAPPING._extra_content, ...) to force the None value while torchvision is installed in CI; happy to change that if you prefer a different seam.

Differentiation from existing PRs

#44125 added the torchvision message at the end of this function but did not guard this earlier path. #45045 fixed a spurious torchvision requirement on PIL-backend image processors, a different code path. No open PR touches explicit_local_code in video_processing_auto.py.

Tests

pytest tests/models/auto/test_video_processing_auto.py
  12 passed

pytest tests/models/auto/test_processing_auto.py tests/models/auto/test_image_processing_auto.py
  41 passed, 5 skipped

pytest tests/models/auto/test_video_processing_auto.py -k unavailable_backend
  before: 1 failed (AttributeError: 'NoneType' object has no attribute '__module__')
  after:  1 passed

ruff check  - All checks passed
ruff format - 2 files already formatted

Reproduced on transformers 5.16.1 and main @ c93057d, Python 3.11.15, macOS arm64, torchvision not installed.

AI usage disclosure

Per CONTRIBUTING: this change was made with AI assistance. I hit the defect while loading a Qwen VL processor for a fine-tuning run on a machine without torchvision.

…lable

Without torchvision every VIDEO_PROCESSOR_MAPPING value is None while the
config type is still a key, so
`(video_processor_class or VIDEO_PROCESSOR_MAPPING[type(config)]).__module__`
raised AttributeError for models whose video processor cannot be inferred,
such as InternVL and InstructBLIP. That happens before the
is_torchvision_available() check further down, so the informative error added
in huggingface#44125 was never reached.

Mirror image_processing_auto.py: guard the None and compute
explicit_local_code only inside `if has_remote_code:`, the only place it is
used.
@caiotheodoro
caiotheodoro force-pushed the fix/video-processor-none-guard branch from 3f40c01 to 5eef47b Compare September 6, 2026 03:04
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

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.

AutoProcessor.from_pretrained raises AttributeError: 'NoneType' object has no attribute '__module__' when torchvision is missing

1 participant