

'''simple docstring'''

import argparse
import collections

import torch
from flax import traverse_util
from tax import checkpoints

from transformers import TaConfig, TaEncoderModel, TaForConditionalGeneration
from transformers.utils import logging


logging.set_verbosity_info()





def       lowercase					(     __magic_name__ ,    __magic_name__ ,    __magic_name__ ,    __magic_name__="attention"							):



					'''simple docstring'''







					UpperCAmelCase		:							Tuple   					=   params[F"{prefix}/layers_{i}/{layer_name}/key/kernel"]
					UpperCAmelCase		:							int   					=   params[F"{prefix}/layers_{i}/{layer_name}/out/kernel"]
					UpperCAmelCase		:							List[str]   					=   params[F"{prefix}/layers_{i}/{layer_name}/query/kernel"]
					UpperCAmelCase		:							Any   					=   params[F"{prefix}/layers_{i}/{layer_name}/value/kernel"]
					return k, o, q, v





def       lowercase					(     __magic_name__ ,    __magic_name__ ,    __magic_name__ ,    __magic_name__=False							):



					'''simple docstring'''







					if split_mlp_wi:
										UpperCAmelCase		:							Optional[int]   					=   params[F"{prefix}/layers_{i}/mlp/wi_0/kernel"]
										UpperCAmelCase		:							Tuple   					=   params[F"{prefix}/layers_{i}/mlp/wi_1/kernel"]
										UpperCAmelCase		:							List[Any]   					=   (wi_a, wi_a)
					else:
										UpperCAmelCase		:							Optional[Any]   					=   params[F"{prefix}/layers_{i}/mlp/wi/kernel"]

					UpperCAmelCase		:							Optional[Any]   					=   params[F"{prefix}/layers_{i}/mlp/wo/kernel"]
					return wi, wo





def       lowercase					(     __magic_name__ ,    __magic_name__ ,    __magic_name__ ,    __magic_name__							):



					'''simple docstring'''







					return params[F"{prefix}/layers_{i}/{layer_name}/scale"]





def       lowercase					(     __magic_name__ ,    *, __magic_name__ ,    __magic_name__							):



					'''simple docstring'''







					UpperCAmelCase		:							Optional[Any]   					=   traverse_util.flatten_dict(variables["target"]							)
					UpperCAmelCase		:							Tuple   					=   {'/'.join(lowerCAmelCase_							): v for k, v in old.items()}

					# v1.1 models have a gated GeLU with wi_0 and wi_1 instead of wi
					UpperCAmelCase		:							Any   					=   'encoder/layers_0/mlp/wi_0/kernel' in old
					print("Split MLP:" ,    lowerCAmelCase_							)

					UpperCAmelCase		:							Union[str, Any]   					=   collections.OrderedDict()

					# Shared embeddings.
					UpperCAmelCase		:							Optional[Any]   					=   old['token_embedder/embedding']

					# Encoder.
					for i in range(lowerCAmelCase_							):
										# Block i, layer 0 (Self Attention).
										UpperCAmelCase		:							int   					=   tax_layer_norm_lookup(lowerCAmelCase_ ,    lowerCAmelCase_ ,    "encoder" ,    "pre_attention_layer_norm"							)
										UpperCAmelCase		:							Optional[int]   					=   tax_attention_lookup(lowerCAmelCase_ ,    lowerCAmelCase_ ,    "encoder" ,    "attention"							)
										UpperCAmelCase		:							List[str]   					=   layer_norm
										UpperCAmelCase		:							List[str]   					=   k.T
										UpperCAmelCase		:							Optional[int]   					=   o.T
										UpperCAmelCase		:							List[Any]   					=   q.T
										UpperCAmelCase		:							List[Any]   					=   v.T

										# Block i, layer 1 (MLP).
										UpperCAmelCase		:							Union[str, Any]   					=   tax_layer_norm_lookup(lowerCAmelCase_ ,    lowerCAmelCase_ ,    "encoder" ,    "pre_mlp_layer_norm"							)
										UpperCAmelCase		:							List[str]   					=   tax_mlp_lookup(lowerCAmelCase_ ,    lowerCAmelCase_ ,    "encoder" ,    lowerCAmelCase_							)
										UpperCAmelCase		:							Union[str, Any]   					=   layer_norm
										if split_mlp_wi:
															UpperCAmelCase		:							int   					=   wi[0].T
															UpperCAmelCase		:							List[Any]   					=   wi[1].T
										else:
															UpperCAmelCase		:							Any   					=   wi.T
										UpperCAmelCase		:							Tuple   					=   wo.T

					UpperCAmelCase		:							int   					=   old[
					    'encoder/relpos_bias/rel_embedding'
					].T
					UpperCAmelCase		:							Optional[Any]   					=   old['encoder/encoder_norm/scale']

					if not is_encoder_only:
										# Decoder.
										for i in range(lowerCAmelCase_							):
															# Block i, layer 0 (Self Attention).
															UpperCAmelCase		:							Tuple   					=   tax_layer_norm_lookup(lowerCAmelCase_ ,    lowerCAmelCase_ ,    "decoder" ,    "pre_self_attention_layer_norm"							)
															UpperCAmelCase		:							Optional[int]   					=   tax_attention_lookup(lowerCAmelCase_ ,    lowerCAmelCase_ ,    "decoder" ,    "self_attention"							)
															UpperCAmelCase		:							Tuple   					=   layer_norm
															UpperCAmelCase		:							Dict   					=   k.T
															UpperCAmelCase		:							Optional[Any]   					=   o.T
															UpperCAmelCase		:							Any   					=   q.T
															UpperCAmelCase		:							int   					=   v.T

															# Block i, layer 1 (Cross Attention).
															UpperCAmelCase		:							Union[str, Any]   					=   tax_layer_norm_lookup(lowerCAmelCase_ ,    lowerCAmelCase_ ,    "decoder" ,    "pre_cross_attention_layer_norm"							)
															UpperCAmelCase		:							List[str]   					=   tax_attention_lookup(lowerCAmelCase_ ,    lowerCAmelCase_ ,    "decoder" ,    "encoder_decoder_attention"							)
															UpperCAmelCase		:							Optional[Any]   					=   layer_norm
															UpperCAmelCase		:							Any   					=   k.T
															UpperCAmelCase		:							int   					=   o.T
															UpperCAmelCase		:							str   					=   q.T
															UpperCAmelCase		:							List[Any]   					=   v.T

															# Block i, layer 2 (MLP).
															UpperCAmelCase		:							Union[str, Any]   					=   tax_layer_norm_lookup(lowerCAmelCase_ ,    lowerCAmelCase_ ,    "decoder" ,    "pre_mlp_layer_norm"							)
															UpperCAmelCase		:							Union[str, Any]   					=   tax_mlp_lookup(lowerCAmelCase_ ,    lowerCAmelCase_ ,    "decoder" ,    lowerCAmelCase_							)
															UpperCAmelCase		:							List[str]   					=   layer_norm
															if split_mlp_wi:
																				UpperCAmelCase		:							List[Any]   					=   wi[0].T
																				UpperCAmelCase		:							List[Any]   					=   wi[1].T
															else:
																				UpperCAmelCase		:							Optional[Any]   					=   wi.T
															UpperCAmelCase		:							Optional[int]   					=   wo.T

										UpperCAmelCase		:							List[Any]   					=   old['decoder/decoder_norm/scale']
										UpperCAmelCase		:							Any   					=   old[
										    'decoder/relpos_bias/rel_embedding'
										].T

										# LM Head (only in v1.1 checkpoints, in v1.0 embeddings are used instead)
										if "decoder/logits_dense/kernel" in old:
															UpperCAmelCase		:							Dict   					=   old['decoder/logits_dense/kernel'].T

					return new





def       lowercase					(     __magic_name__ ,    __magic_name__							):



					'''simple docstring'''







					UpperCAmelCase		:							Tuple   					=   collections.OrderedDict([(k, torch.from_numpy(v.copy()							)) for (k, v) in converted_params.items()]							)

					# Add what is missing.
					if "encoder.embed_tokens.weight" not in state_dict:
										UpperCAmelCase		:							List[Any]   					=   state_dict['shared.weight']

					if not is_encoder_only:
										if "decoder.embed_tokens.weight" not in state_dict:
															UpperCAmelCase		:							List[str]   					=   state_dict['shared.weight']

										if "lm_head.weight" not in state_dict:  # For old 1.0 models.
															print("Using shared word embeddings as lm_head."							)
															UpperCAmelCase		:							Optional[int]   					=   state_dict['shared.weight']

					return state_dict





def       lowercase					(     __magic_name__ ,    __magic_name__ ,    __magic_name__ ,    __magic_name__							):



					'''simple docstring'''







					UpperCAmelCase		:							Optional[int]   					=   checkpoints.load_tax_checkpoint(lowerCAmelCase_							)
					UpperCAmelCase		:							str   					=   convert_tax_to_pytorch(lowerCAmelCase_ ,    num_layers=config.num_layers ,    is_encoder_only=lowerCAmelCase_							)
					UpperCAmelCase		:							List[Any]   					=   make_state_dict(lowerCAmelCase_ ,    lowerCAmelCase_							)
					model.load_state_dict(lowerCAmelCase_ ,    strict=lowerCAmelCase_							)





def       lowercase					(     __magic_name__ ,    __magic_name__ ,    __magic_name__ ,    __magic_name__ = False							):



					'''simple docstring'''







					UpperCAmelCase		:							int   					=   TaConfig.from_json_file(lowerCAmelCase_							)
					print(F"Building PyTorch model from configuration: {config}"							)
					# Non-v1.1 checkpoints could also use T5Model, but this works for all.
					# The v1.0 checkpoints will simply have an LM head that is the word embeddings.
					if is_encoder_only:
										UpperCAmelCase		:							str   					=   TaEncoderModel(lowerCAmelCase_							)
					else:
										UpperCAmelCase		:							Tuple   					=   TaForConditionalGeneration(lowerCAmelCase_							)

					# Load weights from tf checkpoint
					load_tax_weights_in_ta(lowerCAmelCase_ ,    lowerCAmelCase_ ,    lowerCAmelCase_ ,    lowerCAmelCase_							)

					# Save pytorch-model
					print(F"Save PyTorch model to {pytorch_dump_path}"							)
					model.save_pretrained(lowerCAmelCase_							)

					# Verify that we can load the checkpoint.
					model.from_pretrained(lowerCAmelCase_							)
					print("Done"							)


if __name__ == "__main__":
				a   :			List[Any]         = argparse.ArgumentParser(description="Converts a native T5X checkpoint into a PyTorch checkpoint.")
				# Required parameters
				parser.add_argument(
				    "--t5x_checkpoint_path", default=None, type=str, required=True, help="Path to the T5X checkpoint."
				)
				parser.add_argument(
				    "--config_file",
				    default=None,
				    type=str,
				    required=True,
				    help="The config json file corresponding to the pre-trained T5 model.\nThis specifies the model architecture.",
				)
				parser.add_argument(
				    "--pytorch_dump_path", default=None, type=str, required=True, help="Path to the output PyTorch model."
				)
				parser.add_argument(
				    "--is_encoder_only", action="store_true", help="Check if the model is encoder-decoder model", default=False
				)
				a   :			List[str]         = parser.parse_args()
				convert_tax_checkpoint_to_pytorch(
				    args.tax_checkpoint_path, args.config_file, args.pytorch_dump_path, args.is_encoder_only
				)





'''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 	__magic_name__						:







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







							def 							__lowercase			(							self					:       Dict		):
									_a     :      List[Any]        =							floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

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

									_a     :      str        =							self.get_config()

									return config, pixel_values, labels







							def 							__lowercase			(							self					:       Any		):
									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 							__lowercase			(							self					:       Tuple	,_UpperCAmelCase					:       Any	,_UpperCAmelCase					:       Any	,_UpperCAmelCase					:       Optional[Any]		):
									_a     :      Optional[Any]        =							ConvNextVaModel(config=_UpperCAmelCase		)
									model.to(_UpperCAmelCase		)
									model.eval()
									_a     :      Any        =							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 							__lowercase			(							self					:       Tuple	,_UpperCAmelCase					:       Union[str, Any]	,_UpperCAmelCase					:       List[Any]	,_UpperCAmelCase					:       int		):
									_a     :      List[Any]        =							ConvNextVaForImageClassification(_UpperCAmelCase		)
									model.to(_UpperCAmelCase		)
									model.eval()
									_a     :      List[str]        =							model(_UpperCAmelCase	,labels=_UpperCAmelCase		)
									self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.num_labels)		)







							def 							__lowercase			(							self					:       str	,_UpperCAmelCase					:       List[Any]	,_UpperCAmelCase					:       str	,_UpperCAmelCase					:       Optional[Any]		):
									_a     :      Optional[int]        =							ConvNextVaBackbone(config=_UpperCAmelCase		)
									model.to(_UpperCAmelCase		)
									model.eval()
									_a     :      Dict        =							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
									_a     :      Tuple        =							None
									_a     :      List[Any]        =							ConvNextVaBackbone(config=_UpperCAmelCase		)
									model.to(_UpperCAmelCase		)
									model.eval()
									_a     :      List[str]        =							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 							__lowercase			(							self					:       Optional[Any]		):
									_a     :      Any        =							self.prepare_config_and_inputs()
									_a       ,					_a       ,					_a     :      Union[str, Any]        =							config_and_inputs
									_a     :      Any        =							{'pixel_values': pixel_values}
									return config, inputs_dict







							def 							__lowercase			(							self					:       str		):
									_a     :      Tuple        =							self.prepare_config_and_inputs()
									_a       ,					_a       ,					_a     :      Tuple        =							config_and_inputs
									_a     :      List[Any]        =							{'pixel_values': pixel_values, 'labels': labels}
									return config, inputs_dict

@require_torch
class 	__magic_name__						(    _UpperCamelCase			,						_UpperCamelCase			,						unittest.TestCase   ):
							lowerCAmelCase       :    str   				=					(
							    (
							        ConvNextVaModel,
							        ConvNextVaForImageClassification,
							        ConvNextVaBackbone,
							    )
							    if is_torch_available()
							    else ()
							)
							lowerCAmelCase       :    str   				=					(
							    {'feature-extraction': ConvNextVaModel, 'image-classification': ConvNextVaForImageClassification}
							    if is_torch_available()
							    else {}
							)

							lowerCAmelCase       :    int   				=					False
							lowerCAmelCase       :    str   				=					False
							lowerCAmelCase       :    Optional[Any]   				=					False
							lowerCAmelCase       :    List[str]   				=					False
							lowerCAmelCase       :    Optional[int]   				=					False







							def 							__lowercase			(							self					:       List[Any]		):
									_a     :      str        =							ConvNextVaModelTester(self		)
									_a     :      Tuple        =							ConfigTester(self	,config_class=_UpperCAmelCase	,has_text_modality=_UpperCAmelCase	,hidden_size=37		)







							def 							__lowercase			(							self					:       Optional[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 							__lowercase			(							self					:       str		):
									return







							@unittest.skip(reason='ConvNextV2 does not use inputs_embeds'		)
							def 							__lowercase			(							self					:       List[Any]		):
									pass







							@unittest.skip(reason='ConvNextV2 does not support input and output embeddings'		)
							def 							__lowercase			(							self					:       Optional[int]		):
									pass







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







							def 							__lowercase			(							self					:       List[str]		):
									if not self.model_tester.is_training:
											return

									for model_class in self.all_model_classes:
											_a       ,					_a     :      List[Any]        =							self.model_tester.prepare_config_and_inputs_with_labels()
											_a     :      Any        =							True

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

											_a     :      Optional[Any]        =							model_class(_UpperCAmelCase		)
											model.to(_UpperCAmelCase		)
											model.train()
											_a     :      str        =							self._prepare_for_class(_UpperCAmelCase	,_UpperCAmelCase	,return_labels=_UpperCAmelCase		)
											_a     :      Optional[int]        =							model(**_UpperCAmelCase		).loss
											loss.backward()







							def 							__lowercase			(							self					:       str		):
									if not self.model_tester.is_training:
											return

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

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

											_a     :      Tuple        =							model_class(_UpperCAmelCase		)
											model.to(_UpperCAmelCase		)
											model.gradient_checkpointing_enable()
											model.train()
											_a     :      Any        =							self._prepare_for_class(_UpperCAmelCase	,_UpperCAmelCase	,return_labels=_UpperCAmelCase		)
											_a     :      List[Any]        =							model(**_UpperCAmelCase		).loss
											loss.backward()







							def 							__lowercase			(							self					:       List[Any]		):
									_a       ,					_a     :      List[Any]        =							self.model_tester.prepare_config_and_inputs_for_common()

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

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







							def 							__lowercase			(							self					:       int		):
									_a     :      Dict        =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_UpperCAmelCase		)







							def 							__lowercase			(							self					:       Any		):
									def check_hidden_states_output(_UpperCAmelCase					:       List[Any]	,_UpperCAmelCase					:       Tuple	,_UpperCAmelCase					:       Dict		):
											_a     :      Union[str, Any]        =							model_class(_UpperCAmelCase		)
											model.to(_UpperCAmelCase		)
											model.eval()

											with torch.no_grad():
													_a     :      List[Any]        =							model(**self._prepare_for_class(_UpperCAmelCase	,_UpperCAmelCase		)		)

											_a     :      Any        =							outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

											_a     :      str        =							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]	,)

									_a       ,					_a     :      List[str]        =							self.model_tester.prepare_config_and_inputs_for_common()

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

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

											check_hidden_states_output(_UpperCAmelCase	,_UpperCAmelCase	,_UpperCAmelCase		)







							def 							__lowercase			(							self					:       List[Any]		):
									_a     :      Optional[Any]        =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_classification(*_UpperCAmelCase		)







							@slow
							def 							__lowercase			(							self					:       int		):
									for model_name in CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											_a     :      Any        =							ConvNextVaModel.from_pretrained(_UpperCAmelCase		)
											self.assertIsNotNone(_UpperCAmelCase		)



def      __lowerCamelCase     (      )			->      List[Any]:
		_a     :      List[Any]        =							Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'  )
		return image

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







							@cached_property
							def 							__lowercase			(							self					:       Optional[Any]		):
									return AutoImageProcessor.from_pretrained('facebook/convnextv2-tiny-1k-224'		) if is_vision_available() else None







							@slow
							def 							__lowercase			(							self					:       Any		):
									_a     :      List[str]        =							ConvNextVaForImageClassification.from_pretrained('facebook/convnextv2-tiny-1k-224'		).to(_UpperCAmelCase		)

									_a     :      Optional[int]        =							self.default_image_processor
									_a     :      str        =							prepare_img()
									_a     :      str        =							preprocessor(images=_UpperCAmelCase	,return_tensors='pt'		).to(_UpperCAmelCase		)

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

									# verify the logits
									_a     :      Optional[Any]        =							torch.Size((1, 1000)		)
									self.assertEqual(outputs.logits.shape	,_UpperCAmelCase		)

									_a     :      Optional[Any]        =							torch.tensor([0.99_96, 0.19_66, -0.43_86]		).to(_UpperCAmelCase		)
									self.assertTrue(torch.allclose(outputs.logits[0, :3]	,_UpperCAmelCase	,atol=1E-4		)		)




