code: 
  
  
  
  
  
  
  import unittest
  
  import numpy as np
  
  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 ImageProcessingSavingTestMixin, prepare_image_inputs
  
  
  if is_torch_available():
  	import torch
  
  if is_vision_available():
  	from PIL import Image
  
  	from transformers import ViTImageProcessor
  
  
  
  
  
  
  
  class     UpperCAmelCase_		(      unittest.TestCase				):
  
  
  
  						"""simple docstring"""
  						def __init__(       self					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_=7					,       SCREAMING_SNAKE_CASE_=3					,       SCREAMING_SNAKE_CASE_=18					,       SCREAMING_SNAKE_CASE_=30					,       SCREAMING_SNAKE_CASE_=400					,       SCREAMING_SNAKE_CASE_=True					,       SCREAMING_SNAKE_CASE_=None					,       SCREAMING_SNAKE_CASE_=True					,       SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5]					,       SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5]					,       )       ->   str:
  										UpperCamelCase :Optional[int]										=     size if size is not None else {'''height''': 18, '''width''': 18}
  										UpperCamelCase :int										=     parent
  										UpperCamelCase :Any										=     batch_size
  										UpperCamelCase :Optional[Any]										=     num_channels
  										UpperCamelCase :List[Any]										=     image_size
  										UpperCamelCase :Optional[Any]										=     min_resolution
  										UpperCamelCase :Any										=     max_resolution
  										UpperCamelCase :Optional[int]										=     do_resize
  										UpperCamelCase :Tuple										=     size
  										UpperCamelCase :Union[str, Any]										=     do_normalize
  										UpperCamelCase :int										=     image_mean
  										UpperCamelCase :Dict										=     image_std
  
  
  
  
  						def 					UpperCAmelCase		(       self				)       ->   str:
  										return {
  										    "image_mean": self.image_mean,
  										    "image_std": self.image_std,
  										    "do_normalize": self.do_normalize,
  										    "do_resize": self.do_resize,
  										    "size": self.size,
  										}
  
  
  
  
  
  
  
  @require_torch
  @require_vision
  class     UpperCAmelCase_		(      lowercase,			unittest.TestCase				):
  
  
  
  						"""simple docstring"""
  						UpperCamelCase_       :      str     =ViTImageProcessor if is_vision_available() else None
  						def 					UpperCAmelCase		(       self				)       ->   Any:
  										UpperCamelCase :str										=     ViTImageProcessingTester(self				)
  						@property
  						def 					UpperCAmelCase		(       self				)       ->   Optional[int]:
  										return self.image_processor_tester.prepare_image_processor_dict()
  						def 					UpperCAmelCase		(       self				)       ->   List[Any]:
  										UpperCamelCase :Dict										=     self.image_processing_class(**self.image_processor_dict				)
  										self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_					,       '''image_mean'''				)				)
  										self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_					,       '''image_std'''				)				)
  										self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_					,       '''do_normalize'''				)				)
  										self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_					,       '''do_resize'''				)				)
  										self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_					,       '''size'''				)				)
  						def 					UpperCAmelCase		(       self				)       ->   Tuple:
  										UpperCamelCase :Any										=     self.image_processing_class.from_dict(self.image_processor_dict				)
  										self.assertEqual(image_processor.size					,       {'''height''': 18, '''width''': 18}				)
  
  										UpperCamelCase :int										=     self.image_processing_class.from_dict(self.image_processor_dict					,       size=42				)
  										self.assertEqual(image_processor.size					,       {'''height''': 42, '''width''': 42}				)
  						def 					UpperCAmelCase		(       self				)       ->   str:
  										pass
  						def 					UpperCAmelCase		(       self				)       ->   Union[str, Any]:
  										# Initialize image_processing
  										UpperCamelCase :Union[str, Any]										=     self.image_processing_class(**self.image_processor_dict				)
  										# create random PIL images
  										UpperCamelCase :List[str]										=     prepare_image_inputs(self.image_processor_tester					,       equal_resolution=SCREAMING_SNAKE_CASE_				)
  										for image in image_inputs:
  														self.assertIsInstance(SCREAMING_SNAKE_CASE_					,       Image.Image				)
  
  										# Test not batched input
  										UpperCamelCase :str										=     image_processing(image_inputs[0]					,       return_tensors='''pt'''				).pixel_values
  										self.assertEqual(
  										    encoded_images.shape					,       (
  										        1,
  										        self.image_processor_tester.num_channels,
  										        self.image_processor_tester.size['''height'''],
  										        self.image_processor_tester.size['''width'''],
  										    )					,       )
  
  										# Test batched
  										UpperCamelCase :Dict										=     image_processing(SCREAMING_SNAKE_CASE_					,       return_tensors='''pt'''				).pixel_values
  										self.assertEqual(
  										    encoded_images.shape					,       (
  										        self.image_processor_tester.batch_size,
  										        self.image_processor_tester.num_channels,
  										        self.image_processor_tester.size['''height'''],
  										        self.image_processor_tester.size['''width'''],
  										    )					,       )
  						def 					UpperCAmelCase		(       self				)       ->   str:
  										# Initialize image_processing
  										UpperCamelCase :Optional[int]										=     self.image_processing_class(**self.image_processor_dict				)
  										# create random numpy tensors
  										UpperCamelCase :List[str]										=     prepare_image_inputs(self.image_processor_tester					,       equal_resolution=SCREAMING_SNAKE_CASE_					,       numpify=SCREAMING_SNAKE_CASE_				)
  										for image in image_inputs:
  														self.assertIsInstance(SCREAMING_SNAKE_CASE_					,       np.ndarray				)
  
  										# Test not batched input
  										UpperCamelCase :List[Any]										=     image_processing(image_inputs[0]					,       return_tensors='''pt'''				).pixel_values
  										self.assertEqual(
  										    encoded_images.shape					,       (
  										        1,
  										        self.image_processor_tester.num_channels,
  										        self.image_processor_tester.size['''height'''],
  										        self.image_processor_tester.size['''width'''],
  										    )					,       )
  
  										# Test batched
  										UpperCamelCase :List[Any]										=     image_processing(SCREAMING_SNAKE_CASE_					,       return_tensors='''pt'''				).pixel_values
  										self.assertEqual(
  										    encoded_images.shape					,       (
  										        self.image_processor_tester.batch_size,
  										        self.image_processor_tester.num_channels,
  										        self.image_processor_tester.size['''height'''],
  										        self.image_processor_tester.size['''width'''],
  										    )					,       )
  
  
  
  
  						def 					UpperCAmelCase		(       self				)       ->   str:
  										# Initialize image_processing
  										UpperCamelCase :Union[str, Any]										=     self.image_processing_class(**self.image_processor_dict				)
  										# create random PyTorch tensors
  										UpperCamelCase :Tuple										=     prepare_image_inputs(self.image_processor_tester					,       equal_resolution=SCREAMING_SNAKE_CASE_					,       torchify=SCREAMING_SNAKE_CASE_				)
  										for image in image_inputs:
  														self.assertIsInstance(SCREAMING_SNAKE_CASE_					,       torch.Tensor				)
  
  										# Test not batched input
  										UpperCamelCase :int										=     image_processing(image_inputs[0]					,       return_tensors='''pt'''				).pixel_values
  										self.assertEqual(
  										    encoded_images.shape					,       (
  										        1,
  										        self.image_processor_tester.num_channels,
  										        self.image_processor_tester.size['''height'''],
  										        self.image_processor_tester.size['''width'''],
  										    )					,       )
  
  										# Test batched
  										UpperCamelCase :Optional[Any]										=     image_processing(SCREAMING_SNAKE_CASE_					,       return_tensors='''pt'''				).pixel_values
  										self.assertEqual(
  										    encoded_images.shape					,       (
  										        self.image_processor_tester.batch_size,
  										        self.image_processor_tester.num_channels,
  										        self.image_processor_tester.size['''height'''],
  										        self.image_processor_tester.size['''width'''],
  										    )					,       )
  
  
  
  
  
  
style_context: 
  
  
  
  
  
  
  # as due to their complexity multi-gpu tests could impact other tests, and to aid debug we have those in a separate module.
  
  import os
  import sys
  
  from transformers.testing_utils import TestCasePlus, execute_subprocess_async, get_gpu_count, require_torch_gpu, slow
  
  from .utils import load_json
  
  
  
  
  
  
  
  class     UpperCAmelCase_		(      lowercase				):
  
  
  
        """simple docstring"""
        @classmethod
        def 					UpperCAmelCase		(       cls				)       ->   List[Any]:
            return cls
  
  
  
  
        @slow
        @require_torch_gpu
        def 					UpperCAmelCase		(       self				)       ->   int:
            UpperCamelCase :int										=     self.get_auto_remove_tmp_dir()
            UpperCamelCase :List[str]										=     F'''
              --model_name Helsinki-NLP/opus-mt-en-ro
              --save_dir {output_dir}
              --data_dir {self.test_file_dir_str}/test_data/wmt_en_ro
              --num_beams 2
              --task translation
          '''.split()
  
            # we want this test to run even if there is only one GPU, but if there are more we use them all
            UpperCamelCase :List[str]										=     get_gpu_count()
            UpperCamelCase :Optional[Any]										=     F'''
              -m torch.distributed.launch
              --nproc_per_node={n_gpu}
              {self.test_file_dir}/run_distributed_eval.py
          '''.split()
            UpperCamelCase :List[Any]										=     [sys.executable] + distributed_args + args
            execute_subprocess_async(SCREAMING_SNAKE_CASE_					,       env=self.get_env()				)
  
            UpperCamelCase :Tuple										=     os.path.join(SCREAMING_SNAKE_CASE_					,       '''test_bleu.json'''				)
            UpperCamelCase :str										=     load_json(SCREAMING_SNAKE_CASE_				)
            # print(metrics)
            self.assertGreaterEqual(metrics['''bleu''']					,       25				)
  
  
  
  
  
  