


"""simple docstring"""





import itertools
import json
import os
import unittest

from transformers import AddedToken, RobertaTokenizer, RobertaTokenizerFast
from transformers.models.roberta.tokenization_roberta import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin




@require_tokenizers
class 			lowercase__			(      UpperCAmelCase_,					unittest.TestCase    ):
							'''simple docstring'''







							_UpperCAmelCase      				=					RobertaTokenizer
							_UpperCAmelCase      				=					RobertaTokenizerFast
							_UpperCAmelCase      				=					True
							_UpperCAmelCase      				=					{"cls_token": "<s>"}






							def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									super().setUp()

									# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
									_UpperCAmelCase							 =		[
									    'l',
									    'o',
									    'w',
									    'e',
									    'r',
									    's',
									    't',
									    'i',
									    'd',
									    'n',
									    '\u0120',
									    '\u0120l',
									    '\u0120n',
									    '\u0120lo',
									    '\u0120low',
									    'er',
									    '\u0120lowest',
									    '\u0120newer',
									    '\u0120wider',
									    '<unk>',
									]
									_UpperCAmelCase							 =		dict(zip(_snake_case	,       range(len(_snake_case						)						)						)						)
									_UpperCAmelCase							 =		['#version: 0.2', '\u0120 l', '\u0120l o', '\u0120lo w', 'e r', '']
									_UpperCAmelCase							 =		{'unk_token': '<unk>'}

									_UpperCAmelCase							 =		os.path.join(self.tmpdirname	,       VOCAB_FILES_NAMES['vocab_file']						)
									_UpperCAmelCase							 =		os.path.join(self.tmpdirname	,       VOCAB_FILES_NAMES['merges_file']						)
									with open(self.vocab_file	,       'w'	,       encoding='utf-8'						) as fp:
											fp.write(json.dumps(_snake_case						) + '\n'						)
									with open(self.merges_file	,       'w'	,       encoding='utf-8'						) as fp:
											fp.write('\n'.join(_snake_case						)						)






							def        lowerCamelCase_   (  self	,       **snake_case						)			->							Any:
									kwargs.update(self.special_tokens_map						)
									return self.tokenizer_class.from_pretrained(self.tmpdirname	,       **_snake_case						)






							def        lowerCamelCase_   (  self	,       **snake_case						)			->							Optional[Any]:
									kwargs.update(self.special_tokens_map						)
									return RobertaTokenizerFast.from_pretrained(self.tmpdirname	,       **_snake_case						)






							def        lowerCamelCase_   (  self	,       snake_case						)			->							Optional[Any]:
									_UpperCAmelCase							 =		'lower newer'
									_UpperCAmelCase							 =		'lower newer'
									return input_text, output_text






							def        lowerCamelCase_   (  self						)			->							Dict:
									_UpperCAmelCase							 =		self.tokenizer_class(self.vocab_file	,       self.merges_file	,       **self.special_tokens_map						)
									_UpperCAmelCase							 =		'lower newer'
									_UpperCAmelCase							 =		['l', 'o', 'w', 'er', '\u0120', 'n', 'e', 'w', 'er']
									_UpperCAmelCase							 =		tokenizer.tokenize(_snake_case						)  # , add_prefix_space=True)
									self.assertListEqual(_snake_case	,       _snake_case						)

									_UpperCAmelCase							 =		tokens + [tokenizer.unk_token]
									_UpperCAmelCase							 =		[0, 1, 2, 15, 10, 9, 3, 2, 15, 19]
									self.assertListEqual(tokenizer.convert_tokens_to_ids(_snake_case						)	,       _snake_case						)






							def        lowerCamelCase_   (  self						)			->							Optional[int]:
									_UpperCAmelCase							 =		self.get_tokenizer()

									self.assertListEqual(tokenizer.encode('Hello world!'	,       add_special_tokens=_snake_case						)	,       [0, 31414, 232, 328, 2]						)
									self.assertListEqual(
									    tokenizer.encode('Hello world! cécé herlolip 418'	,       add_special_tokens=_snake_case						)	,       [0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]	,       )






							@slow
							def        lowerCamelCase_   (  self						)			->							Optional[Any]:
									_UpperCAmelCase							 =		self.tokenizer_class.from_pretrained('roberta-base'						)

									_UpperCAmelCase							 =		tokenizer.encode('sequence builders'	,       add_special_tokens=_snake_case						)
									_UpperCAmelCase							 =		tokenizer.encode('multi-sequence build'	,       add_special_tokens=_snake_case						)

									_UpperCAmelCase							 =		tokenizer.encode(
									    'sequence builders'	,       add_special_tokens=_snake_case	,       add_prefix_space=_snake_case						)
									_UpperCAmelCase							 =		tokenizer.encode(
									    'sequence builders'	,       'multi-sequence build'	,       add_special_tokens=_snake_case	,       add_prefix_space=_snake_case						)

									_UpperCAmelCase							 =		tokenizer.build_inputs_with_special_tokens(_snake_case						)
									_UpperCAmelCase							 =		tokenizer.build_inputs_with_special_tokens(_snake_case	,       _snake_case						)

									assert encoded_sentence == encoded_text_from_decode
									assert encoded_pair == encoded_pair_from_decode






							def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									_UpperCAmelCase							 =		self.get_tokenizer()

									_UpperCAmelCase							 =		'Encode this sequence.'
									_UpperCAmelCase							 =		tokenizer.byte_encoder[' '.encode('utf-8'						)[0]]

									# Testing encoder arguments
									_UpperCAmelCase							 =		tokenizer.encode(_snake_case	,       add_special_tokens=_snake_case	,       add_prefix_space=_snake_case						)
									_UpperCAmelCase							 =		tokenizer.convert_ids_to_tokens(encoded[0]						)[0]
									self.assertNotEqual(_snake_case	,       _snake_case						)

									_UpperCAmelCase							 =		tokenizer.encode(_snake_case	,       add_special_tokens=_snake_case	,       add_prefix_space=_snake_case						)
									_UpperCAmelCase							 =		tokenizer.convert_ids_to_tokens(encoded[0]						)[0]
									self.assertEqual(_snake_case	,       _snake_case						)

									tokenizer.add_special_tokens({'bos_token': '<s>'}						)
									_UpperCAmelCase							 =		tokenizer.encode(_snake_case	,       add_special_tokens=_snake_case						)
									_UpperCAmelCase							 =		tokenizer.convert_ids_to_tokens(encoded[1]						)[0]
									self.assertNotEqual(_snake_case	,       _snake_case						)

									# Testing spaces after special tokens
									_UpperCAmelCase							 =		'<mask>'
									tokenizer.add_special_tokens(
									    {'mask_token': AddedToken(_snake_case	,       lstrip=_snake_case	,       rstrip=_snake_case						)}						)  # mask token has a left space
									_UpperCAmelCase							 =		tokenizer.convert_tokens_to_ids(_snake_case						)

									_UpperCAmelCase							 =		'Encode <mask> sequence'
									_UpperCAmelCase							 =		'Encode <mask>sequence'

									_UpperCAmelCase							 =		tokenizer.encode(_snake_case						)
									_UpperCAmelCase							 =		encoded.index(_snake_case						)
									_UpperCAmelCase							 =		tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]						)[0]
									self.assertEqual(_snake_case	,       _snake_case						)

									_UpperCAmelCase							 =		tokenizer.encode(_snake_case						)
									_UpperCAmelCase							 =		encoded.index(_snake_case						)
									_UpperCAmelCase							 =		tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]						)[0]
									self.assertNotEqual(_snake_case	,       _snake_case						)






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






							def        lowerCamelCase_   (  self						)			->							Tuple:


									for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
											with self.subTest(f'{tokenizer.__class__.__name__} ({pretrained_name})'						):
													_UpperCAmelCase							 =		self.rust_tokenizer_class.from_pretrained(_snake_case	,       **_snake_case						)
													_UpperCAmelCase							 =		self.tokenizer_class.from_pretrained(_snake_case	,       **_snake_case						)
													_UpperCAmelCase							 =		'A, <mask> AllenNLP sentence.'
													_UpperCAmelCase							 =		tokenizer_r.encode_plus(_snake_case	,       add_special_tokens=_snake_case	,       return_token_type_ids=_snake_case						)
													_UpperCAmelCase							 =		tokenizer_p.encode_plus(_snake_case	,       add_special_tokens=_snake_case	,       return_token_type_ids=_snake_case						)

													# token_type_ids should put 0 everywhere
													self.assertEqual(sum(tokens_r['token_type_ids']						)	,       sum(tokens_p['token_type_ids']						)						)

													# attention_mask should put 1 everywhere, so sum over length should be 1
													self.assertEqual(
													    sum(tokens_r['attention_mask']						) / len(tokens_r['attention_mask']						)	,       sum(tokens_p['attention_mask']						) / len(tokens_p['attention_mask']						)	,       )

													_UpperCAmelCase							 =		tokenizer_r.convert_ids_to_tokens(tokens_r['input_ids']						)
													_UpperCAmelCase							 =		tokenizer_p.convert_ids_to_tokens(tokens_p['input_ids']						)

													# Rust correctly handles the space before the mask while python doesnt
													self.assertSequenceEqual(tokens_p['input_ids']	,       [0, 250, 6, 50264, 3823, 487, 21992, 3645, 4, 2]						)
													self.assertSequenceEqual(tokens_r['input_ids']	,       [0, 250, 6, 50264, 3823, 487, 21992, 3645, 4, 2]						)

													self.assertSequenceEqual(
													    _snake_case	,       ['<s>', 'A', ',', '<mask>', 'ĠAllen', 'N', 'LP', 'Ġsentence', '.', '</s>']						)
													self.assertSequenceEqual(
													    _snake_case	,       ['<s>', 'A', ',', '<mask>', 'ĠAllen', 'N', 'LP', 'Ġsentence', '.', '</s>']						)






							def        lowerCamelCase_   (  self						)			->							int:


									for trim_offsets, add_prefix_space in itertools.product([True, False]	,       repeat=2						):
											_UpperCAmelCase							 =		self.rust_tokenizer_class.from_pretrained(
											    self.tmpdirname	,       use_fast=_snake_case	,       add_prefix_space=_snake_case	,       trim_offsets=_snake_case						)

											_UpperCAmelCase							 =		json.loads(tokenizer_r.backend_tokenizer.pre_tokenizer.__getstate__()						)
											_UpperCAmelCase							 =		json.loads(tokenizer_r.backend_tokenizer.post_processor.__getstate__()						)

											self.assertEqual(pre_tokenizer_state['add_prefix_space']	,       _snake_case						)

											self.assertEqual(post_processor_state['add_prefix_space']	,       _snake_case						)
											self.assertEqual(post_processor_state['trim_offsets']	,       _snake_case						)






							def        lowerCamelCase_   (  self						)			->							List[str]:


									for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
											with self.subTest(f'{tokenizer.__class__.__name__} ({pretrained_name})'						):
													_UpperCAmelCase							 =		'hello'  # `hello` is a token in the vocabulary of `pretrained_name`
													_UpperCAmelCase							 =		f'{text_of_1_token} {text_of_1_token}'

													_UpperCAmelCase							 =		self.rust_tokenizer_class.from_pretrained(
													    _snake_case	,       use_fast=_snake_case	,       add_prefix_space=_snake_case	,       trim_offsets=_snake_case						)
													_UpperCAmelCase							 =		tokenizer_r(_snake_case	,       return_offsets_mapping=_snake_case	,       add_special_tokens=_snake_case						)
													self.assertEqual(encoding.offset_mapping[0]	,       (0, len(_snake_case						))						)
													self.assertEqual(
													    encoding.offset_mapping[1]	,       (len(_snake_case						) + 1, len(_snake_case						) + 1 + len(_snake_case						))	,       )

													_UpperCAmelCase							 =		self.rust_tokenizer_class.from_pretrained(
													    _snake_case	,       use_fast=_snake_case	,       add_prefix_space=_snake_case	,       trim_offsets=_snake_case						)
													_UpperCAmelCase							 =		tokenizer_r(_snake_case	,       return_offsets_mapping=_snake_case	,       add_special_tokens=_snake_case						)
													self.assertEqual(encoding.offset_mapping[0]	,       (0, len(_snake_case						))						)
													self.assertEqual(
													    encoding.offset_mapping[1]	,       (len(_snake_case						) + 1, len(_snake_case						) + 1 + len(_snake_case						))	,       )

													_UpperCAmelCase							 =		self.rust_tokenizer_class.from_pretrained(
													    _snake_case	,       use_fast=_snake_case	,       add_prefix_space=_snake_case	,       trim_offsets=_snake_case						)
													_UpperCAmelCase							 =		tokenizer_r(_snake_case	,       return_offsets_mapping=_snake_case	,       add_special_tokens=_snake_case						)
													self.assertEqual(encoding.offset_mapping[0]	,       (0, len(_snake_case						))						)
													self.assertEqual(
													    encoding.offset_mapping[1]	,       (len(_snake_case						), len(_snake_case						) + 1 + len(_snake_case						))	,       )

													_UpperCAmelCase							 =		self.rust_tokenizer_class.from_pretrained(
													    _snake_case	,       use_fast=_snake_case	,       add_prefix_space=_snake_case	,       trim_offsets=_snake_case						)
													_UpperCAmelCase							 =		tokenizer_r(_snake_case	,       return_offsets_mapping=_snake_case	,       add_special_tokens=_snake_case						)
													self.assertEqual(encoding.offset_mapping[0]	,       (0, len(_snake_case						))						)
													self.assertEqual(
													    encoding.offset_mapping[1]	,       (len(_snake_case						), len(_snake_case						) + 1 + len(_snake_case						))	,       )

													_UpperCAmelCase							 =		f' {text}'

													# tokenizer_r = self.rust_tokenizer_class.from_pretrained(
													#     pretrained_name, use_fast=True, add_prefix_space=True, trim_offsets=True
													# )
													# encoding = tokenizer_r(text, return_offsets_mapping=True, add_special_tokens=False)
													# self.assertEqual(encoding.offset_mapping[0], (1, 1 + len(text_of_1_token)))
													# self.assertEqual(
													#     encoding.offset_mapping[1],
													#     (1 + len(text_of_1_token) + 1, 1 + len(text_of_1_token) + 1 + len(text_of_1_token)),
													# )

													_UpperCAmelCase							 =		self.rust_tokenizer_class.from_pretrained(
													    _snake_case	,       use_fast=_snake_case	,       add_prefix_space=_snake_case	,       trim_offsets=_snake_case						)
													_UpperCAmelCase							 =		tokenizer_r(_snake_case	,       return_offsets_mapping=_snake_case	,       add_special_tokens=_snake_case						)
													self.assertEqual(encoding.offset_mapping[0]	,       (1, 1 + len(_snake_case						))						)
													self.assertEqual(
													    encoding.offset_mapping[1]	,       (1 + len(_snake_case						) + 1, 1 + len(_snake_case						) + 1 + len(_snake_case						))	,       )

													_UpperCAmelCase							 =		self.rust_tokenizer_class.from_pretrained(
													    _snake_case	,       use_fast=_snake_case	,       add_prefix_space=_snake_case	,       trim_offsets=_snake_case						)
													_UpperCAmelCase							 =		tokenizer_r(_snake_case	,       return_offsets_mapping=_snake_case	,       add_special_tokens=_snake_case						)
													self.assertEqual(encoding.offset_mapping[0]	,       (0, 1 + len(_snake_case						))						)
													self.assertEqual(
													    encoding.offset_mapping[1]	,       (1 + len(_snake_case						), 1 + len(_snake_case						) + 1 + len(_snake_case						))	,       )

													_UpperCAmelCase							 =		self.rust_tokenizer_class.from_pretrained(
													    _snake_case	,       use_fast=_snake_case	,       add_prefix_space=_snake_case	,       trim_offsets=_snake_case						)
													_UpperCAmelCase							 =		tokenizer_r(_snake_case	,       return_offsets_mapping=_snake_case	,       add_special_tokens=_snake_case						)
													self.assertEqual(encoding.offset_mapping[0]	,       (0, 1 + len(_snake_case						))						)
													self.assertEqual(
													    encoding.offset_mapping[1]	,       (1 + len(_snake_case						), 1 + len(_snake_case						) + 1 + len(_snake_case						))	,       )







"""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 			lowercase__			(      A    ):
							'''simple docstring'''







							def        lowerCamelCase_   (  self						)			->							int:
									_UpperCAmelCase							 =		self.config_class(**self.inputs_dict						)
									self.parent.assertTrue(hasattr(snake_case	,       'embed_dim'						)						)
									self.parent.assertTrue(hasattr(snake_case	,       'num_heads'						)						)







class 			lowercase__			:
							'''simple docstring'''







							def __init__(  self	,       snake_case	,       snake_case=13	,       snake_case=64	,       snake_case=3	,       snake_case=[16, 48, 96]	,       snake_case=[1, 3, 6]	,       snake_case=[1, 2, 10]	,       snake_case=[7, 3, 3]	,       snake_case=[4, 2, 2]	,       snake_case=[2, 1, 1]	,       snake_case=[2, 2, 2]	,       snake_case=[False, False, True]	,       snake_case=[0.0, 0.0, 0.0]	,       snake_case=0.02	,       snake_case=1E-12	,       snake_case=True	,       snake_case=True	,       snake_case=2	,       )			->							Tuple:
									_UpperCAmelCase							 =		parent
									_UpperCAmelCase							 =		batch_size
									_UpperCAmelCase							 =		image_size
									_UpperCAmelCase							 =		patch_sizes
									_UpperCAmelCase							 =		patch_stride
									_UpperCAmelCase							 =		patch_padding
									_UpperCAmelCase							 =		is_training
									_UpperCAmelCase							 =		use_labels
									_UpperCAmelCase							 =		num_labels
									_UpperCAmelCase							 =		num_channels
									_UpperCAmelCase							 =		embed_dim
									_UpperCAmelCase							 =		num_heads
									_UpperCAmelCase							 =		stride_kv
									_UpperCAmelCase							 =		depth
									_UpperCAmelCase							 =		cls_token
									_UpperCAmelCase							 =		attention_drop_rate
									_UpperCAmelCase							 =		initializer_range
									_UpperCAmelCase							 =		layer_norm_eps






							def        lowerCamelCase_   (  self						)			->							Dict:
									_UpperCAmelCase							 =		floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

									_UpperCAmelCase							 =		None
									if self.use_labels:
											_UpperCAmelCase							 =		ids_tensor([self.batch_size]	,       self.num_labels						)

									_UpperCAmelCase							 =		self.get_config()
									return config, pixel_values, labels






							def        lowerCamelCase_   (  self						)			->							List[str]:
									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        lowerCamelCase_   (  self	,       snake_case	,       snake_case	,       snake_case						)			->							Optional[int]:
									_UpperCAmelCase							 =		CvtModel(config=snake_case						)
									model.to(snake_case						)
									model.eval()
									_UpperCAmelCase							 =		model(snake_case						)
									_UpperCAmelCase							 =		(self.image_size, self.image_size)
									_UpperCAmelCase ,					_UpperCAmelCase							 =		image_size[0], image_size[1]
									for i in range(len(self.depth						)						):
											_UpperCAmelCase							 =		floor(((height + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1						)
											_UpperCAmelCase							 =		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        lowerCamelCase_   (  self	,       snake_case	,       snake_case	,       snake_case						)			->							Optional[Any]:
									_UpperCAmelCase							 =		self.num_labels
									_UpperCAmelCase							 =		CvtForImageClassification(snake_case						)
									model.to(snake_case						)
									model.eval()
									_UpperCAmelCase							 =		model(snake_case	,       labels=snake_case						)
									self.parent.assertEqual(result.logits.shape	,       (self.batch_size, self.num_labels)						)






							def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									_UpperCAmelCase							 =		self.prepare_config_and_inputs()
									_UpperCAmelCase ,					_UpperCAmelCase ,					_UpperCAmelCase							 =		config_and_inputs
									_UpperCAmelCase							 =		{'pixel_values': pixel_values}
									return config, inputs_dict







@require_torch
class 			lowercase__			(      A,					A,					unittest.TestCase    ):
							'''simple docstring'''







							_UpperCAmelCase      				=					(CvtModel, CvtForImageClassification) if is_torch_available() else ()
							_UpperCAmelCase      				=					(
							    {'''feature-extraction''': CvtModel, '''image-classification''': CvtForImageClassification}
							    if is_torch_available()
							    else {}
							)

							_UpperCAmelCase      				=					False
							_UpperCAmelCase      				=					False
							_UpperCAmelCase      				=					False
							_UpperCAmelCase      				=					False
							_UpperCAmelCase      				=					False






							def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									_UpperCAmelCase							 =		CvtModelTester(self						)
									_UpperCAmelCase							 =		ConfigTester(self	,       config_class=snake_case	,       has_text_modality=snake_case	,       hidden_size=37						)






							def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									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        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									return






							@unittest.skip(reason='Cvt does not output attentions'						)
							def        lowerCamelCase_   (  self						)			->							str:
									pass






							@unittest.skip(reason='Cvt does not use inputs_embeds'						)
							def        lowerCamelCase_   (  self						)			->							int:
									pass






							@unittest.skip(reason='Cvt does not support input and output embeddings'						)
							def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									pass






							def        lowerCamelCase_   (  self						)			->							Any:
									_UpperCAmelCase ,					_UpperCAmelCase							 =		self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
											_UpperCAmelCase							 =		model_class(snake_case						)
											_UpperCAmelCase							 =		inspect.signature(model.forward						)
											# signature.parameters is an OrderedDict => so arg_names order is deterministic
											_UpperCAmelCase							 =		[*signature.parameters.keys()]

											_UpperCAmelCase							 =		['pixel_values']
											self.assertListEqual(arg_names[:1]	,       snake_case						)






							def        lowerCamelCase_   (  self						)			->							Optional[int]:
									_UpperCAmelCase							 =		self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*snake_case						)






							def        lowerCamelCase_   (  self						)			->							Optional[int]:
									def check_hidden_states_output(snake_case	,       snake_case	,       snake_case						):
											_UpperCAmelCase							 =		model_class(snake_case						)
											model.to(snake_case						)
											model.eval()

											with torch.no_grad():
													_UpperCAmelCase							 =		model(**self._prepare_for_class(snake_case	,       snake_case						)						)

											_UpperCAmelCase							 =		outputs.hidden_states

											_UpperCAmelCase							 =		len(self.model_tester.depth						)
											self.assertEqual(len(snake_case						)	,       snake_case						)

											# 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							 =		self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
											_UpperCAmelCase							 =		True
											check_hidden_states_output(snake_case	,       snake_case	,       snake_case						)

											# check that output_hidden_states also work using config
											del inputs_dict["output_hidden_states"]
											_UpperCAmelCase							 =		True

											check_hidden_states_output(snake_case	,       snake_case	,       snake_case						)






							def        lowerCamelCase_   (  self						)			->							Any:
									_UpperCAmelCase							 =		self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_classification(*snake_case						)






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






							@slow
							def        lowerCamelCase_   (  self						)			->							Dict:
									for model_name in CVT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											_UpperCAmelCase							 =		CvtModel.from_pretrained(snake_case						)
											self.assertIsNotNone(snake_case						)







def 	UpperCAmelCase     (		):

		'''simple docstring'''


		_UpperCAmelCase							 =		Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'       )
		return image






@require_torch
@require_vision
class 			lowercase__			(      unittest.TestCase    ):
							'''simple docstring'''







							@cached_property
							def        lowerCamelCase_   (  self						)			->							List[Any]:
									return AutoImageProcessor.from_pretrained(CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]						)






							@slow
							def        lowerCamelCase_   (  self						)			->							Dict:
									_UpperCAmelCase							 =		CvtForImageClassification.from_pretrained(CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]						).to(snake_case						)

									_UpperCAmelCase							 =		self.default_image_processor
									_UpperCAmelCase							 =		prepare_img()
									_UpperCAmelCase							 =		image_processor(images=snake_case	,       return_tensors='pt'						).to(snake_case						)

									# forward pass
									with torch.no_grad():
											_UpperCAmelCase							 =		model(**snake_case						)

									# verify the logits
									_UpperCAmelCase							 =		torch.Size((1, 1000)						)
									self.assertEqual(outputs.logits.shape	,       snake_case						)

									_UpperCAmelCase							 =		torch.tensor([0.9285, 0.9015, -0.3150]						).to(snake_case						)

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


