transformers - ✅(Solved) Fix Unable to load `AutoImageProcessor` from URL [1 pull requests, 6 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
huggingface/transformers#44821Fetched 2026-04-08 00:57:12
View on GitHub
Comments
6
Participants
3
Timeline
16
Reactions
0
Timeline (top)
commented ×6cross-referenced ×4closed ×2referenced ×2

Error Message

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/models/auto/image_processing_auto.py", line 514, in from_pretrained raise initial_exception File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/models/auto/image_processing_auto.py", line 501, in from_pretrained config_dict, _ = ImageProcessingMixin.get_image_processor_dict( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/image_processing_base.py", line 282, in get_image_processor_dict resolved_processor_file = cached_file( ^^^^^^^^^^^^ File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/utils/hub.py", line 277, in cached_file file = cached_files(path_or_repo_id=path_or_repo_id, filenames=[filename], **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/utils/hub.py", line 469, in cached_files raise OSError(f"{e}") from e OSError: Repo id must be in the form 'repo_name' or 'namespace/repo_name': 'https://huggingface.co/jinfengxie/BFMS_1014/raw/main/config.json'. Use repo_type argument if needed.

Fix Action

Fixed

PR fix notes

PR #44838: Fix AutoImageProcessor.from_pretrained failing with URL input

Description (problem / solution / changelog)

Summary

  • Fixes #44821 — AutoImageProcessor.from_pretrained fails with OSError: Repo id must be in the form 'repo_name' or 'namespace/repo_name' when given a URL
  • The URL handling branch (is_remote_url check) in get_image_processor_dict was accidentally removed during the v5 cleanup
  • Restores URL support by adding an elif branch that detects HTTP(S) URLs, downloads the JSON content directly, and writes it to a temp file for parsing
  • Adds a unit test with mocked HTTP to verify URL-based loading works

Test plan

  • New test test_image_processor_from_pretrained_url passes — verifies that a mocked URL returns a valid ViTImageProcessor
  • Existing ImageProcessorUtilTester tests still pass
  • Manually test with transformers.AutoImageProcessor.from_pretrained("https://huggingface.co/jinfengxie/BFMS_1014/raw/main/config.json")

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Changed files

  • src/transformers/image_processing_base.py (modified, +20/-0)
  • tests/utils/test_image_processing_utils.py (modified, +21/-0)

Code Example

import transformers

url = "https://huggingface.co/jinfengxie/BFMS_1014/raw/main/config.json"
transformers.AutoImageProcessor.from_pretrained(url)  # fails on >=5.0, succeeds pre-5.0

local_file = "/path/to/config.json"  # download the file from the URL above
transformers.AutoImageProcessor.from_pretrained(local_file)  # succeeds on v4 and v5

---

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/models/auto/image_processing_auto.py", line 514, in from_pretrained
    raise initial_exception
  File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/models/auto/image_processing_auto.py", line 501, in from_pretrained
    config_dict, _ = ImageProcessingMixin.get_image_processor_dict(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/image_processing_base.py", line 282, in get_image_processor_dict
    resolved_processor_file = cached_file(
                              ^^^^^^^^^^^^
  File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/utils/hub.py", line 277, in cached_file
    file = cached_files(path_or_repo_id=path_or_repo_id, filenames=[filename], **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/utils/hub.py", line 469, in cached_files
    raise OSError(f"{e}") from e
OSError: Repo id must be in the form 'repo_name' or 'namespace/repo_name': 'https://huggingface.co/jinfengxie/BFMS_1014/raw/main/config.json'. Use `repo_type` argument if needed.
RAW_BUFFERClick to expand / collapse

System Info

<details><summary>Versions</summary> <p>
  • transformers version: 5.3.0
  • Platform: Linux-6.8.0-106-generic-x86_64-with-glibc2.39
  • Python version: 3.12.3
  • Huggingface_hub version: 1.7.1
  • Safetensors version: 0.7.0
  • Accelerate version: not installed
  • Accelerate config: not found
  • DeepSpeed version: not installed
  • PyTorch version (accelerator?): 2.10.0+cu128 (NA)
</p> </details>

Bug

I am trying to load a config from URL, to instatiate the AutoImageProcessor. This worked before, but not anymore with new versions of transformers.

Bug starts occuring with transformers>=5.3.0. It worked with transformers==4.57.6

To reproduce;

import transformers

url = "https://huggingface.co/jinfengxie/BFMS_1014/raw/main/config.json"
transformers.AutoImageProcessor.from_pretrained(url)  # fails on >=5.0, succeeds pre-5.0

local_file = "/path/to/config.json"  # download the file from the URL above
transformers.AutoImageProcessor.from_pretrained(local_file)  # succeeds on v4 and v5
<details><summary>traceback</summary> <p>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/models/auto/image_processing_auto.py", line 514, in from_pretrained
    raise initial_exception
  File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/models/auto/image_processing_auto.py", line 501, in from_pretrained
    config_dict, _ = ImageProcessingMixin.get_image_processor_dict(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/image_processing_base.py", line 282, in get_image_processor_dict
    resolved_processor_file = cached_file(
                              ^^^^^^^^^^^^
  File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/utils/hub.py", line 277, in cached_file
    file = cached_files(path_or_repo_id=path_or_repo_id, filenames=[filename], **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bart/git/streetscapes/.venv/lib/python3.12/site-packages/transformers/utils/hub.py", line 469, in cached_files
    raise OSError(f"{e}") from e
OSError: Repo id must be in the form 'repo_name' or 'namespace/repo_name': 'https://huggingface.co/jinfengxie/BFMS_1014/raw/main/config.json'. Use `repo_type` argument if needed.
</p> </details>

extent analysis

Fix Plan

The issue arises from the change in how transformers handles URLs for loading models and configurations. To fix this, you need to specify the repository ID and the filename separately.

Step-by-Step Solution:

  1. Specify Repository ID and Filename: Instead of passing the full URL to from_pretrained, you should pass the repository ID and specify the filename using the subfolder argument if necessary.
  2. Use repo_id and revision: If your model or config is not in the main branch, ensure you specify the correct revision.

Example Code:

from transformers import AutoImageProcessor

# Define the repository ID and filename
repo_id = "jinfengxie/BFMS_1014"
filename = "config.json"

# Load the image processor
image_processor = AutoImageProcessor.from_pretrained(
    repo_id,
    subfolder="raw/main",  # Specify the subfolder if the file is not in the root
    filename=filename,
    revision="main"  # Specify the revision if not using the default branch
)

Verification

After applying the fix, verify that the AutoImageProcessor can be instantiated successfully without raising any errors. You can do this by running the modified code snippet above.

Extra Tips

  • Always ensure you're using the correct repository ID and filename when loading models or configurations from the Hugging Face hub.
  • If you're working with specific revisions or branches, make sure to specify the revision argument accordingly.
  • Keep your transformers library up to date to leverage the latest features and fixes.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING