Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6927f5a
Refactor image loading in tests to use load_test_image helper
LevelVoid Jul 9, 2026
2d2a2ad
Apply Ruff formatting
LevelVoid Jul 9, 2026
f060982
Revert unintended formatting changes
LevelVoid Jul 9, 2026
272629e
Merge branch 'main' into refactor/load_test_image
LevelVoid Jul 9, 2026
87be61b
Merge branch 'main' into refactor/load_test_image
LevelVoid Jul 10, 2026
e8b7412
Merge branch 'main' into refactor/load_test_image
LevelVoid Jul 11, 2026
3e2760a
Remove unused COCO fixture URLs
LevelVoid Jul 11, 2026
7fb1d74
fix: Remove empty vision and pytesseract func
LevelVoid Jul 11, 2026
0e4fc1f
Merge branch 'main' into refactor/load_test_image
LevelVoid Jul 11, 2026
f86d444
Merge branch 'main' into refactor/load_test_image
tarekziade Jul 13, 2026
1d63b73
Merge branch 'main' into refactor/load_test_image
LevelVoid Jul 13, 2026
1fd06c5
Refactor COCO URLs to use load_coco_image helper and comment cleanup
LevelVoid Jul 13, 2026
a3c2f52
Merge branch 'refactor/load_test_image' of https://github.com/LevelVo…
LevelVoid Jul 13, 2026
8590fb0
Merge branch 'main' into refactor/load_test_image
LevelVoid Jul 13, 2026
0b1fcec
Merge branch 'main' into refactor/load_test_image
LevelVoid Jul 13, 2026
a5a4ad5
Merge branch 'main' into refactor/load_test_image
tarekziade Jul 13, 2026
dcd9886
Merge branch 'main' into refactor/load_test_image
LevelVoid Jul 14, 2026
75af436
Merge branch 'main' into refactor/load_test_image
LevelVoid Jul 14, 2026
32390e4
Merge branch 'main' into refactor/load_test_image
LevelVoid Jul 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions tests/models/aimv2/test_modeling_aimv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import unittest

import numpy as np
import requests
from parameterized import parameterized

from transformers import Aimv2Config, Aimv2TextConfig, Aimv2VisionConfig
Expand All @@ -35,6 +34,7 @@
)

from ...test_configuration_common import ConfigTester
from ...test_image_processing_common import load_coco_image
from ...test_modeling_common import (
TEST_EAGER_MATCHES_SDPA_INFERENCE_PARAMETERIZATION,
ModelTesterMixin,
Expand All @@ -58,8 +58,6 @@


if is_vision_available():
from PIL import Image

from transformers import AutoImageProcessor, AutoProcessor


Expand Down Expand Up @@ -479,7 +477,7 @@ def test_inference(self):
model = Aimv2Model.from_pretrained(model_name, device_map=torch_device)
processor = AutoProcessor.from_pretrained(model_name)

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")
inputs = processor(
text=["a photo of a cat", "a photo of a dog"], images=image, padding=True, return_tensors="pt"
).to(model.device)
Expand Down Expand Up @@ -513,7 +511,7 @@ def test_inference(self):
model = Aimv2VisionModel.from_pretrained(model_name, device_map=torch_device)
processor = AutoImageProcessor.from_pretrained(model_name)

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")
inputs = processor(image, return_tensors="pt").to(model.device)

with torch.no_grad():
Expand Down Expand Up @@ -544,7 +542,7 @@ def test_inference_for_native_resolution(self):
model = Aimv2VisionModel.from_pretrained(model_name, device_map="auto")
processor = AutoImageProcessor.from_pretrained(model_name)

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")
inputs = processor(image, return_tensors="pt").to(model.device)

with torch.no_grad():
Expand Down
26 changes: 11 additions & 15 deletions tests/models/aria/test_modeling_aria.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import unittest

import pytest
import requests

from transformers import (
AriaConfig,
Expand All @@ -27,7 +26,6 @@
AutoTokenizer,
BitsAndBytesConfig,
is_torch_available,
is_vision_available,
)
from transformers.models.idefics3 import Idefics3VisionConfig
from transformers.testing_utils import (
Expand All @@ -43,16 +41,14 @@

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_image_processing_common import load_coco_image, load_test_image
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor


if is_torch_available():
import torch


if is_vision_available():
from PIL import Image

# Used to be https://aria-vl.github.io/static/images/view.jpg but it was removed, llava-vl has the same image
IMAGE_OF_VIEW_URL = "https://llava-vl.github.io/static/images/view.jpg"

Expand Down Expand Up @@ -246,7 +242,7 @@ def test_small_model_integration_test(self):
)

prompt = "<|img|>\nUSER: What are the things I should be cautious about when I visit this place?\nASSISTANT:"
raw_image = Image.open(requests.get(IMAGE_OF_VIEW_URL, stream=True).raw)
raw_image = load_test_image(IMAGE_OF_VIEW_URL)
inputs = self.processor(images=raw_image, text=prompt, return_tensors="pt").to(model.device, model.dtype)

non_img_tokens = [
Expand Down Expand Up @@ -286,7 +282,7 @@ def test_small_model_integration_test_llama_single(self):
processor = AutoProcessor.from_pretrained(model_id)

prompt = "USER: <|img|>\nWhat are the things I should be cautious about when I visit this place? ASSISTANT:"
raw_image = Image.open(requests.get(IMAGE_OF_VIEW_URL, stream=True).raw)
raw_image = load_test_image(IMAGE_OF_VIEW_URL)
inputs = processor(images=raw_image, text=prompt, return_tensors="pt").to(model.device, model.dtype)

output = model.generate(**inputs, max_new_tokens=90, do_sample=False)
Expand Down Expand Up @@ -320,8 +316,8 @@ def test_small_model_integration_test_llama_batched(self):
"USER: <|img|>\nWhat are the things I should be cautious about when I visit this place? What should I bring with me? ASSISTANT:",
"USER: <|img|>\nWhat is this? ASSISTANT:",
]
image1 = Image.open(requests.get(IMAGE_OF_VIEW_URL, stream=True).raw)
image2 = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image1 = load_test_image(IMAGE_OF_VIEW_URL)
image2 = load_coco_image("000000039769.jpg")

inputs = processor(images=[image1, image2], text=prompts, return_tensors="pt", padding=True).to(
model.device, model.dtype
Expand Down Expand Up @@ -358,8 +354,8 @@ def test_small_model_integration_test_batch(self):
"USER: <|img|>\nWhat are the things I should be cautious about when I visit this place? What should I bring with me?\nASSISTANT:",
"USER: <|img|>\nWhat is this?\nASSISTANT:",
]
image1 = Image.open(requests.get(IMAGE_OF_VIEW_URL, stream=True).raw)
image2 = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image1 = load_test_image(IMAGE_OF_VIEW_URL)
image2 = load_coco_image("000000039769.jpg")

inputs = self.processor(images=[image1, image2], text=prompts, return_tensors="pt", padding=True).to(
model.device, model.dtype
Expand Down Expand Up @@ -398,8 +394,8 @@ def test_small_model_integration_test_llama_batched_regression(self):
"USER: <|img|>\nWhat are the things I should be cautious about when I visit this place? What should I bring with me?\nASSISTANT:",
"USER: <|img|>\nWhat is this?\nASSISTANT: Two cats lying on a bed!\nUSER: <|img|>\nAnd this?\nASSISTANT:",
]
image1 = Image.open(requests.get(IMAGE_OF_VIEW_URL, stream=True).raw)
image2 = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image1 = load_test_image(IMAGE_OF_VIEW_URL)
image2 = load_coco_image("000000039769.jpg")

inputs = processor(images=[image1, image2, image1], text=prompts, return_tensors="pt", padding=True)
inputs = inputs.to(model.device, model.dtype)
Expand Down Expand Up @@ -431,8 +427,8 @@ def test_batched_generation(self):
prompt3 = "<image>\nUSER: Describe the image.\nASSISTANT:"
url1 = "https://images.unsplash.com/photo-1552053831-71594a27632d?q=80&w=3062&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"
url2 = "https://images.unsplash.com/photo-1617258683320-61900b281ced?q=80&w=3087&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"
image1 = Image.open(requests.get(url1, stream=True).raw)
image2 = Image.open(requests.get(url2, stream=True).raw)
image1 = load_test_image(url1)
image2 = load_test_image(url2)

# Create inputs
messages = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingTestMixin, prepare_image_inputs
from ...test_image_processing_common import (
ImageProcessingTestMixin,
load_coco_image,
prepare_image_inputs,
)


if is_torch_available():
Expand Down Expand Up @@ -203,15 +207,7 @@ def test_backends_equivalence(self):
if len(self.image_processing_classes) < 2:
self.skipTest(reason="Skipping backends equivalence test as there are less than 2 backends")

import io

import httpx

dummy_image = Image.open(
io.BytesIO(
httpx.get("http://images.cocodataset.org/val2017/000000039769.jpg", follow_redirects=True).content
)
)
dummy_image = load_coco_image("000000039769.jpg")

encodings = {}
for backend_name, image_processing_class in self.image_processing_classes.items():
Expand Down
21 changes: 8 additions & 13 deletions tests/models/eomt/test_modeling_eomt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@

import unittest

import requests

from transformers import AutoImageProcessor, EomtConfig, EomtForUniversalSegmentation, pipeline
from transformers.testing_utils import require_torch, require_torch_accelerator, require_torch_fp16, slow, torch_device
from transformers.utils import is_torch_available, is_vision_available
from transformers.utils import is_torch_available

from ...test_configuration_common import ConfigTester
from ...test_image_processing_common import load_coco_image
from ...test_modeling_common import ModelTesterMixin, floats_tensor
from ...test_pipeline_mixin import PipelineTesterMixin

Expand All @@ -30,10 +29,6 @@
import torch


if is_vision_available():
from PIL import Image


class EomtForUniversalSegmentationTester:
def __init__(
self,
Expand Down Expand Up @@ -175,7 +170,7 @@ def test_inference(self):
model = EomtForUniversalSegmentation.from_pretrained(self.model_id, device_map="auto")
processor = AutoImageProcessor.from_pretrained(self.model_id)

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")

inputs = processor(images=image, return_tensors="pt").to(model.device)

Expand Down Expand Up @@ -218,7 +213,7 @@ def test_inference_fp16(self):
model = EomtForUniversalSegmentation.from_pretrained(self.model_id, dtype=torch.float16, device_map="auto")
processor = AutoImageProcessor.from_pretrained(self.model_id)

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")

inputs = processor(images=image, return_tensors="pt").to(model.device)

Expand All @@ -234,7 +229,7 @@ def test_semantic_segmentation_inference(self):
model = EomtForUniversalSegmentation.from_pretrained(model_id, device_map="auto")
processor = AutoImageProcessor.from_pretrained(model_id)

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")

inputs = processor(images=image, return_tensors="pt").to(model.device)

Expand Down Expand Up @@ -271,7 +266,7 @@ def test_panoptic_segmentation_inference(self):
model = EomtForUniversalSegmentation.from_pretrained(self.model_id, device_map="auto")
processor = AutoImageProcessor.from_pretrained(self.model_id)

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")

inputs = processor(images=image, return_tensors="pt").to(model.device)

Expand Down Expand Up @@ -320,7 +315,7 @@ def test_instance_segmentation_inference(self):
model = EomtForUniversalSegmentation.from_pretrained(model_id, device_map="auto")
processor = AutoImageProcessor.from_pretrained(model_id)

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")

inputs = processor(images=image, return_tensors="pt").to(model.device)

Expand Down Expand Up @@ -366,7 +361,7 @@ def test_instance_segmentation_inference(self):

@slow
def test_segmentation_pipeline(self):
image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")

pipe = pipeline(model=self.model_id, subtask="panoptic", device=torch_device)
output = pipe(image)
Expand Down
21 changes: 8 additions & 13 deletions tests/models/eomt_dinov3/test_modeling_eomt_dinov3.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

import unittest

import requests

from transformers import AutoImageProcessor, EomtDinov3Config, EomtDinov3ForUniversalSegmentation, pipeline
from transformers.testing_utils import (
Expectations,
Expand All @@ -26,9 +24,10 @@
slow,
torch_device,
)
from transformers.utils import is_torch_available, is_vision_available
from transformers.utils import is_torch_available

from ...test_configuration_common import ConfigTester
from ...test_image_processing_common import load_coco_image
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor
from ...test_pipeline_mixin import PipelineTesterMixin

Expand All @@ -37,10 +36,6 @@
import torch


if is_vision_available():
from PIL import Image


class EomtDinov3ForUniversalSegmentationTester:
def __init__(
self,
Expand Down Expand Up @@ -220,7 +215,7 @@ def test_inference(self):
model = EomtDinov3ForUniversalSegmentation.from_pretrained(self.model_id, device_map="auto")
processor = AutoImageProcessor.from_pretrained(self.model_id)

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")

inputs = processor(images=image, return_tensors="pt").to(model.device)

Expand Down Expand Up @@ -262,7 +257,7 @@ def test_inference_bf16(self):
)
processor = AutoImageProcessor.from_pretrained(self.model_id)

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")

inputs = processor(images=image, return_tensors="pt").to(model.device)

Expand Down Expand Up @@ -319,7 +314,7 @@ def test_semantic_segmentation_inference(self):
model = EomtDinov3ForUniversalSegmentation.from_pretrained(model_id, device_map="auto")
processor = AutoImageProcessor.from_pretrained(model_id)

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")

inputs = processor(images=image, return_tensors="pt").to(model.device)

Expand Down Expand Up @@ -375,7 +370,7 @@ def test_panoptic_segmentation_inference(self):
model = EomtDinov3ForUniversalSegmentation.from_pretrained(self.model_id, device_map="auto")
processor = AutoImageProcessor.from_pretrained(self.model_id)

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")

inputs = processor(images=image, return_tensors="pt").to(model.device)

Expand Down Expand Up @@ -421,7 +416,7 @@ def test_instance_segmentation_inference(self):
model = EomtDinov3ForUniversalSegmentation.from_pretrained(model_id, device_map="auto")
processor = AutoImageProcessor.from_pretrained(model_id)

image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")

inputs = processor(images=image, return_tensors="pt").to(model.device)

Expand Down Expand Up @@ -463,7 +458,7 @@ def test_instance_segmentation_inference(self):
self.assertTrue(0.0 <= info["score"] <= 1.0)

def test_segmentation_pipeline(self):
image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = load_coco_image("000000039769.jpg")

model = EomtDinov3ForUniversalSegmentation.from_pretrained(self.model_id, device_map="auto")
processor = AutoImageProcessor.from_pretrained(self.model_id)
Expand Down
14 changes: 4 additions & 10 deletions tests/models/fast_vlm/test_modeling_fast_vlm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@
import copy
import unittest

import requests

from transformers import (
AutoProcessor,
FastVlmConfig,
FastVlmForConditionalGeneration,
FastVlmModel,
is_torch_available,
is_vision_available,
)
from transformers.testing_utils import (
Expectations,
Expand All @@ -38,17 +35,14 @@

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_image_processing_common import load_coco_image, load_test_image
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor


if is_torch_available():
import torch


if is_vision_available():
from PIL import Image


class FastVlmVisionText2TextModelTester:
def __init__(
self,
Expand Down Expand Up @@ -257,7 +251,7 @@ def test_small_model_integration_test(self):

prompt = "user\n<image>\nWhat are the things I should be cautious about when I visit this place?\nassistant"
image_file = "https://llava-vl.github.io/static/images/view.jpg"
raw_image = Image.open(requests.get(image_file, stream=True).raw)
raw_image = load_test_image(image_file)
inputs = self.processor(images=raw_image, text=prompt, return_tensors="pt").to(torch_device, dtype=model.dtype)

output = model.generate(**inputs, max_new_tokens=20)
Expand All @@ -281,8 +275,8 @@ def test_small_model_integration_test_batch(self):
"user\n<image>\nWhat are the things I should be cautious about when I visit this place? What should I bring with me?\nassistant",
"user\n<image>\nWhat is this?\nassistant",
]
image1 = Image.open(requests.get("https://llava-vl.github.io/static/images/view.jpg", stream=True).raw)
image2 = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image1 = load_test_image("https://llava-vl.github.io/static/images/view.jpg")
image2 = load_coco_image("000000039769.jpg")

self.processor.tokenizer.padding_side = "left"
inputs = self.processor(images=[image1, image2], text=prompts, return_tensors="pt", padding=True).to(
Expand Down
Loading
Loading