Au revoir flaky test_fast_is_faster_than_slow (#36240)

* fix

* fix

* fix

---------

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
This commit is contained in:
Yih-Dar
2025-02-17 18:30:07 +01:00
committed by GitHub
parent 429f1a682d
commit 626666c444
2 changed files with 22 additions and 4 deletions

View File

@@ -223,9 +223,14 @@ class ImageProcessingTestMixin:
# Warmup
for _ in range(5):
_ = image_processor(image, return_tensors="pt")
start = time.time()
_ = image_processor(image, return_tensors="pt")
return time.time() - start
all_times = []
for _ in range(10):
start = time.time()
_ = image_processor(image, return_tensors="pt")
all_times.append(time.time() - start)
# Take the average of the fastest 3 runs
avg_time = sum(sorted(all_times[:3])) / 3.0
return avg_time
dummy_images = torch.randint(0, 255, (4, 3, 224, 224), dtype=torch.uint8)
image_processor_slow = self.image_processing_class(**self.image_processor_dict)