import unittest

from transformers import AlbertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
    import torch

    from transformers import (
        MODEL_FOR_PRETRAINING_MAPPING,
        AlbertForMaskedLM,
        AlbertForMultipleChoice,
        AlbertForPreTraining,
        AlbertForQuestionAnswering,
        AlbertForSequenceClassification,
        AlbertForTokenClassification,
        AlbertModel,
    )
    from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST


class 	lowerCamelCase_     :






    '''simple docstring'''






    def __init__(	self , __lowercase , __lowercase=13 , __lowercase=7 , __lowercase=True , __lowercase=True , __lowercase=True , __lowercase=True , __lowercase=99 , __lowercase=16 , __lowercase=36 , __lowercase=6 , __lowercase=6 , __lowercase=6 , __lowercase=37 , __lowercase="gelu" , __lowercase=0.1 , __lowercase=0.1 , __lowercase=512 , __lowercase=16 , __lowercase=2 , __lowercase=0.02 , __lowercase=3 , __lowercase=4 , __lowercase=None , )       ->	Optional[Any]:
        __UpperCamelCase     :str			  =		parent
        __UpperCamelCase     :List[str]			  =		batch_size
        __UpperCamelCase     :List[Any]			  =		seq_length
        __UpperCamelCase     :Optional[Any]			  =		is_training
        __UpperCamelCase     :List[Any]			  =		use_input_mask
        __UpperCamelCase     :str			  =		use_token_type_ids
        __UpperCamelCase     :Dict			  =		use_labels
        __UpperCamelCase     :List[str]			  =		vocab_size
        __UpperCamelCase     :Any			  =		embedding_size
        __UpperCamelCase     :Union[str, Any]			  =		hidden_size
        __UpperCamelCase     :Tuple			  =		num_hidden_layers
        __UpperCamelCase     :List[Any]			  =		num_hidden_groups
        __UpperCamelCase     :Optional[Any]			  =		num_attention_heads
        __UpperCamelCase     :Tuple			  =		intermediate_size
        __UpperCamelCase     :Any			  =		hidden_act
        __UpperCamelCase     :Optional[Any]			  =		hidden_dropout_prob
        __UpperCamelCase     :Any			  =		attention_probs_dropout_prob
        __UpperCamelCase     :List[Any]			  =		max_position_embeddings
        __UpperCamelCase     :str			  =		type_vocab_size
        __UpperCamelCase     :Any			  =		type_sequence_label_size
        __UpperCamelCase     :int			  =		initializer_range
        __UpperCamelCase     :int			  =		num_labels
        __UpperCamelCase     :Tuple			  =		num_choices
        __UpperCamelCase     :str			  =		scope







    def 			UpperCamelCase__   (	self)       ->	Dict:
        __UpperCamelCase     :Optional[int]			  =		ids_tensor([self.batch_size, self.seq_length] , self.vocab_size)

        __UpperCamelCase     :int			  =		None
        if self.use_input_mask:
            __UpperCamelCase     :str			  =		random_attention_mask([self.batch_size, self.seq_length])

        __UpperCamelCase     :Dict			  =		None
        if self.use_token_type_ids:
            __UpperCamelCase     :Optional[Any]			  =		ids_tensor([self.batch_size, self.seq_length] , self.type_vocab_size)

        __UpperCamelCase     :Optional[Any]			  =		None
        __UpperCamelCase     :Dict			  =		None
        __UpperCamelCase     :List[Any]			  =		None
        if self.use_labels:
            __UpperCamelCase     :str			  =		ids_tensor([self.batch_size] , self.type_sequence_label_size)
            __UpperCamelCase     :Dict			  =		ids_tensor([self.batch_size, self.seq_length] , self.num_labels)
            __UpperCamelCase     :Optional[Any]			  =		ids_tensor([self.batch_size] , self.num_choices)

        __UpperCamelCase     :Tuple			  =		self.get_config()

        return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels







    def 			UpperCamelCase__   (	self)       ->	List[Any]:
        return AlbertConfig(
            vocab_size=self.vocab_size , hidden_size=self.hidden_size , num_hidden_layers=self.num_hidden_layers , num_attention_heads=self.num_attention_heads , intermediate_size=self.intermediate_size , hidden_act=self.hidden_act , hidden_dropout_prob=self.hidden_dropout_prob , attention_probs_dropout_prob=self.attention_probs_dropout_prob , max_position_embeddings=self.max_position_embeddings , type_vocab_size=self.type_vocab_size , initializer_range=self.initializer_range , num_hidden_groups=self.num_hidden_groups , )







    def 			UpperCamelCase__   (	self , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase)       ->	Union[str, Any]:
        __UpperCamelCase     :Optional[int]			  =		AlbertModel(config=__lowercase)
        model.to(__lowercase)
        model.eval()
        __UpperCamelCase     :Optional[Any]			  =		model(__lowercase , attention_mask=__lowercase , token_type_ids=__lowercase)
        __UpperCamelCase     :List[Any]			  =		model(__lowercase , token_type_ids=__lowercase)
        __UpperCamelCase     :int			  =		model(__lowercase)
        self.parent.assertEqual(result.last_hidden_state.shape , (self.batch_size, self.seq_length, self.hidden_size))
        self.parent.assertEqual(result.pooler_output.shape , (self.batch_size, self.hidden_size))







    def 			UpperCamelCase__   (	self , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase)       ->	Optional[Any]:
        __UpperCamelCase     :int			  =		AlbertForPreTraining(config=__lowercase)
        model.to(__lowercase)
        model.eval()
        __UpperCamelCase     :List[str]			  =		model(
            __lowercase , attention_mask=__lowercase , token_type_ids=__lowercase , labels=__lowercase , sentence_order_label=__lowercase , )
        self.parent.assertEqual(result.prediction_logits.shape , (self.batch_size, self.seq_length, self.vocab_size))
        self.parent.assertEqual(result.sop_logits.shape , (self.batch_size, config.num_labels))







    def 			UpperCamelCase__   (	self , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase)       ->	Union[str, Any]:
        __UpperCamelCase     :Dict			  =		AlbertForMaskedLM(config=__lowercase)
        model.to(__lowercase)
        model.eval()
        __UpperCamelCase     :List[Any]			  =		model(__lowercase , attention_mask=__lowercase , token_type_ids=__lowercase , labels=__lowercase)
        self.parent.assertEqual(result.logits.shape , (self.batch_size, self.seq_length, self.vocab_size))







    def 			UpperCamelCase__   (	self , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase)       ->	List[str]:
        __UpperCamelCase     :List[str]			  =		AlbertForQuestionAnswering(config=__lowercase)
        model.to(__lowercase)
        model.eval()
        __UpperCamelCase     :List[str]			  =		model(
            __lowercase , attention_mask=__lowercase , token_type_ids=__lowercase , start_positions=__lowercase , end_positions=__lowercase , )
        self.parent.assertEqual(result.start_logits.shape , (self.batch_size, self.seq_length))
        self.parent.assertEqual(result.end_logits.shape , (self.batch_size, self.seq_length))







    def 			UpperCamelCase__   (	self , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase)       ->	List[str]:
        __UpperCamelCase     :List[str]			  =		self.num_labels
        __UpperCamelCase     :Optional[Any]			  =		AlbertForSequenceClassification(__lowercase)
        model.to(__lowercase)
        model.eval()
        __UpperCamelCase     :List[str]			  =		model(__lowercase , attention_mask=__lowercase , token_type_ids=__lowercase , labels=__lowercase)
        self.parent.assertEqual(result.logits.shape , (self.batch_size, self.num_labels))







    def 			UpperCamelCase__   (	self , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase)       ->	List[str]:
        __UpperCamelCase     :List[Any]			  =		self.num_labels
        __UpperCamelCase     :Optional[Any]			  =		AlbertForTokenClassification(config=__lowercase)
        model.to(__lowercase)
        model.eval()
        __UpperCamelCase     :int			  =		model(__lowercase , attention_mask=__lowercase , token_type_ids=__lowercase , labels=__lowercase)
        self.parent.assertEqual(result.logits.shape , (self.batch_size, self.seq_length, self.num_labels))







    def 			UpperCamelCase__   (	self , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase , __lowercase)       ->	Union[str, Any]:
        __UpperCamelCase     :Optional[int]			  =		self.num_choices
        __UpperCamelCase     :Optional[Any]			  =		AlbertForMultipleChoice(config=__lowercase)
        model.to(__lowercase)
        model.eval()
        __UpperCamelCase     :List[Any]			  =		input_ids.unsqueeze(1).expand(-1 , self.num_choices , -1).contiguous()
        __UpperCamelCase     :List[str]			  =		token_type_ids.unsqueeze(1).expand(-1 , self.num_choices , -1).contiguous()
        __UpperCamelCase     :str			  =		input_mask.unsqueeze(1).expand(-1 , self.num_choices , -1).contiguous()
        __UpperCamelCase     :Optional[int]			  =		model(
            __lowercase , attention_mask=__lowercase , token_type_ids=__lowercase , labels=__lowercase , )
        self.parent.assertEqual(result.logits.shape , (self.batch_size, self.num_choices))







    def 			UpperCamelCase__   (	self)       ->	str:
        __UpperCamelCase     :Optional[Any]			  =		self.prepare_config_and_inputs()
        (
            (
            __UpperCamelCase
        )  ,       (
            __UpperCamelCase
        )  ,       (
            __UpperCamelCase
        )  ,       (
            __UpperCamelCase
        )  ,       (
            __UpperCamelCase
        )  ,       (
            __UpperCamelCase
        )  ,       (
            __UpperCamelCase
        )  ,       
        )     :Optional[Any]			  =		config_and_inputs
        __UpperCamelCase     :Optional[int]			  =		{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
        return config, inputs_dict


@require_torch
class 	lowerCamelCase_     (   UpperCAmelCase_						,	UpperCAmelCase_						,	unittest.TestCase ):






    '''simple docstring'''






    a__	:						Union[str, Any]						=      (
        (
            AlbertModel,
            AlbertForPreTraining,
            AlbertForMaskedLM,
            AlbertForMultipleChoice,
            AlbertForSequenceClassification,
            AlbertForTokenClassification,
            AlbertForQuestionAnswering,
        )
        if is_torch_available()
        else ()
    )
    a__	:						int						=      (
        {
            """feature-extraction""": AlbertModel,
            """fill-mask""": AlbertForMaskedLM,
            """question-answering""": AlbertForQuestionAnswering,
            """text-classification""": AlbertForSequenceClassification,
            """token-classification""": AlbertForTokenClassification,
            """zero-shot""": AlbertForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )
    a__	:						List[Any]						=      True







    def 			UpperCamelCase__   (	self , __lowercase , __lowercase , __lowercase=False)       ->	Any:
        __UpperCamelCase     :List[Any]			  =		super()._prepare_for_class(__lowercase , __lowercase , return_labels=__lowercase)

        if return_labels:
            if model_class in get_values(__lowercase):
                __UpperCamelCase     :Union[str, Any]			  =		torch.zeros(
                    (self.model_tester.batch_size, self.model_tester.seq_length) , dtype=torch.long , device=__lowercase)
                __UpperCamelCase     :Union[str, Any]			  =		torch.zeros(
                    self.model_tester.batch_size , dtype=torch.long , device=__lowercase)
        return inputs_dict







    def 			UpperCamelCase__   (	self)       ->	Optional[int]:
        __UpperCamelCase     :Dict			  =		AlbertModelTester(self)
        __UpperCamelCase     :Dict			  =		ConfigTester(self , config_class=__lowercase , hidden_size=37)







    def 			UpperCamelCase__   (	self)       ->	Optional[int]:
        self.config_tester.run_common_tests()







    def 			UpperCamelCase__   (	self)       ->	Any:
        __UpperCamelCase     :Optional[int]			  =		self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*__lowercase)







    def 			UpperCamelCase__   (	self)       ->	Union[str, Any]:
        __UpperCamelCase     :Dict			  =		self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_pretraining(*__lowercase)







    def 			UpperCamelCase__   (	self)       ->	Union[str, Any]:
        __UpperCamelCase     :Tuple			  =		self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*__lowercase)







    def 			UpperCamelCase__   (	self)       ->	Union[str, Any]:
        __UpperCamelCase     :Optional[Any]			  =		self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*__lowercase)







    def 			UpperCamelCase__   (	self)       ->	Optional[int]:
        __UpperCamelCase     :Optional[Any]			  =		self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*__lowercase)







    def 			UpperCamelCase__   (	self)       ->	Optional[int]:
        __UpperCamelCase     :Union[str, Any]			  =		self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*__lowercase)







    def 			UpperCamelCase__   (	self)       ->	Optional[Any]:
        __UpperCamelCase     :Any			  =		self.model_tester.prepare_config_and_inputs()
        for type in ["absolute", "relative_key", "relative_key_query"]:
            __UpperCamelCase     :str			  =		type
            self.model_tester.create_and_check_model(*__lowercase)







    @slow
    def 			UpperCamelCase__   (	self)       ->	str:
        for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
            __UpperCamelCase     :List[Any]			  =		AlbertModel.from_pretrained(__lowercase)
            self.assertIsNotNone(__lowercase)


@require_torch
class 	lowerCamelCase_     (   unittest.TestCase ):






    '''simple docstring'''






    @slow
    def 			UpperCamelCase__   (	self)       ->	Optional[Any]:
        __UpperCamelCase     :int			  =		AlbertModel.from_pretrained('''albert-base-v2''')
        __UpperCamelCase     :Union[str, Any]			  =		torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]])
        __UpperCamelCase     :str			  =		torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
        with torch.no_grad():
            __UpperCamelCase     :str			  =		model(__lowercase , attention_mask=__lowercase)[0]
        __UpperCamelCase     :Optional[Any]			  =		torch.Size((1, 11, 768))
        self.assertEqual(output.shape , __lowercase)
        __UpperCamelCase     :Tuple			  =		torch.tensor(
            [[[-0.65_13, 1.50_35, -0.27_66], [-0.65_15, 1.50_46, -0.27_80], [-0.65_12, 1.50_49, -0.27_84]]])

        self.assertTrue(torch.allclose(output[:, 1:4, 1:4] , __lowercase , atol=1E-4))










'''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		)		)




