Refactor image loading in tests to use load_test_image helper
Author: LevelVoid
Pull request: yes

<!-- ci-dashboard-badge:start -->
[![CI](https://transformers-ci.lor-e.huggingface.cool/badge/pr?pr=47218)](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=47218)
<!-- ci-dashboard-badge:end -->

# 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`](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md).

- [x] (First-time contributors only): I confirm that this PR description and code is not written by an LLM or code agent

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://huggingface.co/docs/transformers/contributing) and the
      [Pull Request](https://huggingface.co/docs/transformers/pr_checks) checks?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case. (Link to the issue: https://github.com/huggingface/transformers/issues/47205)
- [ ] Did you make sure to update the documentation with your changes according to the [guidelines](https://github.com/huggingface/transformers/tree/main/docs)?
- [ ] Did you write any new necessary [tests](https://huggingface.co/docs/transformers/testing)?


## 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!
<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker @Cyrilvallez @vasqu
- vision models: @yonigozlan @molbap
- audio models: @eustlb @ebezzam @vasqu
- multimodal models: @zucchini-nlp
- graph models: @clefourrier

Library:

- generate: @zucchini-nlp (visual-language models) or @Cyrilvallez (all others)
- continuous batching: @remi-or @ArthurZucker @McPatate
- pipelines: @Rocketknight1
- tokenizers: @ArthurZucker and @itazap
- trainer: @SunMarc
- attention: @vasqu @ArthurZucker @CyrilVallez
- model loading (from pretrained, etc): @CyrilVallez
- distributed: @3outeille @ArthurZucker
- CIs: @ydshieh

Integrations:

- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization: @SunMarc
- kernels: @vasqu @drbh
- peft: @BenjaminBossan @githubnemo

Devices/Backends:

- AMD ROCm: @ivarflakstad
- Intel XPU: @IlyasMoutawwakil
- Ascend NPU: @ivarflakstad 

Documentation: @stevhliu

Research projects are not maintained and should be taken as is.

 -->

Comments:
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.

@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` 

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_47218). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@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.

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

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/29226732967)💔 This comment contains `run-slow`, but unknown error occurred and [the workflow run](https://github.com/huggingface/transformers/actions/runs/29226732967) aborted!

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

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/29264094535)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/aimv2", "models/aria", "models/deepseek_vl_hybrid", "models/eomt", "models/eomt_dinov3", "models/fast_vlm", "models/flava", "models/fuyu", "models/idefics", "models/imagegpt", "models/kimi_k25", "models/layoutlmv2", "models/lfm2_vl", "models/llava", "models/minimax_m3_vl", "models/pix2struct"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/29264094535)

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [c372574d](https://github.com/huggingface/transformers/commit/c372574d8d4b79df93c3597ca6178e3e6b3a9251) | workflow commit (merge commit) |
| PR | [a5a4ad55](https://github.com/LevelVoid/transformers/commit/a5a4ad552a96d740c402386ac5af1fdad7a914fd) | branch commit (from PR) |
| main | [11ed2ff4](https://github.com/huggingface/transformers/commit/11ed2ff4df5fdfb3117f0e3365ef6ad94081ba69) | base commit (on `main`) |

⚠️ **Model CI failed to report results**

The test failure analysis could not be completed. Please check the [workflow run](https://github.com/huggingface/transformers/actions/runs/29264094535) for details.


@LevelVoid let's stop merging main, we need the slow GPU test to finish (merging main stops it)

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

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/29317501082)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/aimv2", "models/aria", "models/deepseek_vl_hybrid", "models/eomt", "models/eomt_dinov3", "models/fast_vlm", "models/flava", "models/fuyu", "models/idefics", "models/imagegpt", "models/kimi_k25", "models/layoutlmv2", "models/lfm2_vl", "models/llava", "models/minimax_m3_vl", "models/pix2struct"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/29317501082)

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [3d3cbce4](https://github.com/huggingface/transformers/commit/3d3cbce4d10986dc26580ee9fabd9c684f267a33) | workflow commit (merge commit) |
| PR | [32390e44](https://github.com/LevelVoid/transformers/commit/32390e44f1987d98a047f167bdd89d300960ac89) | branch commit (from PR) |
| main | [f1a2a70f](https://github.com/huggingface/transformers/commit/f1a2a70f2804720198a071816bc311e765869296) | base commit (on `main`) |

⚠️ **Model CI failed to report results**

The test failure analysis could not be completed. Please check the [workflow run](https://github.com/huggingface/transformers/actions/runs/29317501082) for details.


Understood. I've stopped merging main. I'm currently investigating the failures from the run-slow GPU workflow and trying to reproduce them locally to identify the root cause. If there's a recommended way to reproduce this workflow locally, or if there are specific scripts/workflows I should look at to match the CI environment, I'd really appreciate any pointers.

@tarekziade I've been investigating the remaining failures from the run-slow GPU workflow.
So far, I've been able to reproduce and run all of the tests I modified locally, and they all pass after updating my branch. The remaining issue is that the pytest/custom-tests slow CI workflow still reports failures that I haven't been able to reproduce locally.
I'm currently comparing the CI logs to determine whether those failures are actually related to the load_test_image refactor or are coming from differences in the CI environment. If there's a recommended way to reproduce the run-slow environment locally, or if there are particular logs/workflows I should focus on when debugging these failures, I'd really appreciate any guidance.

> @tarekziade I've been investigating the remaining failures from the run-slow GPU workflow. So far, I've been able to reproduce and run all of the tests I modified locally, and they all pass after updating my branch. The remaining issue is that the pytest/custom-tests slow CI workflow still reports failures that I haven't been able to reproduce locally. I'm currently comparing the CI logs to determine whether those failures are actually related to the load_test_image refactor or are coming from differences in the CI environment. If there's a recommended way to reproduce the run-slow environment locally, or if there are particular logs/workflows I should focus on when debugging these failures, I'd really appreciate any guidance.

Yeah it could be unrelated or flaky. to try out for flakiness, you can use this on the specific test

```
pytest -sxv tests/models/xxx/file.py::ClassName::test_name --flake-finder --flake-runs 500
```

if you can reproduce then try the same on the `main` branch. 



run-slow: flava

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/29412664108)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/flava"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/29412664108)

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [a30375e7](https://github.com/huggingface/transformers/commit/a30375e7fafb7b1ad37d0cf38696f7069a4b9ed9) | workflow commit (merge commit) |
| PR | [e1849f0a](https://github.com/LevelVoid/transformers/commit/e1849f0aaafb445320a8d74a04a39f524b6df588) | branch commit (from PR) |
| main | [e194978a](https://github.com/huggingface/transformers/commit/e194978ab2043fe57150aafea53a4efbea77258c) | base commit (on `main`) |

⚠️ **Model CI failed to report results**

The test failure analysis could not be completed. Please check the [workflow run](https://github.com/huggingface/transformers/actions/runs/29412664108) for details.


> > @tarekziade I've been investigating the remaining failures from the run-slow GPU workflow. So far, I've been able to reproduce and run all of the tests I modified locally, and they all pass after updating my branch. The remaining issue is that the pytest/custom-tests slow CI workflow still reports failures that I haven't been able to reproduce locally. I'm currently comparing the CI logs to determine whether those failures are actually related to the load_test_image refactor or are coming from differences in the CI environment. If there's a recommended way to reproduce the run-slow environment locally, or if there are particular logs/workflows I should focus on when debugging these failures, I'd really appreciate any guidance.
> 
> Yeah it could be unrelated or flaky. to try out for flakiness, you can use this on the specific test
> 
> ```
> pytest -sxv tests/models/xxx/file.py::ClassName::test_name --flake-finder --flake-runs 500
> ```
> 
> if you can reproduce then try the same on the `main` branch.

I tried reproducing the failure on both `main` and my PR branch using `flakefinder`, and in both cases the test consistently fails with the same `AssertionError`.
I've attached the logs from both runs:
[pr_flava.txt](https://github.com/user-attachments/files/30058725/pr_flava.txt)
[main_flava.txt](https://github.com/user-attachments/files/30058727/main_flava.txt)
Is this an existing flaky test, or is there another run-slow failure you'd like me to focus on instead?



@tarekziade I also noticed a new failure on the latest run from the security-gate / bandit-check workflow. It fails during the checkout step with:
`Refusing to checkout fork pull request code from a 'pull_request_target' workflow.`
Since this happens before Bandit actually runs, I'm not sure if this is something I need to address on my side or if it's a CI/workflow configuration issue. Should I do anything here, or can this be ignored for now?

> @tarekziade I also noticed a new failure on the latest run from the security-gate / bandit-check workflow. It fails during the checkout step with: `Refusing to checkout fork pull request code from a 'pull_request_target' workflow.` Since this happens before Bandit actually runs, I'm not sure if this is something I need to address on my side or if it's a CI/workflow configuration issue. Should I do anything here, or can this be ignored for now?

Yes we had lots of issues in the CI in the past week, I am looking now

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

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/29561208144)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/aimv2", "models/aria", "models/deepseek_vl_hybrid", "models/eomt", "models/eomt_dinov3", "models/fast_vlm", "models/flava", "models/fuyu", "models/idefics", "models/imagegpt", "models/kimi_k25", "models/layoutlmv2", "models/lfm2_vl", "models/llava", "models/minimax_m3_vl", "models/pix2struct"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/29561208144)

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [facbd63f](https://github.com/huggingface/transformers/commit/facbd63f44600948cf24ebef3870cf193eab6ea6) | workflow commit (merge commit) |
| PR | [0f9f11ce](https://github.com/LevelVoid/transformers/commit/0f9f11ce31aa0c8b579ee2a60fc277e5c121a5f0) | branch commit (from PR) |
| main | [150eb7c9](https://github.com/huggingface/transformers/commit/150eb7c9ed4091294c829fa0e9466b090cb0f87f) | base commit (on `main`) |

✅ No failing test specific to this PR 🎉 👏 !


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](https://github.com/huggingface/transformers/actions/runs/29555708659) for the exact violations.

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

**[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

<!-- ci-dashboard-recap:start -->

---

### CI recap

**Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=47218)
**Latest run:** [29564388740:2](https://github.com/huggingface/transformers/actions/runs/29564388740)
**Result:** `success` | **Jobs:** 15 | **Tests:** 172,160 | **Failures:** 0 | **Duration:** 15h 0m

<!-- ci-dashboard-recap:end -->

> Thanks for your work @LevelVoid and sorry it took so long

Thanks! Really appreciate the review and guidance. Looking forward to contributing more.