


import unittest

from transformers import BertGenerationTokenizer
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_torch, slow
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin


A      :    Union[str, Any]		=					"▁"

A      :    int		=					get_tests_dir("fixtures/test_sentencepiece.model")







@require_sentencepiece
class 			_lowercase (							__a							,  unittest.TestCase):


       """simple docstring"""




       A__											=			BertGenerationTokenizer
       A__											=			False
       A__											=			True





       def 						lowerCAmelCase     (   self							:			Any       ):


             '''simple docstring'''



             super().setUp()

             lowerCamelCase__		:				Dict    =  BertGenerationTokenizer(_UpperCamelCase					,      keep_accents=_UpperCamelCase       )
             tokenizer.save_pretrained(self.tmpdirname       )





       def 						lowerCAmelCase     (   self							:			Tuple       ):


             '''simple docstring'''



             lowerCamelCase__		:				Tuple    =  "<s>"
             lowerCamelCase__		:				List[Any]    =  1

             self.assertEqual(self.get_tokenizer()._convert_token_to_id(_UpperCamelCase       )					,      _UpperCamelCase       )
             self.assertEqual(self.get_tokenizer()._convert_id_to_token(_UpperCamelCase       )					,      _UpperCamelCase       )





       def 						lowerCAmelCase     (   self							:			List[str]       ):


             '''simple docstring'''



             lowerCamelCase__		:				Union[str, Any]    =  list(self.get_tokenizer().get_vocab().keys()       )

             self.assertEqual(vocab_keys[0]					,      "<unk>"       )
             self.assertEqual(vocab_keys[1]					,      "<s>"       )
             self.assertEqual(vocab_keys[-1]					,      "<pad>"       )
             self.assertEqual(len(_UpperCamelCase       )					,      1002       )





       def 						lowerCAmelCase     (   self							:			Any       ):


             '''simple docstring'''



             self.assertEqual(self.get_tokenizer().vocab_size					,      1000       )





       def 						lowerCAmelCase     (   self							:			int       ):


             '''simple docstring'''



             lowerCamelCase__		:				Tuple    =  BertGenerationTokenizer(_UpperCamelCase					,      keep_accents=_UpperCamelCase       )

             lowerCamelCase__		:				Tuple    =  tokenizer.tokenize("This is a test"       )
             self.assertListEqual(_UpperCamelCase					,      ["▁This", "▁is", "▁a", "▁t", "est"]       )

             self.assertListEqual(
                 tokenizer.convert_tokens_to_ids(_UpperCamelCase       )					,      [285, 46, 10, 170, 382]					,      )

             lowerCamelCase__		:				Dict    =  tokenizer.tokenize("I was born in 92000, and this is falsé."       )
             self.assertListEqual(
                 _UpperCamelCase					,      [
                     SPIECE_UNDERLINE + "I",
                     SPIECE_UNDERLINE + "was",
                     SPIECE_UNDERLINE + "b",
                     "or",
                     "n",
                     SPIECE_UNDERLINE + "in",
                     SPIECE_UNDERLINE + "",
                     "9",
                     "2",
                     "0",
                     "0",
                     "0",
                     ",",
                     SPIECE_UNDERLINE + "and",
                     SPIECE_UNDERLINE + "this",
                     SPIECE_UNDERLINE + "is",
                     SPIECE_UNDERLINE + "f",
                     "al",
                     "s",
                     "é",
                     ".",
                 ]					,      )
             lowerCamelCase__		:				Any    =  tokenizer.convert_tokens_to_ids(_UpperCamelCase       )
             self.assertListEqual(
                 _UpperCamelCase					,      [8, 21, 84, 55, 24, 19, 7, 0, 602, 347, 347, 347, 3, 12, 66, 46, 72, 80, 6, 0, 4]					,      )

             lowerCamelCase__		:				str    =  tokenizer.convert_ids_to_tokens(_UpperCamelCase       )
             self.assertListEqual(
                 _UpperCamelCase					,      [
                     SPIECE_UNDERLINE + "I",
                     SPIECE_UNDERLINE + "was",
                     SPIECE_UNDERLINE + "b",
                     "or",
                     "n",
                     SPIECE_UNDERLINE + "in",
                     SPIECE_UNDERLINE + "",
                     "<unk>",
                     "2",
                     "0",
                     "0",
                     "0",
                     ",",
                     SPIECE_UNDERLINE + "and",
                     SPIECE_UNDERLINE + "this",
                     SPIECE_UNDERLINE + "is",
                     SPIECE_UNDERLINE + "f",
                     "al",
                     "s",
                     "<unk>",
                     ".",
                 ]					,      )





       @cached_property
       def 						lowerCAmelCase     (   self							:			Union[str, Any]       ):


             '''simple docstring'''



             return BertGenerationTokenizer.from_pretrained("google/bert_for_seq_generation_L-24_bbc_encoder"       )





       @slow
       def 						lowerCAmelCase     (   self							:			Dict       ):


             '''simple docstring'''



             lowerCamelCase__		:				Tuple    =  "Hello World!"
             lowerCamelCase__		:				Union[str, Any]    =  [18536, 2260, 101]

             self.assertListEqual(_UpperCamelCase					,      self.big_tokenizer.encode(_UpperCamelCase       )       )





       @slow
       def 						lowerCAmelCase     (   self							:			Optional[int]       ):


             '''simple docstring'''



             lowerCamelCase__		:				Union[str, Any]    =  (
                 "This is a very long text with a lot of weird characters, such as: . , ~ ? ( ) \" [ ] ! : - . Also we will"
                 " add words that should not exsist and be tokenized to <unk>, such as saoneuhaoesuth"
             )
             lowerCamelCase__		:				Tuple    =  [
                 871,
                 419,
                 358,
                 946,
                 991,
                 2521,
                 452,
                 358,
                 1357,
                 387,
                 7751,
                 3536,
                 112,
                 985,
                 456,
                 126,
                 865,
                 938,
                 5400,
                 5734,
                 458,
                 1368,
                 467,
                 786,
                 2462,
                 5246,
                 1159,
                 633,
                 865,
                 4519,
                 457,
                 582,
                 852,
                 2557,
                 427,
                 916,
                 508,
                 405,
                 34324,
                 497,
                 391,
                 408,
                 11342,
                 1244,
                 385,
                 100,
                 938,
                 985,
                 456,
                 574,
                 362,
                 12597,
                 3200,
                 3129,
                 1172,
             ]

             self.assertListEqual(_UpperCamelCase					,      self.big_tokenizer.encode(_UpperCamelCase       )       )





       @require_torch
       @slow
       def 						lowerCAmelCase     (   self							:			List[str]       ):


             '''simple docstring'''



             import torch

             from transformers import BertGenerationConfig, BertGenerationEncoder

             # Build sequence
             lowerCamelCase__		:				Optional[int]    =  list(self.big_tokenizer.get_vocab().keys()       )[:10]
             lowerCamelCase__		:				Optional[Any]    =  " ".join(_UpperCamelCase       )
             lowerCamelCase__		:				List[str]    =  self.big_tokenizer.encode_plus(_UpperCamelCase					,      return_tensors="pt"					,      return_token_type_ids=_UpperCamelCase       )
             lowerCamelCase__		:				Optional[int]    =  self.big_tokenizer.batch_encode_plus(
                 [sequence + " " + sequence]					,      return_tensors="pt"					,      return_token_type_ids=_UpperCamelCase       )

             lowerCamelCase__		:				Any    =  BertGenerationConfig()
             lowerCamelCase__		:				int    =  BertGenerationEncoder(_UpperCamelCase       )

             assert model.get_input_embeddings().weight.shape[0] >= self.big_tokenizer.vocab_size

             with torch.no_grad():
                   model(**_UpperCamelCase       )
                   model(**_UpperCamelCase       )





       @slow
       def 						lowerCAmelCase     (   self							:			str       ):


             '''simple docstring'''



             lowerCamelCase__		:				List[Any]    =  {"input_ids": [[39286, 458, 36335, 2001, 456, 13073, 13266, 455, 113, 7746, 1741, 11157, 391, 13073, 13266, 455, 113, 3967, 35412, 113, 4936, 109, 3870, 2377, 113, 30084, 45720, 458, 134, 17496, 112, 503, 11672, 113, 118, 112, 5665, 13347, 38687, 112, 1496, 31389, 112, 3268, 47264, 134, 962, 112, 16377, 8035, 23130, 430, 12169, 15518, 28592, 458, 146, 41697, 109, 391, 12169, 15518, 16689, 458, 146, 41358, 109, 452, 726, 4034, 111, 763, 35412, 5082, 388, 1903, 111, 9051, 391, 2870, 48918, 1900, 1123, 550, 998, 112, 9586, 15985, 455, 391, 410, 22955, 37636, 114], [448, 17496, 419, 3663, 385, 763, 113, 27533, 2870, 3283, 13043, 1639, 24713, 523, 656, 24013, 18550, 2521, 517, 27014, 21244, 420, 1212, 1465, 391, 927, 4833, 388, 578, 11786, 114, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [484, 2169, 7687, 21932, 18146, 726, 363, 17032, 3391, 114, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], "attention_mask": [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
             # fmt: on

             self.tokenizer_integration_test_util(
                 expected_encoding=_UpperCamelCase					,      model_name="google/bert_for_seq_generation_L-24_bbc_encoder"					,      revision="c817d1fd1be2ffa69431227a1fe320544943d4db"					,      )




import inspect
import unittest

from transformers import ConvNextVaConfig
from transformers.models.auto import get_values
from transformers.models.auto.modeling_auto import MODEL_FOR_BACKBONE_MAPPING_NAMES, MODEL_MAPPING_NAMES
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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 ConvNextVaBackbone, ConvNextVaForImageClassification, ConvNextVaModel
			from transformers.models.convnextva.modeling_convnextva import CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
			from PIL import Image

			from transformers import AutoImageProcessor





class 	_lowerCAmelCase					:




				def __init__(					self				,				_UpperCamelCase				,				_UpperCamelCase=13				,				_UpperCamelCase=32				,				_UpperCamelCase=3				,				_UpperCamelCase=4				,				_UpperCamelCase=[10, 20, 30, 40]				,				_UpperCamelCase=[2, 2, 3, 2]				,				_UpperCamelCase=True				,				_UpperCamelCase=True				,				_UpperCamelCase=37				,				_UpperCamelCase="gelu"				,				_UpperCamelCase=10				,				_UpperCamelCase=0.02				,				_UpperCamelCase=["stage2", "stage3", "stage4"]				,				_UpperCamelCase=[2, 3, 4]				,				_UpperCamelCase=None				,				)				->      Union[str, Any]:
							lowerCAmelCase_						=	parent
							lowerCAmelCase_						=	batch_size
							lowerCAmelCase_						=	image_size
							lowerCAmelCase_						=	num_channels
							lowerCAmelCase_						=	num_stages
							lowerCAmelCase_						=	hidden_sizes
							lowerCAmelCase_						=	depths
							lowerCAmelCase_						=	is_training
							lowerCAmelCase_						=	use_labels
							lowerCAmelCase_						=	intermediate_size
							lowerCAmelCase_						=	hidden_act
							lowerCAmelCase_						=	num_labels
							lowerCAmelCase_						=	initializer_range
							lowerCAmelCase_						=	out_features
							lowerCAmelCase_						=	out_indices
							lowerCAmelCase_						=	scope




				def      __a						(					self     )				->      Optional[int]:
							lowerCAmelCase_						=	floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

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

							lowerCAmelCase_						=	self.get_config()

							return config, pixel_values, labels




				def      __a						(					self     )				->      List[str]:
							return ConvNextVaConfig(
							    num_channels=self.num_channels				,				hidden_sizes=self.hidden_sizes				,				depths=self.depths				,				num_stages=self.num_stages				,				hidden_act=self.hidden_act				,				is_decoder=_UpperCamelCase				,				initializer_range=self.initializer_range				,				out_features=self.out_features				,				out_indices=self.out_indices				,				num_labels=self.num_labels				,				)




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )				->      str:
							lowerCAmelCase_						=	ConvNextVaModel(config=_UpperCamelCase     )
							model.to(_UpperCamelCase     )
							model.eval()
							lowerCAmelCase_						=	model(_UpperCamelCase     )
							# expected last hidden states: B, C, H // 32, W // 32
							self.parent.assertEqual(
							    result.last_hidden_state.shape				,				(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)				,				)




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )				->      Optional[int]:
							lowerCAmelCase_						=	ConvNextVaForImageClassification(_UpperCamelCase     )
							model.to(_UpperCamelCase     )
							model.eval()
							lowerCAmelCase_						=	model(_UpperCamelCase				,				labels=_UpperCamelCase     )
							self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.num_labels)     )




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )				->      Tuple:
							lowerCAmelCase_						=	ConvNextVaBackbone(config=_UpperCamelCase     )
							model.to(_UpperCamelCase     )
							model.eval()
							lowerCAmelCase_						=	model(_UpperCamelCase     )

							# verify hidden states
							self.parent.assertEqual(len(result.feature_maps     )				,				len(config.out_features     )     )
							self.parent.assertListEqual(list(result.feature_maps[0].shape     )				,				[self.batch_size, self.hidden_sizes[1], 4, 4]     )

							# verify channels
							self.parent.assertEqual(len(model.channels     )				,				len(config.out_features     )     )
							self.parent.assertListEqual(model.channels				,				config.hidden_sizes[1:]     )

							# verify backbone works with out_features=None
							lowerCAmelCase_						=	None
							lowerCAmelCase_						=	ConvNextVaBackbone(config=_UpperCamelCase     )
							model.to(_UpperCamelCase     )
							model.eval()
							lowerCAmelCase_						=	model(_UpperCamelCase     )

							# verify feature maps
							self.parent.assertEqual(len(result.feature_maps     )				,				1     )
							self.parent.assertListEqual(list(result.feature_maps[0].shape     )				,				[self.batch_size, self.hidden_sizes[-1], 1, 1]     )

							# verify channels
							self.parent.assertEqual(len(model.channels     )				,				1     )
							self.parent.assertListEqual(model.channels				,				[config.hidden_sizes[-1]]     )




				def      __a						(					self     )				->      Any:
							lowerCAmelCase_						=	self.prepare_config_and_inputs()
							lowerCAmelCase_	,  lowerCAmelCase_	,  lowerCAmelCase_						=	config_and_inputs
							lowerCAmelCase_						=	{"pixel_values": pixel_values}
							return config, inputs_dict




				def      __a						(					self     )				->      str:
							lowerCAmelCase_						=	self.prepare_config_and_inputs()
							lowerCAmelCase_	,  lowerCAmelCase_	,  lowerCAmelCase_						=	config_and_inputs
							lowerCAmelCase_						=	{"pixel_values": pixel_values, "labels": labels}
							return config, inputs_dict





@require_torch
class 	_lowerCAmelCase					(	__a					,      __a					,      unittest.TestCase       ):
				_lowercase					=(
				    (
				        ConvNextVaModel,
				        ConvNextVaForImageClassification,
				        ConvNextVaBackbone,
				    )
				    if is_torch_available()
				    else ()
				)
				_lowercase					=(
				    {'''feature-extraction''': ConvNextVaModel, '''image-classification''': ConvNextVaForImageClassification}
				    if is_torch_available()
				    else {}
				)

				_lowercase					=False
				_lowercase					=False
				_lowercase					=False
				_lowercase					=False
				_lowercase					=False




				def      __a						(					self     )				->      Tuple:
							lowerCAmelCase_						=	ConvNextVaModelTester(self     )
							lowerCAmelCase_						=	ConfigTester(self				,				config_class=_UpperCamelCase				,				has_text_modality=_UpperCamelCase				,				hidden_size=37     )




				def      __a						(					self     )				->      List[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      __a						(					self     )				->      Any:
							return




				@unittest.skip(reason="ConvNextV2 does not use inputs_embeds"     )
				def      __a						(					self     )				->      List[Any]:
							pass




				@unittest.skip(reason="ConvNextV2 does not support input and output embeddings"     )
				def      __a						(					self     )				->      int:
							pass




				@unittest.skip(reason="ConvNextV2 does not use feedforward chunking"     )
				def      __a						(					self     )				->      str:
							pass




				def      __a						(					self     )				->      Union[str, Any]:
							if not self.model_tester.is_training:
										return

							for model_class in self.all_model_classes:
										lowerCAmelCase_	,  lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs_with_labels()
										lowerCAmelCase_						=	True

										if model_class.__name__ in [
										    *get_values(_UpperCamelCase     ),
										    *get_values(_UpperCamelCase     ),
										]:
													continue

										lowerCAmelCase_						=	model_class(_UpperCamelCase     )
										model.to(_UpperCamelCase     )
										model.train()
										lowerCAmelCase_						=	self._prepare_for_class(_UpperCamelCase				,				_UpperCamelCase				,				return_labels=_UpperCamelCase     )
										lowerCAmelCase_						=	model(**_UpperCamelCase     ).loss
										loss.backward()




				def      __a						(					self     )				->      Optional[int]:
							if not self.model_tester.is_training:
										return

							for model_class in self.all_model_classes:
										lowerCAmelCase_	,  lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs_with_labels()
										lowerCAmelCase_						=	False
										lowerCAmelCase_						=	True

										if (
										    model_class.__name__
										    in [*get_values(_UpperCamelCase     ), *get_values(_UpperCamelCase     )]
										    or not model_class.supports_gradient_checkpointing
										):
													continue

										lowerCAmelCase_						=	model_class(_UpperCamelCase     )
										model.to(_UpperCamelCase     )
										model.gradient_checkpointing_enable()
										model.train()
										lowerCAmelCase_						=	self._prepare_for_class(_UpperCamelCase				,				_UpperCamelCase				,				return_labels=_UpperCamelCase     )
										lowerCAmelCase_						=	model(**_UpperCamelCase     ).loss
										loss.backward()




				def      __a						(					self     )				->      Any:
							lowerCAmelCase_	,  lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs_for_common()

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

										lowerCAmelCase_						=	["pixel_values"]
										self.assertListEqual(arg_names[:1]				,				_UpperCamelCase     )




				def      __a						(					self     )				->      Tuple:
							lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_UpperCamelCase     )




				def      __a						(					self     )				->      List[Any]:
							def check_hidden_states_output(_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     ):
										lowerCAmelCase_						=	model_class(_UpperCamelCase     )
										model.to(_UpperCamelCase     )
										model.eval()

										with torch.no_grad():
													lowerCAmelCase_						=	model(**self._prepare_for_class(_UpperCamelCase				,				_UpperCamelCase     )     )

										lowerCAmelCase_						=	outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

										lowerCAmelCase_						=	self.model_tester.num_stages
										self.assertEqual(len(_UpperCamelCase     )				,				expected_num_stages + 1     )

										# ConvNextV2's feature maps are of shape (batch_size, num_channels, height, width)
										self.assertListEqual(
										    list(hidden_states[0].shape[-2:]     )				,				[self.model_tester.image_size // 4, self.model_tester.image_size // 4]				,				)

							lowerCAmelCase_	,  lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
										lowerCAmelCase_						=	True
										check_hidden_states_output(_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )

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

										check_hidden_states_output(_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )




				def      __a						(					self     )				->      Optional[int]:
							lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_image_classification(*_UpperCamelCase     )




				@slow
				def      __a						(					self     )				->      Optional[Any]:
							for model_name in CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										lowerCAmelCase_						=	ConvNextVaModel.from_pretrained(_UpperCamelCase     )
										self.assertIsNotNone(_UpperCamelCase     )






def    lowerCamelCase__				(				):




			"""simple docstring"""


			lowerCAmelCase_						=	Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"				)
			return image





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




				@cached_property
				def      __a						(					self     )				->      int:
							return AutoImageProcessor.from_pretrained("facebook/convnextv2-tiny-1k-224"     ) if is_vision_available() else None




				@slow
				def      __a						(					self     )				->      List[str]:
							lowerCAmelCase_						=	ConvNextVaForImageClassification.from_pretrained("facebook/convnextv2-tiny-1k-224"     ).to(_UpperCamelCase     )

							lowerCAmelCase_						=	self.default_image_processor
							lowerCAmelCase_						=	prepare_img()
							lowerCAmelCase_						=	preprocessor(images=_UpperCamelCase				,				return_tensors="pt"     ).to(_UpperCamelCase     )

							# forward pass
							with torch.no_grad():
										lowerCAmelCase_						=	model(**_UpperCamelCase     )

							# verify the logits
							lowerCAmelCase_						=	torch.Size((1, 1_000)     )
							self.assertEqual(outputs.logits.shape				,				_UpperCamelCase     )

							lowerCAmelCase_						=	torch.tensor([0.9996, 0.1966, -0.4386]     ).to(_UpperCamelCase     )
							self.assertTrue(torch.allclose(outputs.logits[0, :3]				,				_UpperCamelCase				,				atol=1e-4     )     )



