





'''simple docstring'''







import inspect
import unittest
from math import floor

from transformers import CvtConfig
from transformers.file_utils import cached_property, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import CvtForImageClassification, CvtModel
					from transformers.models.cvt.modeling_cvt import CVT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
					from PIL import Image

					from transformers import AutoImageProcessor


class 					__a      (lowerCamelCase     ):

							def     UpperCAmelCase__	(							self							:     Optional[int]   )					->       Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Optional[Any]     						=  self.config_class(**self.inputs_dict   )
													self.parent.assertTrue(hasattr(__magic_name__       ,     '''embed_dim'''   )   )
													self.parent.assertTrue(hasattr(__magic_name__       ,     '''num_heads'''   )   )





class 					__a      :

							def __init__(							self							:     List[str]       ,     __magic_name__							:     Dict       ,     __magic_name__							:     Tuple=13       ,     __magic_name__							:     Any=64       ,     __magic_name__							:     Optional[Any]=3       ,     __magic_name__							:     Tuple=[16, 48, 96]       ,     __magic_name__							:     Optional[Any]=[1, 3, 6]       ,     __magic_name__							:     str=[1, 2, 10]       ,     __magic_name__							:     str=[7, 3, 3]       ,     __magic_name__							:     Dict=[4, 2, 2]       ,     __magic_name__							:     Any=[2, 1, 1]       ,     __magic_name__							:     str=[2, 2, 2]       ,     __magic_name__							:     Union[str, Any]=[False, False, True]       ,     __magic_name__							:     Dict=[0.0, 0.0, 0.0]       ,     __magic_name__							:     Optional[int]=0.0_2       ,     __magic_name__							:     Dict=1E-12       ,     __magic_name__							:     Optional[Any]=True       ,     __magic_name__							:     List[str]=True       ,     __magic_name__							:     int=2       ,     )					->       List[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      int     						=  parent
													UpperCAmelCase_			:      int     						=  batch_size
													UpperCAmelCase_			:      Dict     						=  image_size
													UpperCAmelCase_			:      Tuple     						=  patch_sizes
													UpperCAmelCase_			:      List[Any]     						=  patch_stride
													UpperCAmelCase_			:      Dict     						=  patch_padding
													UpperCAmelCase_			:      Union[str, Any]     						=  is_training
													UpperCAmelCase_			:      Optional[Any]     						=  use_labels
													UpperCAmelCase_			:      Union[str, Any]     						=  num_labels
													UpperCAmelCase_			:      Any     						=  num_channels
													UpperCAmelCase_			:      Union[str, Any]     						=  embed_dim
													UpperCAmelCase_			:      str     						=  num_heads
													UpperCAmelCase_			:      int     						=  stride_kv
													UpperCAmelCase_			:      Any     						=  depth
													UpperCAmelCase_			:      Tuple     						=  cls_token
													UpperCAmelCase_			:      str     						=  attention_drop_rate
													UpperCAmelCase_			:      Any     						=  initializer_range
													UpperCAmelCase_			:      Optional[Any]     						=  layer_norm_eps

							def     UpperCAmelCase__	(							self							:     int   )					->       Any:







													"""simple docstring"""
													UpperCAmelCase_			:      List[Any]     						=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]   )

													UpperCAmelCase_			:      Any     						=  None
													if self.use_labels:
																			UpperCAmelCase_			:      int     						=  ids_tensor([self.batch_size]       ,     self.num_labels   )

													UpperCAmelCase_			:      int     						=  self.get_config()
													return config, pixel_values, labels

							def     UpperCAmelCase__	(							self							:     str   )					->       Optional[Any]:







													"""simple docstring"""
													return CvtConfig(
													    image_size=self.image_size       ,     num_labels=self.num_labels       ,     num_channels=self.num_channels       ,     embed_dim=self.embed_dim       ,     num_heads=self.num_heads       ,     patch_sizes=self.patch_sizes       ,     patch_padding=self.patch_padding       ,     patch_stride=self.patch_stride       ,     stride_kv=self.stride_kv       ,     depth=self.depth       ,     cls_token=self.cls_token       ,     attention_drop_rate=self.attention_drop_rate       ,     initializer_range=self.initializer_range       ,     )

							def     UpperCAmelCase__	(							self							:     str       ,     __magic_name__							:     Any       ,     __magic_name__							:     Tuple       ,     __magic_name__							:     Dict   )					->       List[str]:







													"""simple docstring"""
													UpperCAmelCase_			:      int     						=  CvtModel(config=__magic_name__   )
													model.to(__magic_name__   )
													model.eval()
													UpperCAmelCase_			:      Any     						=  model(__magic_name__   )
													UpperCAmelCase_			:      Optional[int]     						=  (self.image_size, self.image_size)
													UpperCAmelCase_						,       UpperCAmelCase_			:      Optional[Any]     						=  image_size[0], image_size[1]
													for i in range(len(self.depth   )   ):
																			UpperCAmelCase_			:      Tuple     						=  floor(((height + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1   )
																			UpperCAmelCase_			:      List[Any]     						=  floor(((width + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1   )
													self.parent.assertEqual(result.last_hidden_state.shape       ,     (self.batch_size, self.embed_dim[-1], height, width)   )

							def     UpperCAmelCase__	(							self							:     int       ,     __magic_name__							:     Optional[int]       ,     __magic_name__							:     Any       ,     __magic_name__							:     int   )					->       Tuple:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  self.num_labels
													UpperCAmelCase_			:      List[str]     						=  CvtForImageClassification(__magic_name__   )
													model.to(__magic_name__   )
													model.eval()
													UpperCAmelCase_			:      str     						=  model(__magic_name__       ,     labels=__magic_name__   )
													self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.num_labels)   )



							def     UpperCAmelCase__	(							self							:     Optional[Any]   )					->       Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  self.prepare_config_and_inputs()
													UpperCAmelCase_						,       UpperCAmelCase_						,       UpperCAmelCase_			:      List[str]     						=  config_and_inputs
													UpperCAmelCase_			:      Union[str, Any]     						=  {'''pixel_values''': pixel_values}
													return config, inputs_dict





@require_torch
class 					__a      (lowerCamelCase       ,		lowerCamelCase       ,		unittest.TestCase     ):
							__a					:   Union[str, Any]									=       (CvtModel, CvtForImageClassification) if is_torch_available() else ()
							__a					:   Union[str, Any]									=       (
							    {"feature-extraction": CvtModel, "image-classification": CvtForImageClassification}
							    if is_torch_available()
							    else {}
							)

							__a					:   Dict									=       False
							__a					:   List[Any]									=       False
							__a					:   Optional[Any]									=       False
							__a					:   List[str]									=       False
							__a					:   str									=       False

							def     UpperCAmelCase__	(							self							:     Dict   )					->       str:







													"""simple docstring"""
													UpperCAmelCase_			:      int     						=  CvtModelTester(self   )
													UpperCAmelCase_			:      Optional[Any]     						=  ConfigTester(self       ,     config_class=__magic_name__       ,     has_text_modality=__magic_name__       ,     hidden_size=37   )

							def     UpperCAmelCase__	(							self							:     int   )					->       Optional[int]:







													"""simple docstring"""
													self.create_and_test_config_common_properties()
													self.config_tester.create_and_test_config_to_json_string()
													self.config_tester.create_and_test_config_to_json_file()
													self.config_tester.create_and_test_config_from_and_save_pretrained()
													self.config_tester.create_and_test_config_with_num_labels()
													self.config_tester.check_config_can_be_init_without_params()
													self.config_tester.check_config_arguments_init()

							def     UpperCAmelCase__	(							self							:     str   )					->       Optional[int]:







													"""simple docstring"""
													return

							@unittest.skip(reason='''Cvt does not output attentions'''   )
							def     UpperCAmelCase__	(							self							:     Optional[int]   )					->       Tuple:







													"""simple docstring"""
													pass

							@unittest.skip(reason='''Cvt does not use inputs_embeds'''   )
							def     UpperCAmelCase__	(							self							:     List[str]   )					->       Optional[Any]:







													"""simple docstring"""
													pass

							@unittest.skip(reason='''Cvt does not support input and output embeddings'''   )
							def     UpperCAmelCase__	(							self							:     List[Any]   )					->       Optional[Any]:







													"""simple docstring"""
													pass

							def     UpperCAmelCase__	(							self							:     Any   )					->       int:







													"""simple docstring"""
													UpperCAmelCase_						,       UpperCAmelCase_			:      Any     						=  self.model_tester.prepare_config_and_inputs_for_common()

													for model_class in self.all_model_classes:
																			UpperCAmelCase_			:      Optional[int]     						=  model_class(__magic_name__   )
																			UpperCAmelCase_			:      Optional[Any]     						=  inspect.signature(model.forward   )
																			# signature.parameters is an OrderedDict => so arg_names order is deterministic
																			UpperCAmelCase_			:      str     						=  [*signature.parameters.keys()]

																			UpperCAmelCase_			:      Optional[int]     						=  ['''pixel_values''']
																			self.assertListEqual(arg_names[:1]       ,     __magic_name__   )

							def     UpperCAmelCase__	(							self							:     Optional[int]   )					->       Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      str     						=  self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*__magic_name__   )

							def     UpperCAmelCase__	(							self							:     Union[str, Any]   )					->       str:







													"""simple docstring"""
													def check_hidden_states_output(__magic_name__							:     List[str]       ,     __magic_name__							:     List[str]       ,     __magic_name__							:     int   ):
																			UpperCAmelCase_			:      List[Any]     						=  model_class(__magic_name__   )
																			model.to(__magic_name__   )
																			model.eval()

																			with torch.no_grad():
																									UpperCAmelCase_			:      Any     						=  model(**self._prepare_for_class(__magic_name__       ,     __magic_name__   )   )

																			UpperCAmelCase_			:      Optional[Any]     						=  outputs.hidden_states

																			UpperCAmelCase_			:      List[str]     						=  len(self.model_tester.depth   )
																			self.assertEqual(len(__magic_name__   )       ,     __magic_name__   )

																			# verify the first hidden states (first block)
																			self.assertListEqual(
																			    list(hidden_states[0].shape[-3:]   )       ,     [
																			        self.model_tester.embed_dim[0],
																			        self.model_tester.image_size // 4,
																			        self.model_tester.image_size // 4,
																			    ]       ,     )

													UpperCAmelCase_						,       UpperCAmelCase_			:      str     						=  self.model_tester.prepare_config_and_inputs_for_common()

													for model_class in self.all_model_classes:
																			UpperCAmelCase_			:      Dict     						=  True
																			check_hidden_states_output(__magic_name__       ,     __magic_name__       ,     __magic_name__   )

																			# check that output_hidden_states also work using config
																			del inputs_dict["output_hidden_states"]
																			UpperCAmelCase_			:      Any     						=  True

																			check_hidden_states_output(__magic_name__       ,     __magic_name__       ,     __magic_name__   )

							def     UpperCAmelCase__	(							self							:     Dict   )					->       Dict:







													"""simple docstring"""
													UpperCAmelCase_			:      List[str]     						=  self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_image_classification(*__magic_name__   )

							@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''   )
							def     UpperCAmelCase__	(							self							:     Tuple   )					->       Tuple:







													"""simple docstring"""
													pass



							@slow
							def     UpperCAmelCase__	(							self							:     str   )					->       List[Any]:







													"""simple docstring"""
													for model_name in CVT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			UpperCAmelCase_			:      List[Any]     						=  CvtModel.from_pretrained(__magic_name__   )
																			self.assertIsNotNone(__magic_name__   )





def        lowerCamelCase_      (  ) ->	str:
						UpperCAmelCase_			:      str     						=  Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''   )
						return image


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

							@cached_property
							def     UpperCAmelCase__	(							self							:     str   )					->       List[Any]:







													"""simple docstring"""
													return AutoImageProcessor.from_pretrained(CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]   )



							@slow
							def     UpperCAmelCase__	(							self							:     List[Any]   )					->       str:







													"""simple docstring"""
													UpperCAmelCase_			:      List[Any]     						=  CvtForImageClassification.from_pretrained(CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]   ).to(__magic_name__   )

													UpperCAmelCase_			:      List[Any]     						=  self.default_image_processor
													UpperCAmelCase_			:      Any     						=  prepare_img()
													UpperCAmelCase_			:      Any     						=  image_processor(images=__magic_name__       ,     return_tensors='''pt'''   ).to(__magic_name__   )

													# forward pass
													with torch.no_grad():
																			UpperCAmelCase_			:      str     						=  model(**__magic_name__   )

													# verify the logits
													UpperCAmelCase_			:      Dict     						=  torch.Size((1, 10_00)   )
													self.assertEqual(outputs.logits.shape       ,     __magic_name__   )

													UpperCAmelCase_			:      Union[str, Any]     						=  torch.tensor([0.9_2_8_5, 0.9_0_1_5, -0.3_1_5_0]   ).to(__magic_name__   )

													self.assertTrue(torch.allclose(outputs.logits[0, :3]       ,     __magic_name__       ,     atol=1E-4   )   )












'''simple docstring'''







def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			int = 10,			SCREAMING_SNAKE_CASE__      :			int = 22   ) ->	int:
						UpperCAmelCase_			:      Optional[int]     						=  range(1,			SCREAMING_SNAKE_CASE__   )
						UpperCAmelCase_			:      List[Any]     						=  range(1,			SCREAMING_SNAKE_CASE__   )
						return sum(
						    1 for power in powers for base in bases if len(str(base**power   )   ) == power   )


if __name__ == "__main__":
					print(f'''{solution(10, 22) = }''')





