Skip to content

Refactor image loading in tests to use load_test_image helper#47218

Open
LevelVoid wants to merge 11 commits into
huggingface:mainfrom
LevelVoid:refactor/load_test_image
Open

Refactor image loading in tests to use load_test_image helper#47218
LevelVoid wants to merge 11 commits into
huggingface:mainfrom
LevelVoid:refactor/load_test_image

Conversation

@LevelVoid

@LevelVoid LevelVoid commented Jul 9, 2026

Copy link
Copy Markdown

CI

What does this PR do?

This PR introduces a shared load_test_image helper in tests/test_processing_common.py and updates the affected test files to use it instead of directly downloading COCO fixture images via httpx.get(...) or requests.get(...) for the files mentioned in issue #47205.

By routing image loading through url_to_local_path(...), the tests consistently use the local fixture cache when available and remain aligned with the CI prefetch workflow.

Fixes #47205

Code Agent Policy

The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. These often are low-quality, or fix extremely minor issues that occur rarely or never in practice.
As a result, we're instituting a rule that first-time contributors should not use code agents to submit PRs or issues.
We'd also ask autonomous "OpenClaw"-like agents not to open any PRs or issues.

Issues/PRs from first-time contributors that violate this rule will probably just be closed without review, and we
might block you, especially if you open more than one or appear to be deliberately ignoring this. We especially do not
want new contributors to jump in on random issues to contribute an agent-written fix. This creates lots of noise
for reviewers and other users and will almost certainly get you blocked.

For more information, please read CONTRIBUTING.md.

  • (First-time contributors only): I confirm that this PR description and code is not written by an LLM or code agent

Before submitting

Who can review?

@tarekziade As discussed on the issue, this PR implements the requested changes. I'd appreciate your review when you have a chance. Thank you!

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution 🤗!

CI Security Gate — automatic approval blocked

This PR was not automatically approved for CI because the security gate failed.

Possible reasons:

  • The PR touches 50 or more files — only PRs with fewer than 50 changed files are automatically approved
  • A changed file is outside the allowed directories (src/, tests/, docs/, utils/), has a disallowed extension (only .py, .txt, .md permitted outside tests/ and docs/), or is not .md/.yml inside docs/
  • A new high-severity security issue was detected in the changed Python files (Bandit check)

See the workflow run for the exact violations.

A maintainer can review and manually approve CI if a finding is a false positive.

@LevelVoid

LevelVoid commented Jul 10, 2026

Copy link
Copy Markdown
Author

Hi @tarekziade,
Just a quick update: after the initial CI passed, I updated the branch with the latest main using GitHub's Update branch button as new commits landed.
Since then, the failing tests have changed across updates. The previous run failed in:
tests/models/speech_to_text/test_feature_extraction_speech_to_text.py::Speech2TextFeatureExtractionWithoutTorchaudioTest::test_dither
and after updating again with the latest main, the current failure is:
tests/cli/test_serve.py
with a pydantic_core.ValidationError related to InputTokensDetails.
These failures appear to be in areas unrelated to the changes in this PR, so I wanted to check whether you'd prefer that I wait for CI to stabilize or investigate these failures further.

@tarekziade

Copy link
Copy Markdown
Collaborator

@LevelVoid the linters where updated, can you run pip install -e [.dev] locally to get a fresh mlinter ? I also re-triggred CI

we can also remove the COCO urls from fetch_hub_objects_for_ci.py

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@LevelVoid

Copy link
Copy Markdown
Author

@tarekziade Thanks! I've updated my local development dependencies, removed the obsolete COCO URLs from fetch_hub_objects_for_ci.py, and pushed the changes. Please let me know if there's anything else you'd like me to update.

Comment thread tests/models/aria/test_modeling_aria.py Outdated
Comment on lines +53 to +54
if is_vision_available():
from PIL import Image
pass

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

something like this to be removed - across the files changed in this PR 🙏

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

sure, will remove those across all changed files along.

@tarekziade

Copy link
Copy Markdown
Collaborator

run-slow: aimv2, aria, deepseek_vl_hybrid, eomt, eomt_dinov3, fast_vlm, flava, fuyu, idefics, imagegpt, kimi_k25, layoutlmv2, lfm2_vl, llava, minimax_m3_vl, pix2struct

@github-actions

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️💔 This comment contains run-slow, but unknown error occurred and the workflow run aborted!

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 29226737596:2
Result: success | Jobs: 15 | Tests: 170,779 | Failures: 0 | Duration: 15h 4m

"http://images.cocodataset.org/val2017/000000039769.jpg",
"http://images.cocodataset.org/val2017/000000077595.jpg",
"http://images.cocodataset.org/val2017/000000136466.jpg",
# Legacy COCO URLs have been removed; tests now use the HuggingFace internal testing fixtures mirror.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

let's remove this comment


image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_test_image(
"https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017/000000039769.jpg"

@tarekziade tarekziade Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe we could use a constant for that dataset as a root url and a simple function load_coco_image

in the commont module:

COCO_DATASET_URL = "https://huggingface.co/datasets/hf-internal-testing/fixtures-coco/resolve/main/val2017"

def load_coco_image(image):
  ...

then here, just:

load_coco_image("000000039769.jpg")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, this will simplify the codebase across multiple files. i will make the changes and push the code.

@tarekziade tarekziade left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM I have one small simplification idea

@github-actions

Copy link
Copy Markdown
Contributor

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

run-slow: aimv2, aria, deepseek_vl_hybrid, eomt, eomt_dinov3, fast_vlm, flava, fuyu, idefics, imagegpt, kimi_k25, layoutlmv2, lfm2_vl, llava, minimax_m3_vl, pix2struct

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.

Standardize test image fixture loading for COCO images

4 participants