

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 MobileNetVaImageProcessor

class 				UpperCAmelCase_		(			unittest.TestCase   ):
							"""simple docstring"""







							def __init__(			self       ,							_a       ,							_a=7       ,							_a=3       ,							_a=1_8       ,							_a=3_0       ,							_a=4_0_0       ,							_a=True       ,							_a=None       ,							_a=True       ,							_a=None       ,							)    ->    int:
												_a	:    Optional[int]         =		size if size is not None else {'''shortest_edge''': 2_0}
												_a	:    Optional[int]         =		crop_size if crop_size is not None else {'''height''': 1_8, '''width''': 1_8}
												_a	:    Dict         =		parent
												_a	:    Any         =		batch_size
												_a	:    int         =		num_channels
												_a	:    List[Any]         =		image_size
												_a	:    Any         =		min_resolution
												_a	:    List[str]         =		max_resolution
												_a	:    Tuple         =		do_resize
												_a	:    Optional[Any]         =		size
												_a	:    Tuple         =		do_center_crop
												_a	:    Dict         =		crop_size




							def 				__lowercase				(			self       )    ->    Tuple:
												return {
												    "do_resize": self.do_resize,
												    "size": self.size,
												    "do_center_crop": self.do_center_crop,
												    "crop_size": self.crop_size,
												}



@require_torch
@require_vision
class 				UpperCAmelCase_		(			__lowercase				,       unittest.TestCase   ):
							"""simple docstring"""







							UpperCAmelCase__       :						List[str]	    =    MobileNetVaImageProcessor if is_vision_available() else None


							def 				__lowercase				(			self       )    ->    Any:
												_a	:    str         =		MobileNetVaImageProcessingTester(self       )


							@property
							def 				__lowercase				(			self       )    ->    List[Any]:
												return self.image_processor_tester.prepare_image_processor_dict()


							def 				__lowercase				(			self       )    ->    List[Any]:
												_a	:    Optional[Any]         =		self.image_processing_class(**self.image_processor_dict       )
												self.assertTrue(hasattr(_a       ,							'''do_resize'''       )       )
												self.assertTrue(hasattr(_a       ,							'''size'''       )       )
												self.assertTrue(hasattr(_a       ,							'''do_center_crop'''       )       )
												self.assertTrue(hasattr(_a       ,							'''crop_size'''       )       )


							def 				__lowercase				(			self       )    ->    Tuple:
												_a	:    Union[str, Any]         =		self.image_processing_class.from_dict(self.image_processor_dict       )
												self.assertEqual(image_processor.size       ,							{'''shortest_edge''': 2_0}       )
												self.assertEqual(image_processor.crop_size       ,							{'''height''': 1_8, '''width''': 1_8}       )

												_a	:    Tuple         =		self.image_processing_class.from_dict(self.image_processor_dict       ,							size=4_2       ,							crop_size=8_4       )
												self.assertEqual(image_processor.size       ,							{'''shortest_edge''': 4_2}       )
												self.assertEqual(image_processor.crop_size       ,							{'''height''': 8_4, '''width''': 8_4}       )


							def 				__lowercase				(			self       )    ->    List[str]:
												pass


							def 				__lowercase				(			self       )    ->    Dict:
												# Initialize image_processing
												_a	:    Union[str, Any]         =		self.image_processing_class(**self.image_processor_dict       )
												# create random PIL images
												_a	:    Dict         =		prepare_image_inputs(self.image_processor_tester       ,							equal_resolution=_a       )
												for image in image_inputs:
																	self.assertIsInstance(_a       ,							Image.Image       )

												# Test not batched input
												_a	:    List[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.crop_size['''height'''],
												        self.image_processor_tester.crop_size['''width'''],
												    )       ,							)

												# Test batched
												_a	:    Tuple         =		image_processing(_a       ,							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 				__lowercase				(			self       )    ->    Any:
												# Initialize image_processing
												_a	:    List[Any]         =		self.image_processing_class(**self.image_processor_dict       )
												# create random numpy tensors
												_a	:    List[Any]         =		prepare_image_inputs(self.image_processor_tester       ,							equal_resolution=_a       ,							numpify=_a       )
												for image in image_inputs:
																	self.assertIsInstance(_a       ,							np.ndarray       )

												# Test not batched input
												_a	:    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.crop_size['''height'''],
												        self.image_processor_tester.crop_size['''width'''],
												    )       ,							)

												# Test batched
												_a	:    Any         =		image_processing(_a       ,							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 				__lowercase				(			self       )    ->    Any:
												# Initialize image_processing
												_a	:    Optional[Any]         =		self.image_processing_class(**self.image_processor_dict       )
												# create random PyTorch tensors
												_a	:    Optional[int]         =		prepare_image_inputs(self.image_processor_tester       ,							equal_resolution=_a       ,							torchify=_a       )
												for image in image_inputs:
																	self.assertIsInstance(_a       ,							torch.Tensor       )

												# Test not batched input
												_a	:    Dict         =		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
												_a	:    Union[str, Any]         =		image_processing(_a       ,							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'''],
												    )       ,							)






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''']



