

'''simple docstring'''



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					:       Optional[int]					,							__SCREAMING_SNAKE_CASE					:       Any					,							__SCREAMING_SNAKE_CASE					:       str=13					,							__SCREAMING_SNAKE_CASE					:       str=7					,							__SCREAMING_SNAKE_CASE					:       List[str]=True					,							__SCREAMING_SNAKE_CASE					:       Tuple=True					,							__SCREAMING_SNAKE_CASE					:       List[str]=True					,							__SCREAMING_SNAKE_CASE					:       List[Any]=True					,							__SCREAMING_SNAKE_CASE					:       str=99					,							__SCREAMING_SNAKE_CASE					:       Dict=32					,							__SCREAMING_SNAKE_CASE					:       List[str]=5					,							__SCREAMING_SNAKE_CASE					:       Optional[Any]=4					,							__SCREAMING_SNAKE_CASE					:       str=37					,							__SCREAMING_SNAKE_CASE					:       Tuple="gelu"					,							__SCREAMING_SNAKE_CASE					:       Any=0.1					,							__SCREAMING_SNAKE_CASE					:       Optional[int]=0.1					,							__SCREAMING_SNAKE_CASE					:       int=512					,							__SCREAMING_SNAKE_CASE					:       Dict=16					,							__SCREAMING_SNAKE_CASE					:       List[str]=2					,							__SCREAMING_SNAKE_CASE					:       Union[str, Any]=0.02					,							__SCREAMING_SNAKE_CASE					:       int=4					,							)  -> int:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE     =      parent
      __SCREAMING_SNAKE_CASE     =      batch_size
      __SCREAMING_SNAKE_CASE     =      seq_length
      __SCREAMING_SNAKE_CASE     =      is_training
      __SCREAMING_SNAKE_CASE     =      use_attention_mask
      __SCREAMING_SNAKE_CASE     =      use_token_type_ids
      __SCREAMING_SNAKE_CASE     =      use_labels
      __SCREAMING_SNAKE_CASE     =      vocab_size
      __SCREAMING_SNAKE_CASE     =      hidden_size
      __SCREAMING_SNAKE_CASE     =      num_hidden_layers
      __SCREAMING_SNAKE_CASE     =      num_attention_heads
      __SCREAMING_SNAKE_CASE     =      intermediate_size
      __SCREAMING_SNAKE_CASE     =      hidden_act
      __SCREAMING_SNAKE_CASE     =      hidden_dropout_prob
      __SCREAMING_SNAKE_CASE     =      attention_probs_dropout_prob
      __SCREAMING_SNAKE_CASE     =      max_position_embeddings
      __SCREAMING_SNAKE_CASE     =      type_vocab_size
      __SCREAMING_SNAKE_CASE     =      type_sequence_label_size
      __SCREAMING_SNAKE_CASE     =      initializer_range
      __SCREAMING_SNAKE_CASE     =      num_choices
 def       UpperCAmelCase__		(		self					:       Dict			)  -> int:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE     =      ids_tensor([self.batch_size, self.seq_length]					,							self.vocab_size			)

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

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

      __SCREAMING_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=__SCREAMING_SNAKE_CASE					,							initializer_range=self.initializer_range					,							)

      return config, input_ids, token_type_ids, attention_mask
 def       UpperCAmelCase__		(		self					:       str			)  -> int:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE     =      self.prepare_config_and_inputs()
      __SCREAMING_SNAKE_CASE   ,			__SCREAMING_SNAKE_CASE   ,			__SCREAMING_SNAKE_CASE   ,			__SCREAMING_SNAKE_CASE     =      config_and_inputs
      __SCREAMING_SNAKE_CASE     =      {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
      return config, inputs_dict


 def       UpperCAmelCase__		(		self					:       str			)  -> List[Any]:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE     =      self.prepare_config_and_inputs()
      __SCREAMING_SNAKE_CASE   ,			__SCREAMING_SNAKE_CASE   ,			__SCREAMING_SNAKE_CASE   ,			__SCREAMING_SNAKE_CASE     =      config_and_inputs

      __SCREAMING_SNAKE_CASE     =      True
      __SCREAMING_SNAKE_CASE     =      floats_tensor([self.batch_size, self.seq_length, self.hidden_size]			)
      __SCREAMING_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__   (      a ,					unittest.TestCase					):



 """simple docstring"""



 lowerCAmelCase__  					=      True

 lowerCAmelCase__  					=      (
     (
         FlaxRobertaModel,
         FlaxRobertaForCausalLM,
         FlaxRobertaForMaskedLM,
         FlaxRobertaForSequenceClassification,
         FlaxRobertaForTokenClassification,
         FlaxRobertaForMultipleChoice,
         FlaxRobertaForQuestionAnswering,
     )
     if is_flax_available()
     else ()
 )
 def       UpperCAmelCase__		(		self					:       str			)  -> Optional[Any]:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE     =      FlaxRobertaModelTester(self			)


 @slow
 def       UpperCAmelCase__		(		self					:       List[Any]			)  -> str:


      """simple docstring"""




      for model_class_name in self.all_model_classes:
           __SCREAMING_SNAKE_CASE     =      model_class_name.from_pretrained("""roberta-base"""					,							from_pt=__SCREAMING_SNAKE_CASE			)
           __SCREAMING_SNAKE_CASE     =      model(np.ones((1, 1)			)			)
           self.assertIsNotNone(__SCREAMING_SNAKE_CASE			)









'''simple docstring'''



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


UpperCAmelCase :       Optional[int]			   =     logging.get_logger(__name__)

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







class 						lowerCAmelCase__   (      a ,					a					):



 """simple docstring"""



 lowerCAmelCase__  					=      "convnextv2"
 def __init__(		self					:       Any					,							__SCREAMING_SNAKE_CASE					:       int=3					,							__SCREAMING_SNAKE_CASE					:       Dict=4					,							__SCREAMING_SNAKE_CASE					:       List[Any]=4					,							__SCREAMING_SNAKE_CASE					:       Optional[int]=None					,							__SCREAMING_SNAKE_CASE					:       Dict=None					,							__SCREAMING_SNAKE_CASE					:       Optional[int]="gelu"					,							__SCREAMING_SNAKE_CASE					:       Union[str, Any]=0.02					,							__SCREAMING_SNAKE_CASE					:       Dict=1E-12					,							__SCREAMING_SNAKE_CASE					:       List[str]=0.0					,							__SCREAMING_SNAKE_CASE					:       Optional[Any]=224					,							__SCREAMING_SNAKE_CASE					:       Tuple=None					,							__SCREAMING_SNAKE_CASE					:       List[str]=None					,							**__SCREAMING_SNAKE_CASE					:       Union[str, Any]					,							)  -> Union[str, Any]:


      """simple docstring"""




      super().__init__(**__SCREAMING_SNAKE_CASE			)

      __SCREAMING_SNAKE_CASE     =      num_channels
      __SCREAMING_SNAKE_CASE     =      patch_size
      __SCREAMING_SNAKE_CASE     =      num_stages
      __SCREAMING_SNAKE_CASE     =      [96, 192, 384, 768] if hidden_sizes is None else hidden_sizes
      __SCREAMING_SNAKE_CASE     =      [3, 3, 9, 3] if depths is None else depths
      __SCREAMING_SNAKE_CASE     =      hidden_act
      __SCREAMING_SNAKE_CASE     =      initializer_range
      __SCREAMING_SNAKE_CASE     =      layer_norm_eps
      __SCREAMING_SNAKE_CASE     =      drop_path_rate
      __SCREAMING_SNAKE_CASE     =      image_size
      __SCREAMING_SNAKE_CASE     =      ["""stem"""] + [f'stage{idx}' for idx in range(1					,							len(self.depths			) + 1			)]
      __SCREAMING_SNAKE_CASE   ,			__SCREAMING_SNAKE_CASE     =      get_aligned_output_features_output_indices(
          out_features=__SCREAMING_SNAKE_CASE					,							out_indices=__SCREAMING_SNAKE_CASE					,							stage_names=self.stage_names			)






