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 DeiTImageProcessor
  
  
  
  
  
  class        lowercase_				( unittest.TestCase):
  
  
  
  
  
  
  							"""simple docstring"""
  
  
  
  
  
  
  
  							def __init__(   self			,    _UpperCAmelCase			,    _UpperCAmelCase=7			,    _UpperCAmelCase=3			,    _UpperCAmelCase=18			,    _UpperCAmelCase=30			,    _UpperCAmelCase=400			,    _UpperCAmelCase=True			,    _UpperCAmelCase=None			,    _UpperCAmelCase=True			,    _UpperCAmelCase=None			,    _UpperCAmelCase=True			,    _UpperCAmelCase=[0.5, 0.5, 0.5]			,    _UpperCAmelCase=[0.5, 0.5, 0.5]			,    ):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													a_					=		size if size is not None else {"""height""": 20, """width""": 20}
  													a_					=		crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
  
  													a_					=		parent
  													a_					=		batch_size
  													a_					=		num_channels
  													a_					=		image_size
  													a_					=		min_resolution
  													a_					=		max_resolution
  													a_					=		do_resize
  													a_					=		size
  													a_					=		do_center_crop
  													a_					=		crop_size
  													a_					=		do_normalize
  													a_					=		image_mean
  													a_					=		image_std
  
  
  
  
  
  
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													return {
  													    "do_resize": self.do_resize,
  													    "size": self.size,
  													    "do_center_crop": self.do_center_crop,
  													    "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        lowercase_				( UpperCamelCase__			,unittest.TestCase):
  
  
  
  
  
  
  							"""simple docstring"""
  
  
  
  
  
  
  
  							snake_case_        =		DeiTImageProcessor if is_vision_available() else None
  							snake_case_        =		True
  
  
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													a_					=		DeiTImageProcessingTester(self		)
  
  
  							@property
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													return self.image_processor_tester.prepare_image_processor_dict()
  
  
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													a_					=		self.image_processing_class(**self.image_processor_dict		)
  													self.assertTrue(hasattr(_UpperCAmelCase			,    """do_resize"""		)		)
  													self.assertTrue(hasattr(_UpperCAmelCase			,    """size"""		)		)
  													self.assertTrue(hasattr(_UpperCAmelCase			,    """do_center_crop"""		)		)
  													self.assertTrue(hasattr(_UpperCAmelCase			,    """center_crop"""		)		)
  													self.assertTrue(hasattr(_UpperCAmelCase			,    """do_normalize"""		)		)
  													self.assertTrue(hasattr(_UpperCAmelCase			,    """image_mean"""		)		)
  													self.assertTrue(hasattr(_UpperCAmelCase			,    """image_std"""		)		)
  
  
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													a_					=		self.image_processing_class.from_dict(self.image_processor_dict		)
  													self.assertEqual(image_processor.size			,    {"""height""": 20, """width""": 20}		)
  													self.assertEqual(image_processor.crop_size			,    {"""height""": 18, """width""": 18}		)
  
  													a_					=		self.image_processing_class.from_dict(self.image_processor_dict			,    size=42			,    crop_size=84		)
  													self.assertEqual(image_processor.size			,    {"""height""": 42, """width""": 42}		)
  													self.assertEqual(image_processor.crop_size			,    {"""height""": 84, """width""": 84}		)
  
  
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													pass
  
  
  							def 						lowercase__     (   self		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													a_					=		self.image_processing_class(**self.image_processor_dict		)
  													# create random PIL images
  													a_					=		prepare_image_inputs(self.image_processor_tester			,    equal_resolution=_UpperCAmelCase		)
  													for image in image_inputs:
  																			self.assertIsInstance(_UpperCAmelCase			,    Image.Image		)
  
  													# Test not batched input
  													a_					=		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_					=		image_processing(_UpperCAmelCase			,    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		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													a_					=		self.image_processing_class(**self.image_processor_dict		)
  													# create random numpy tensors
  													a_					=		prepare_image_inputs(self.image_processor_tester			,    equal_resolution=_UpperCAmelCase			,    numpify=_UpperCAmelCase		)
  													for image in image_inputs:
  																			self.assertIsInstance(_UpperCAmelCase			,    np.ndarray		)
  
  													# Test not batched input
  													a_					=		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_					=		image_processing(_UpperCAmelCase			,    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		):
  
  
  
  
  
  
  
  													"""simple docstring"""
  
  
  													a_					=		self.image_processing_class(**self.image_processor_dict		)
  													# create random PyTorch tensors
  													a_					=		prepare_image_inputs(self.image_processor_tester			,    equal_resolution=_UpperCAmelCase			,    torchify=_UpperCAmelCase		)
  													for image in image_inputs:
  																			self.assertIsInstance(_UpperCAmelCase			,    torch.Tensor		)
  
  													# Test not batched input
  													a_					=		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_					=		image_processing(_UpperCAmelCase			,    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"""],
  													    )			,    )
style_context: 
  
  
  import importlib
  import sys
  from argparse import REMAINDER, ArgumentParser
  from pathlib import Path
  
  import torch_xla.distributed.xla_multiprocessing as xmp
  
  
  
  
  def   lowerCamelCase_       (					):
  
  
  
  						"""simple docstring"""
  
  
  
  
  						a_					=		ArgumentParser(
  						    description=(
  						        """PyTorch TPU distributed training launch helper utility that will spawn up multiple distributed processes"""
  						    )      )
  
  						# Optional arguments for the launch helper
  						parser.add_argument("""--num_cores"""       ,    type=UpperCAmelCase__       ,    default=1       ,    help="""Number of TPU cores to use (1 or 8)."""      )
  
  						# positional
  						parser.add_argument(
  						    """training_script"""       ,    type=UpperCAmelCase__       ,    help=(
  						        """The full path to the single TPU training """
  						        """program/script to be launched in parallel, """
  						        """followed by all the arguments for the """
  						        """training script"""
  						    )       ,    )
  
  						# rest from the training program
  						parser.add_argument("""training_script_args"""       ,    nargs=UpperCAmelCase__      )
  
  						return parser.parse_args()
  
  
  
  
  def   lowerCamelCase_       (					):
  
  
  
  						"""simple docstring"""
  
  
  
  
  						a_					=		parse_args()
  
  						# Import training_script as a module.
  						a_					=		Path(args.training_script      )
  						sys.path.append(str(script_fpath.parent.resolve()      )      )
  						a_					=		script_fpath.stem
  						a_					=		importlib.import_module(UpperCAmelCase__      )
  
  						# Patch sys.argv
  						a_					=		[args.training_script] + args.training_script_args + ["""--tpu_num_cores""", str(args.num_cores      )]
  
  						xmp.spawn(mod._mp_fn       ,    args=()       ,    nprocs=args.num_cores      )
  
  
  if __name__ == "__main__":
  	main()