


import unittest

import numpy as np

from transformers import RobertaConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
   from transformers.models.roberta.modeling_flax_roberta import (
       FlaxRobertaForCausalLM,
       FlaxRobertaForMaskedLM,
       FlaxRobertaForMultipleChoice,
       FlaxRobertaForQuestionAnswering,
       FlaxRobertaForSequenceClassification,
       FlaxRobertaForTokenClassification,
       FlaxRobertaModel,
   )







class lowerCAmelCase_						(			unittest.TestCase	):

 '''simple docstring'''

 def __init__(     self		,				_UpperCAmelCase		,				_UpperCAmelCase=13		,				_UpperCAmelCase=7		,				_UpperCAmelCase=True		,				_UpperCAmelCase=True		,				_UpperCAmelCase=True		,				_UpperCAmelCase=True		,				_UpperCAmelCase=99		,				_UpperCAmelCase=32		,				_UpperCAmelCase=5		,				_UpperCAmelCase=4		,				_UpperCAmelCase=37		,				_UpperCAmelCase="gelu"		,				_UpperCAmelCase=0.1		,				_UpperCAmelCase=0.1		,				_UpperCAmelCase=5_12		,				_UpperCAmelCase=16		,				_UpperCAmelCase=2		,				_UpperCAmelCase=0.02		,				_UpperCAmelCase=4		,				):
       snake_case_	=				parent
       snake_case_	=				batch_size
       snake_case_	=				seq_length
       snake_case_	=				is_training
       snake_case_	=				use_attention_mask
       snake_case_	=				use_token_type_ids
       snake_case_	=				use_labels
       snake_case_	=				vocab_size
       snake_case_	=				hidden_size
       snake_case_	=				num_hidden_layers
       snake_case_	=				num_attention_heads
       snake_case_	=				intermediate_size
       snake_case_	=				hidden_act
       snake_case_	=				hidden_dropout_prob
       snake_case_	=				attention_probs_dropout_prob
       snake_case_	=				max_position_embeddings
       snake_case_	=				type_vocab_size
       snake_case_	=				type_sequence_label_size
       snake_case_	=				initializer_range
       snake_case_	=				num_choices



 def 						UpperCamelCase__					(     self ):
       snake_case_	=				ids_tensor([self.batch_size, self.seq_length]		,				self.vocab_size )

       snake_case_	=				None
       if self.use_attention_mask:
             snake_case_	=				random_attention_mask([self.batch_size, self.seq_length] )

       snake_case_	=				None
       if self.use_token_type_ids:
             snake_case_	=				ids_tensor([self.batch_size, self.seq_length]		,				self.type_vocab_size )

       snake_case_	=				RobertaConfig(
           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		,				is_decoder=_UpperCAmelCase		,				initializer_range=self.initializer_range		,				)

       return config, input_ids, token_type_ids, attention_mask



 def 						UpperCamelCase__					(     self ):
       snake_case_	=				self.prepare_config_and_inputs()
       snake_case_	,   snake_case_	,   snake_case_	,   snake_case_	=				config_and_inputs
       snake_case_	=				{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
       return config, inputs_dict





 def 						UpperCamelCase__					(     self ):
       snake_case_	=				self.prepare_config_and_inputs()
       snake_case_	,   snake_case_	,   snake_case_	,   snake_case_	=				config_and_inputs

       snake_case_	=				True
       snake_case_	=				floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
       snake_case_	=				ids_tensor([self.batch_size, self.seq_length]		,				vocab_size=2 )

       return (
           config,
           input_ids,
           token_type_ids,
           encoder_hidden_states,
           encoder_attention_mask,
       )







@require_flax
class lowerCAmelCase_						(			lowerCamelCase__ ,						unittest.TestCase	):

 '''simple docstring'''

 __snake_case												=  True

 __snake_case												=  (
     (
         FlaxRobertaModel,
         FlaxRobertaForCausalLM,
         FlaxRobertaForMaskedLM,
         FlaxRobertaForSequenceClassification,
         FlaxRobertaForTokenClassification,
         FlaxRobertaForMultipleChoice,
         FlaxRobertaForQuestionAnswering,
     )
     if is_flax_available()
     else ()
 )



 def 						UpperCamelCase__					(     self ):
       snake_case_	=				FlaxRobertaModelTester(self )





 @slow
 def 						UpperCamelCase__					(     self ):
       for model_class_name in self.all_model_classes:
             snake_case_	=				model_class_name.from_pretrained('''roberta-base'''		,				from_pt=_UpperCAmelCase )
             snake_case_	=				model(np.ones((1, 1) ) )
             self.assertIsNotNone(_UpperCAmelCase )



from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


UpperCAmelCase      =   logging.get_logger(__name__)

UpperCAmelCase      =   {
    """facebook/convnextv2-tiny-1k-224""": """https://huggingface.co/facebook/convnextv2-tiny-1k-224/resolve/main/config.json""",
}







class lowerCAmelCase_						(			lowerCamelCase__ ,						lowerCamelCase__	):

 '''simple docstring'''

 __snake_case												=  "convnextv2"



 def __init__(     self		,				_UpperCAmelCase=3		,				_UpperCAmelCase=4		,				_UpperCAmelCase=4		,				_UpperCAmelCase=None		,				_UpperCAmelCase=None		,				_UpperCAmelCase="gelu"		,				_UpperCAmelCase=0.02		,				_UpperCAmelCase=1E-12		,				_UpperCAmelCase=0.0		,				_UpperCAmelCase=2_24		,				_UpperCAmelCase=None		,				_UpperCAmelCase=None		,				**_UpperCAmelCase		,				):
       super().__init__(**_UpperCAmelCase )

       snake_case_	=				num_channels
       snake_case_	=				patch_size
       snake_case_	=				num_stages
       snake_case_	=				[96, 1_92, 3_84, 7_68] if hidden_sizes is None else hidden_sizes
       snake_case_	=				[3, 3, 9, 3] if depths is None else depths
       snake_case_	=				hidden_act
       snake_case_	=				initializer_range
       snake_case_	=				layer_norm_eps
       snake_case_	=				drop_path_rate
       snake_case_	=				image_size
       snake_case_	=				['''stem'''] + [F'''stage{idx}''' for idx in range(1		,				len(self.depths ) + 1 )]
       snake_case_	,   snake_case_	=				get_aligned_output_features_output_indices(
           out_features=_UpperCAmelCase		,				out_indices=_UpperCAmelCase		,				stage_names=self.stage_names )