


import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import CLIPTokenizer, CLIPTokenizerFast
from transformers.models.clip.tokenization_clip import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
						from PIL import Image

						from transformers import CLIPImageProcessor, CLIPProcessor
@require_vision
class        _lowercase      (			unittest.TestCase       ):






				'''simple docstring'''



				def 		__magic_name__(       self			:List[Any]	)		->			Optional[int]:
										__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		tempfile.mkdtemp()

										# fmt: off
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		['''l''', '''o''', '''w''', '''e''', '''r''', '''s''', '''t''', '''i''', '''d''', '''n''', '''lo''', '''l</w>''', '''w</w>''', '''r</w>''', '''t</w>''', '''low</w>''', '''er</w>''', '''lowest</w>''', '''newer</w>''', '''wider''', '''<unk>''', '''<|startoftext|>''', '''<|endoftext|>''']
										# fmt: on
										__SCREAMING_SNAKE_CASE						:     str					=		dict(zip(lowerCAmelCase__			,			range(len(lowerCAmelCase__	)	)	)	)
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		['''#version: 0.2''', '''l o''', '''lo w</w>''', '''e r</w>''', '''''']
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		{'''unk_token''': '''<unk>'''}

										__SCREAMING_SNAKE_CASE						:     str					=		os.path.join(self.tmpdirname			,			VOCAB_FILES_NAMES['''vocab_file''']	)
										__SCREAMING_SNAKE_CASE						:     Dict					=		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(lowerCAmelCase__	) + '''\n'''	)
										with open(self.merges_file			,			'''w'''			,			encoding='''utf-8'''	) as fp:
																fp.write('''\n'''.join(lowerCAmelCase__	)	)

										__SCREAMING_SNAKE_CASE						:     Tuple					=		{
										    '''do_resize''': True,
										    '''size''': 20,
										    '''do_center_crop''': True,
										    '''crop_size''': 18,
										    '''do_normalize''': True,
										    '''image_mean''': [0.4814_5466, 0.457_8275, 0.4082_1073],
										    '''image_std''': [0.2686_2954, 0.2613_0258, 0.2757_7711],
										}
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		os.path.join(self.tmpdirname			,			lowerCAmelCase__	)
										with open(self.image_processor_file			,			'''w'''			,			encoding='''utf-8'''	) as fp:
																json.dump(lowerCAmelCase__			,			lowerCAmelCase__	)


				def 		__magic_name__(       self			:Optional[int]			,			**lowerCAmelCase__			:Union[str, Any]	)		->			List[str]:
										return CLIPTokenizer.from_pretrained(self.tmpdirname			,			**lowerCAmelCase__	)


				def 		__magic_name__(       self			:int			,			**lowerCAmelCase__			:Union[str, Any]	)		->			Any:
										return CLIPTokenizerFast.from_pretrained(self.tmpdirname			,			**lowerCAmelCase__	)


				def 		__magic_name__(       self			:List[Any]			,			**lowerCAmelCase__			:int	)		->			Union[str, Any]:
										return CLIPImageProcessor.from_pretrained(self.tmpdirname			,			**lowerCAmelCase__	)


				def 		__magic_name__(       self			:Optional[Any]	)		->			List[str]:
										shutil.rmtree(self.tmpdirname	)


				def 		__magic_name__(       self			:Tuple	)		->			List[Any]:
										__SCREAMING_SNAKE_CASE						:     Tuple					=		[np.random.randint(255			,			size=(3, 30, 400)			,			dtype=np.uinta	)]

										__SCREAMING_SNAKE_CASE						:     int					=		[Image.fromarray(np.moveaxis(lowerCAmelCase__			,			0			,			-1	)	) for x in image_inputs]

										return image_inputs


				def 		__magic_name__(       self			:List[Any]	)		->			Tuple:
										__SCREAMING_SNAKE_CASE						:     List[str]					=		self.get_tokenizer()
										__SCREAMING_SNAKE_CASE						:     str					=		self.get_rust_tokenizer()
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		self.get_image_processor()

										__SCREAMING_SNAKE_CASE						:     str					=		CLIPProcessor(tokenizer=lowerCAmelCase__			,			image_processor=lowerCAmelCase__	)
										processor_slow.save_pretrained(self.tmpdirname	)
										__SCREAMING_SNAKE_CASE						:     str					=		CLIPProcessor.from_pretrained(self.tmpdirname			,			use_fast=lowerCAmelCase__	)

										__SCREAMING_SNAKE_CASE						:     int					=		CLIPProcessor(tokenizer=lowerCAmelCase__			,			image_processor=lowerCAmelCase__	)
										processor_fast.save_pretrained(self.tmpdirname	)
										__SCREAMING_SNAKE_CASE						:     Tuple					=		CLIPProcessor.from_pretrained(self.tmpdirname	)

										self.assertEqual(processor_slow.tokenizer.get_vocab()			,			tokenizer_slow.get_vocab()	)
										self.assertEqual(processor_fast.tokenizer.get_vocab()			,			tokenizer_fast.get_vocab()	)
										self.assertEqual(tokenizer_slow.get_vocab()			,			tokenizer_fast.get_vocab()	)
										self.assertIsInstance(processor_slow.tokenizer			,			lowerCAmelCase__	)
										self.assertIsInstance(processor_fast.tokenizer			,			lowerCAmelCase__	)

										self.assertEqual(processor_slow.image_processor.to_json_string()			,			image_processor.to_json_string()	)
										self.assertEqual(processor_fast.image_processor.to_json_string()			,			image_processor.to_json_string()	)
										self.assertIsInstance(processor_slow.image_processor			,			lowerCAmelCase__	)
										self.assertIsInstance(processor_fast.image_processor			,			lowerCAmelCase__	)


				def 		__magic_name__(       self			:Optional[int]	)		->			Union[str, Any]:
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		CLIPProcessor(tokenizer=self.get_tokenizer()			,			image_processor=self.get_image_processor()	)
										processor.save_pretrained(self.tmpdirname	)

										__SCREAMING_SNAKE_CASE						:     Tuple					=		self.get_tokenizer(bos_token='''(BOS)'''			,			eos_token='''(EOS)'''	)
										__SCREAMING_SNAKE_CASE						:     List[Any]					=		self.get_image_processor(do_normalize=lowerCAmelCase__			,			padding_value=1.0	)

										__SCREAMING_SNAKE_CASE						:     int					=		CLIPProcessor.from_pretrained(
										    self.tmpdirname			,			bos_token='''(BOS)'''			,			eos_token='''(EOS)'''			,			do_normalize=lowerCAmelCase__			,			padding_value=1.0	)

										self.assertEqual(processor.tokenizer.get_vocab()			,			tokenizer_add_kwargs.get_vocab()	)
										self.assertIsInstance(processor.tokenizer			,			lowerCAmelCase__	)

										self.assertEqual(processor.image_processor.to_json_string()			,			image_processor_add_kwargs.to_json_string()	)
										self.assertIsInstance(processor.image_processor			,			lowerCAmelCase__	)


				def 		__magic_name__(       self			:Optional[int]	)		->			Optional[int]:
										__SCREAMING_SNAKE_CASE						:     Dict					=		self.get_image_processor()
										__SCREAMING_SNAKE_CASE						:     List[Any]					=		self.get_tokenizer()

										__SCREAMING_SNAKE_CASE						:     Dict					=		CLIPProcessor(tokenizer=lowerCAmelCase__			,			image_processor=lowerCAmelCase__	)

										__SCREAMING_SNAKE_CASE						:     Dict					=		self.prepare_image_inputs()

										__SCREAMING_SNAKE_CASE						:     int					=		image_processor(lowerCAmelCase__			,			return_tensors='''np'''	)
										__SCREAMING_SNAKE_CASE						:     Any					=		processor(images=lowerCAmelCase__			,			return_tensors='''np'''	)

										for key in input_image_proc.keys():
																self.assertAlmostEqual(input_image_proc[key].sum()			,			input_processor[key].sum()			,			delta=1E-2	)


				def 		__magic_name__(       self			:Optional[int]	)		->			List[Any]:
										__SCREAMING_SNAKE_CASE						:     Any					=		self.get_image_processor()
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		self.get_tokenizer()

										__SCREAMING_SNAKE_CASE						:     List[Any]					=		CLIPProcessor(tokenizer=lowerCAmelCase__			,			image_processor=lowerCAmelCase__	)

										__SCREAMING_SNAKE_CASE						:     str					=		'''lower newer'''

										__SCREAMING_SNAKE_CASE						:     List[str]					=		processor(text=lowerCAmelCase__	)

										__SCREAMING_SNAKE_CASE						:     List[str]					=		tokenizer(lowerCAmelCase__	)

										for key in encoded_tok.keys():
																self.assertListEqual(encoded_tok[key]			,			encoded_processor[key]	)


				def 		__magic_name__(       self			:Optional[Any]	)		->			List[str]:
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		self.get_image_processor()
										__SCREAMING_SNAKE_CASE						:     Tuple					=		self.get_tokenizer()

										__SCREAMING_SNAKE_CASE						:     List[Any]					=		CLIPProcessor(tokenizer=lowerCAmelCase__			,			image_processor=lowerCAmelCase__	)

										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		'''lower newer'''
										__SCREAMING_SNAKE_CASE						:     List[Any]					=		self.prepare_image_inputs()

										__SCREAMING_SNAKE_CASE						:     str					=		processor(text=lowerCAmelCase__			,			images=lowerCAmelCase__	)

										self.assertListEqual(list(inputs.keys()	)			,			['''input_ids''', '''attention_mask''', '''pixel_values''']	)

										# test if it raises when no input is passed
										with pytest.raises(lowerCAmelCase__	):
																processor()


				def 		__magic_name__(       self			:str	)		->			int:
										__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		self.get_image_processor()
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		self.get_tokenizer()

										__SCREAMING_SNAKE_CASE						:     str					=		CLIPProcessor(tokenizer=lowerCAmelCase__			,			image_processor=lowerCAmelCase__	)

										__SCREAMING_SNAKE_CASE						:     List[str]					=		[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

										__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		processor.batch_decode(lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     Any					=		tokenizer.batch_decode(lowerCAmelCase__	)

										self.assertListEqual(lowerCAmelCase__			,			lowerCAmelCase__	)



				def 		__magic_name__(       self			:Any	)		->			Tuple:
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		self.get_image_processor()
										__SCREAMING_SNAKE_CASE						:     Tuple					=		self.get_tokenizer()

										__SCREAMING_SNAKE_CASE						:     int					=		CLIPProcessor(tokenizer=lowerCAmelCase__			,			image_processor=lowerCAmelCase__	)

										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		'''lower newer'''
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		self.prepare_image_inputs()

										__SCREAMING_SNAKE_CASE						:     int					=		processor(text=lowerCAmelCase__			,			images=lowerCAmelCase__	)

										self.assertListEqual(list(inputs.keys()	)			,			processor.model_input_names	)




"""simple docstring"""
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 			_UpperCAmelCase :






		'''simple docstring'''

		def __init__(self				,       a_				,       a_=13				,       a_=32				,       a_=3				,       a_=4				,       a_=[10, 20, 30, 40]				,       a_=[2, 2, 3, 2]				,       a_=True				,       a_=True				,       a_=37				,       a_="gelu"				,       a_=10				,       a_=0.02				,       a_=["stage2", "stage3", "stage4"]				,       a_=[2, 3, 4]				,       a_=None				,       ):





			'''simple docstring'''

			__snake_case	:						List[str]						=				parent
			__snake_case	:						str						=				batch_size
			__snake_case	:						List[Any]						=				image_size
			__snake_case	:						List[Any]						=				num_channels
			__snake_case	:						str						=				num_stages
			__snake_case	:						Any						=				hidden_sizes
			__snake_case	:						Optional[int]						=				depths
			__snake_case	:						Dict						=				is_training
			__snake_case	:						Tuple						=				use_labels
			__snake_case	:						str						=				intermediate_size
			__snake_case	:						Optional[int]						=				hidden_act
			__snake_case	:						Dict						=				num_labels
			__snake_case	:						Tuple						=				initializer_range
			__snake_case	:						Dict						=				out_features
			__snake_case	:						Optional[int]						=				out_indices
			__snake_case	:						str						=				scope



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						Optional[Any]						=				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

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

			__snake_case	:						Dict						=				self.get_config()

			return config, pixel_values, labels



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			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=a_				,       initializer_range=self.initializer_range				,       out_features=self.out_features				,       out_indices=self.out_indices				,       num_labels=self.num_labels				,       )



		def 				SCREAMING_SNAKE_CASE  (self				,       a_				,       a_				,       a_					):





			'''simple docstring'''

			__snake_case	:						Optional[int]						=				ConvNextVaModel(config=a_					)
			model.to(a_					)
			model.eval()
			__snake_case	:						Any						=				model(a_					)
			# 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 				SCREAMING_SNAKE_CASE  (self				,       a_				,       a_				,       a_					):





			'''simple docstring'''

			__snake_case	:						Any						=				ConvNextVaForImageClassification(a_					)
			model.to(a_					)
			model.eval()
			__snake_case	:						Union[str, Any]						=				model(a_				,       labels=a_					)
			self.parent.assertEqual(result.logits.shape				,       (self.batch_size, self.num_labels)					)



		def 				SCREAMING_SNAKE_CASE  (self				,       a_				,       a_				,       a_					):





			'''simple docstring'''

			__snake_case	:						Dict						=				ConvNextVaBackbone(config=a_					)
			model.to(a_					)
			model.eval()
			__snake_case	:						Tuple						=				model(a_					)

			# 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
			__snake_case	:						str						=				None
			__snake_case	:						Optional[Any]						=				ConvNextVaBackbone(config=a_					)
			model.to(a_					)
			model.eval()
			__snake_case	:						Tuple						=				model(a_					)

			# 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 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						int						=				self.prepare_config_and_inputs()
			__snake_case	,							__snake_case	,							__snake_case	:						Union[str, Any]						=				config_and_inputs
			__snake_case	:						Any						=				{'''pixel_values''': pixel_values}
			return config, inputs_dict



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						int						=				self.prepare_config_and_inputs()
			__snake_case	,							__snake_case	,							__snake_case	:						Union[str, Any]						=				config_and_inputs
			__snake_case	:						Optional[int]						=				{'''pixel_values''': pixel_values, '''labels''': labels}
			return config, inputs_dict



@require_torch
class 			_UpperCAmelCase (							__snake_case,				__snake_case,				unittest.TestCase				):






		'''simple docstring'''

		lowerCamelCase__				=(
		    (
		        ConvNextVaModel,
		        ConvNextVaForImageClassification,
		        ConvNextVaBackbone,
		    )
		    if is_torch_available()
		    else ()
		)
		lowerCamelCase__				=(
		    {'feature-extraction': ConvNextVaModel, 'image-classification': ConvNextVaForImageClassification}
		    if is_torch_available()
		    else {}
		)

		lowerCamelCase__				=False
		lowerCamelCase__				=False
		lowerCamelCase__				=False
		lowerCamelCase__				=False
		lowerCamelCase__				=False



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						Dict						=				ConvNextVaModelTester(self					)
			__snake_case	:						Union[str, Any]						=				ConfigTester(self				,       config_class=a_				,       has_text_modality=a_				,       hidden_size=37					)



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''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 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			return



		@unittest.skip(reason='''ConvNextV2 does not use inputs_embeds'''					)
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			pass



		@unittest.skip(reason='''ConvNextV2 does not support input and output embeddings'''					)
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			pass



		@unittest.skip(reason='''ConvNextV2 does not use feedforward chunking'''					)
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			pass



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			if not self.model_tester.is_training:
				return

			for model_class in self.all_model_classes:
				__snake_case	,							__snake_case	:						str						=				self.model_tester.prepare_config_and_inputs_with_labels()
				__snake_case	:						int						=				True

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

				__snake_case	:						Dict						=				model_class(a_					)
				model.to(a_					)
				model.train()
				__snake_case	:						Tuple						=				self._prepare_for_class(a_				,       a_				,       return_labels=a_					)
				__snake_case	:						List[str]						=				model(**a_					).loss
				loss.backward()



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			if not self.model_tester.is_training:
				return

			for model_class in self.all_model_classes:
				__snake_case	,							__snake_case	:						Optional[Any]						=				self.model_tester.prepare_config_and_inputs_with_labels()
				__snake_case	:						Optional[Any]						=				False
				__snake_case	:						Tuple						=				True

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

				__snake_case	:						Union[str, Any]						=				model_class(a_					)
				model.to(a_					)
				model.gradient_checkpointing_enable()
				model.train()
				__snake_case	:						str						=				self._prepare_for_class(a_				,       a_				,       return_labels=a_					)
				__snake_case	:						Union[str, Any]						=				model(**a_					).loss
				loss.backward()



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	,							__snake_case	:						Optional[Any]						=				self.model_tester.prepare_config_and_inputs_for_common()

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

				__snake_case	:						Any						=				['''pixel_values''']
				self.assertListEqual(arg_names[:1]				,       a_					)



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						str						=				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_model(*a_					)



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			def check_hidden_states_output(a_				,       a_				,       a_					):
				__snake_case	:						Tuple						=				model_class(a_					)
				model.to(a_					)
				model.eval()

				with torch.no_grad():
					__snake_case	:						Union[str, Any]						=				model(**self._prepare_for_class(a_				,       a_					)					)

				__snake_case	:						Union[str, Any]						=				outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

				__snake_case	:						List[Any]						=				self.model_tester.num_stages
				self.assertEqual(len(a_					)				,       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]				,       )

			__snake_case	,							__snake_case	:						List[Any]						=				self.model_tester.prepare_config_and_inputs_for_common()

			for model_class in self.all_model_classes:
				__snake_case	:						str						=				True
				check_hidden_states_output(a_				,       a_				,       a_					)

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

				check_hidden_states_output(a_				,       a_				,       a_					)



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						str						=				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_image_classification(*a_					)



		@slow
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			for model_name in CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				__snake_case	:						str						=				ConvNextVaModel.from_pretrained(a_					)
				self.assertIsNotNone(a_					)






def 		lowercase							(     )     ->Any:
	"""simple docstring"""





	__snake_case	:						List[str]						=				Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''     )
	return image



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






		'''simple docstring'''

		@cached_property
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			return AutoImageProcessor.from_pretrained('''facebook/convnextv2-tiny-1k-224'''					) if is_vision_available() else None



		@slow
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						str						=				ConvNextVaForImageClassification.from_pretrained('''facebook/convnextv2-tiny-1k-224'''					).to(a_					)

			__snake_case	:						Dict						=				self.default_image_processor
			__snake_case	:						Tuple						=				prepare_img()
			__snake_case	:						Tuple						=				preprocessor(images=a_				,       return_tensors='''pt'''					).to(a_					)

			# forward pass
			with torch.no_grad():
				__snake_case	:						Union[str, Any]						=				model(**a_					)

			# verify the logits
			__snake_case	:						Tuple						=				torch.Size((1, 10_00)					)
			self.assertEqual(outputs.logits.shape				,       a_					)

			__snake_case	:						Any						=				torch.tensor([0.9996, 0.1966, -0.4386]					).to(a_					)
			self.assertTrue(torch.allclose(outputs.logits[0, :3]				,       a_				,       atol=1E-4					)					)





