




import operator as op


__a							     =					'scaler.pt'
__a							     =					'pytorch_model'
__a							     =					'random_states'
__a							     =					'optimizer'
__a							     =					'scheduler'
__a							     =					'pytorch_model.bin'
__a							     =					'pytorch_model.bin.index.json'
__a							     =					'model.safetensors'
__a							     =					'model.safetensors.index.json'
__a							     =					'1.10.2'
__a							     =					'py38'
__a							     =					'4.17.0'
__a							     =					['ml.p3.16xlarge', 'ml.p3dn.24xlarge', 'ml.p4dn.24xlarge']
__a							     =					['FULL_SHARD', 'SHARD_GRAD_OP', 'NO_SHARD', 'HYBRID_SHARD', 'HYBRID_SHARD_ZERO2']
__a							     =					['TRANSFORMER_BASED_WRAP', 'SIZE_BASED_WRAP', 'NO_WRAP']
__a							     =					['BACKWARD_PRE', 'BACKWARD_POST', 'NO_PREFETCH']
__a							     =					['FULL_STATE_DICT', 'LOCAL_STATE_DICT', 'SHARDED_STATE_DICT']
__a							     =					'2.0.1'
__a							     =					['pdsh', 'standard', 'openmpi', 'mvapich']
__a							     =					['default', 'reduce-overhead', 'max-autotune']

__a							     =					{'>': op.gt, '>=': op.ge, '==': op.eq, '!=': op.ne, '<=': op.le, '<': op.lt}

# These are the args for `torch.distributed.launch` for pytorch < 1.9
__a							     =					[
    'nnodes',
    'nproc_per_node',
    'rdzv_backend',
    'rdzv_endpoint',
    'rdzv_id',
    'rdzv_conf',
    'standalone',
    'max_restarts',
    'monitor_interval',
    'start_method',
    'role',
    'module',
    'm',
    'no_python',
    'run_path',
    'log_dir',
    'r',
    'redirects',
    't',
    'tee',
    'node_rank',
    'master_addr',
    'master_port',
]

__a							     =					['DEEPSPEED', 'MULTI_GPU', 'FSDP', 'MEGATRON_LM']
__a							     =					['DEEPSPEED', 'MULTI_XPU', 'FSDP']





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 PoolFormerImageProcessor

class     __a(	unittest.TestCase  ):






    """simple docstring"""





    def __init__( self  ,_SCREAMING_SNAKE_CASE  ,_SCREAMING_SNAKE_CASE=7  ,_SCREAMING_SNAKE_CASE=3  ,_SCREAMING_SNAKE_CASE=30  ,_SCREAMING_SNAKE_CASE=400  ,_SCREAMING_SNAKE_CASE=True  ,_SCREAMING_SNAKE_CASE=None  ,_SCREAMING_SNAKE_CASE=0.9  ,_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]  ,)					->						Optional[int]:
         UpperCAmelCase_     :				int  =     size if size is not None else {'''shortest_edge''': 30}
         UpperCAmelCase_     :				List[str]  =     crop_size if crop_size is not None else {'''height''': 30, '''width''': 30}
         UpperCAmelCase_     :				Dict  =     parent
         UpperCAmelCase_     :				int  =     batch_size
         UpperCAmelCase_     :				int  =     num_channels
         UpperCAmelCase_     :				Any  =     min_resolution
         UpperCAmelCase_     :				Tuple  =     max_resolution
         UpperCAmelCase_     :				Optional[int]  =     do_resize_and_center_crop
         UpperCAmelCase_     :				Tuple  =     size
         UpperCAmelCase_     :				List[str]  =     crop_pct
         UpperCAmelCase_     :				List[str]  =     crop_size
         UpperCAmelCase_     :				Any  =     do_normalize
         UpperCAmelCase_     :				str  =     image_mean
         UpperCAmelCase_     :				List[Any]  =     image_std





    def 				a__ ( self    )					->						str:
         return {
             "size": self.size,
             "do_resize_and_center_crop": self.do_resize_and_center_crop,
             "crop_pct": self.crop_pct,
             "crop_size": self.crop_size,
             "do_normalize": self.do_normalize,
             "image_mean": self.image_mean,
             "image_std": self.image_std,
         }


@require_torch
@require_vision
class     __a(	_a							,		unittest.TestCase  ):






    """simple docstring"""





    lowerCAmelCase         = PoolFormerImageProcessor if is_vision_available() else None





    def 				a__ ( self    )					->						Dict:
         UpperCAmelCase_     :				str  =     PoolFormerImageProcessingTester(self    )





    @property
    def 				a__ ( self    )					->						Optional[int]:
         return self.image_processor_tester.prepare_image_processor_dict()





    def 				a__ ( self    )					->						Optional[int]:
         UpperCAmelCase_     :				List[Any]  =     self.image_processing_class(**self.image_processor_dict    )
         self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE  ,'''do_resize_and_center_crop'''    )    )
         self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE  ,'''size'''    )    )
         self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE  ,'''crop_pct'''    )    )
         self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE  ,'''do_normalize'''    )    )
         self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE  ,'''image_mean'''    )    )
         self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE  ,'''image_std'''    )    )





    def 				a__ ( self    )					->						Union[str, Any]:
         UpperCAmelCase_     :				Any  =     self.image_processing_class.from_dict(self.image_processor_dict    )
         self.assertEqual(image_processor.size  ,{'''shortest_edge''': 30}    )
         self.assertEqual(image_processor.crop_size  ,{'''height''': 30, '''width''': 30}    )

         UpperCAmelCase_     :				Optional[Any]  =     self.image_processing_class.from_dict(self.image_processor_dict  ,size=42  ,crop_size=84    )
         self.assertEqual(image_processor.size  ,{'''shortest_edge''': 42}    )
         self.assertEqual(image_processor.crop_size  ,{'''height''': 84, '''width''': 84}    )





    def 				a__ ( self    )					->						Optional[int]:
         pass





    def 				a__ ( self    )					->						Dict:
         # Initialize image_processing
         UpperCAmelCase_     :				str  =     self.image_processing_class(**self.image_processor_dict    )
         # create random PIL images
         UpperCAmelCase_     :				int  =     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_     :				Optional[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.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )  ,)

         # Test batched
         UpperCAmelCase_     :				Union[str, 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.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )  ,)





    def 				a__ ( self    )					->						List[Any]:
         # Initialize image_processing
         UpperCAmelCase_     :				Any  =     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_     :				Tuple  =     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.crop_size['''height'''],
                 self.image_processor_tester.crop_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.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )  ,)





    def 				a__ ( self    )					->						Union[str, Any]:
         # Initialize image_processing
         UpperCAmelCase_     :				List[Any]  =     self.image_processing_class(**self.image_processor_dict    )
         # create random PyTorch tensors
         UpperCAmelCase_     :				Optional[Any]  =     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_     :				Tuple  =     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.crop_size['''height'''],
                 self.image_processor_tester.crop_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.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )  ,)