



"""simple docstring"""
import unittest

import numpy as np

from transformers import BertConfig, 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.bert.modeling_flax_bert import (
       FlaxBertForMaskedLM,
       FlaxBertForMultipleChoice,
       FlaxBertForNextSentencePrediction,
       FlaxBertForPreTraining,
       FlaxBertForQuestionAnswering,
       FlaxBertForSequenceClassification,
       FlaxBertForTokenClassification,
       FlaxBertModel,
   )
class 					a	(  unittest.TestCase       ):



  def __init__(						self :					Optional[int]       ,		lowerCAmelCase :					List[str]       ,		lowerCAmelCase :					Tuple=13       ,		lowerCAmelCase :					List[Any]=7       ,		lowerCAmelCase :					List[str]=True       ,		lowerCAmelCase :					List[str]=True       ,		lowerCAmelCase :					int=True       ,		lowerCAmelCase :					List[Any]=True       ,		lowerCAmelCase :					str=99       ,		lowerCAmelCase :					Optional[int]=32       ,		lowerCAmelCase :					str=5       ,		lowerCAmelCase :					Optional[Any]=4       ,		lowerCAmelCase :					int=37       ,		lowerCAmelCase :					Tuple="gelu"       ,		lowerCAmelCase :					Optional[int]=0.1       ,		lowerCAmelCase :					Tuple=0.1       ,		lowerCAmelCase :					Optional[int]=512       ,		lowerCAmelCase :					Optional[Any]=16       ,		lowerCAmelCase :					Tuple=2       ,		lowerCAmelCase :					List[str]=0.0_2       ,		lowerCAmelCase :					Any=4       ,		)     ->					int:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Any     			=parent
     SCREAMING_SNAKE_CASE_: int     			=batch_size
     SCREAMING_SNAKE_CASE_: Any     			=seq_length
     SCREAMING_SNAKE_CASE_: Any     			=is_training
     SCREAMING_SNAKE_CASE_: Optional[Any]     			=use_attention_mask
     SCREAMING_SNAKE_CASE_: List[Any]     			=use_token_type_ids
     SCREAMING_SNAKE_CASE_: Optional[int]     			=use_labels
     SCREAMING_SNAKE_CASE_: int     			=vocab_size
     SCREAMING_SNAKE_CASE_: Tuple     			=hidden_size
     SCREAMING_SNAKE_CASE_: List[str]     			=num_hidden_layers
     SCREAMING_SNAKE_CASE_: List[Any]     			=num_attention_heads
     SCREAMING_SNAKE_CASE_: List[Any]     			=intermediate_size
     SCREAMING_SNAKE_CASE_: Optional[Any]     			=hidden_act
     SCREAMING_SNAKE_CASE_: int     			=hidden_dropout_prob
     SCREAMING_SNAKE_CASE_: int     			=attention_probs_dropout_prob
     SCREAMING_SNAKE_CASE_: Dict     			=max_position_embeddings
     SCREAMING_SNAKE_CASE_: Tuple     			=type_vocab_size
     SCREAMING_SNAKE_CASE_: Optional[int]     			=type_sequence_label_size
     SCREAMING_SNAKE_CASE_: Optional[Any]     			=initializer_range
     SCREAMING_SNAKE_CASE_: Dict     			=num_choices



  def 	lowerCamelCase__       (						self :					str		)     ->					Union[str, Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: List[str]     			=ids_tensor([self.batch_size, self.seq_length]       ,		self.vocab_size		)

     SCREAMING_SNAKE_CASE_: Union[str, Any]     			=None
     if self.use_attention_mask:
        SCREAMING_SNAKE_CASE_: int     			=random_attention_mask([self.batch_size, self.seq_length]		)

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

     SCREAMING_SNAKE_CASE_: List[str]     			=BertConfig(
         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=lowerCAmelCase       ,		initializer_range=self.initializer_range       ,		)

     return config, input_ids, token_type_ids, attention_mask



  def 	lowerCamelCase__       (						self :					Optional[int]		)     ->					List[Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Any     			=self.prepare_config_and_inputs()
     SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_: Optional[Any]     			=config_and_inputs
     SCREAMING_SNAKE_CASE_: List[str]     			={"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
     return config, inputs_dict





  def 	lowerCamelCase__       (						self :					str		)     ->					int:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: int     			=self.prepare_config_and_inputs()
     SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_: Any     			=config_and_inputs

     SCREAMING_SNAKE_CASE_: Any     			=True
     SCREAMING_SNAKE_CASE_: List[str]     			=floats_tensor([self.batch_size, self.seq_length, self.hidden_size]		)
     SCREAMING_SNAKE_CASE_: List[str]     			=ids_tensor([self.batch_size, self.seq_length]       ,		vocab_size=2		)

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







@require_flax
class 					a	(  UpperCAmelCase__	,      unittest.TestCase       ):
  UpperCamelCase	:				Optional[Any]     						=					True

  UpperCamelCase	:				Any     						=					(
      (
          FlaxBertModel,
          FlaxBertForPreTraining,
          FlaxBertForMaskedLM,
          FlaxBertForMultipleChoice,
          FlaxBertForQuestionAnswering,
          FlaxBertForNextSentencePrediction,
          FlaxBertForSequenceClassification,
          FlaxBertForTokenClassification,
          FlaxBertForQuestionAnswering,
      )
      if is_flax_available()
      else ()
  )



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


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Optional[int]     			=FlaxBertModelTester(self		)





  @slow
  def 	lowerCamelCase__       (						self :					Union[str, Any]		)     ->					Union[str, Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Optional[Any]     			=FlaxBertModel.from_pretrained("""bert-base-cased"""		)
     SCREAMING_SNAKE_CASE_: str     			=model(np.ones((1, 1)		)		)
     self.assertIsNotNone(lowerCAmelCase		)








"""simple docstring"""
from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig


_UpperCAmelCase     =			{
    """albert-base-v1""": """https://huggingface.co/albert-base-v1/resolve/main/config.json""",
    """albert-large-v1""": """https://huggingface.co/albert-large-v1/resolve/main/config.json""",
    """albert-xlarge-v1""": """https://huggingface.co/albert-xlarge-v1/resolve/main/config.json""",
    """albert-xxlarge-v1""": """https://huggingface.co/albert-xxlarge-v1/resolve/main/config.json""",
    """albert-base-v2""": """https://huggingface.co/albert-base-v2/resolve/main/config.json""",
    """albert-large-v2""": """https://huggingface.co/albert-large-v2/resolve/main/config.json""",
    """albert-xlarge-v2""": """https://huggingface.co/albert-xlarge-v2/resolve/main/config.json""",
    """albert-xxlarge-v2""": """https://huggingface.co/albert-xxlarge-v2/resolve/main/config.json""",
}
class 					a	(  UpperCAmelCase__       ):
  UpperCamelCase	:				Any     						=					'albert'



  def __init__(						self :					Dict       ,		lowerCAmelCase :					List[str]=3_0000       ,		lowerCAmelCase :					List[Any]=128       ,		lowerCAmelCase :					List[str]=4096       ,		lowerCAmelCase :					str=12       ,		lowerCAmelCase :					str=1       ,		lowerCAmelCase :					Tuple=64       ,		lowerCAmelCase :					Dict=1_6384       ,		lowerCAmelCase :					int=1       ,		lowerCAmelCase :					str="gelu_new"       ,		lowerCAmelCase :					Dict=0       ,		lowerCAmelCase :					Optional[Any]=0       ,		lowerCAmelCase :					str=512       ,		lowerCAmelCase :					Optional[int]=2       ,		lowerCAmelCase :					List[Any]=0.0_2       ,		lowerCAmelCase :					Union[str, Any]=1E-12       ,		lowerCAmelCase :					Tuple=0.1       ,		lowerCAmelCase :					List[Any]="absolute"       ,		lowerCAmelCase :					List[Any]=0       ,		lowerCAmelCase :					int=2       ,		lowerCAmelCase :					Optional[int]=3       ,		**lowerCAmelCase :					int       ,		)     ->					Tuple:


     '''simple docstring'''




     super().__init__(pad_token_id=lowerCAmelCase       ,		bos_token_id=lowerCAmelCase       ,		eos_token_id=lowerCAmelCase       ,		**lowerCAmelCase		)

     SCREAMING_SNAKE_CASE_: List[str]     			=vocab_size
     SCREAMING_SNAKE_CASE_: Optional[int]     			=embedding_size
     SCREAMING_SNAKE_CASE_: Optional[int]     			=hidden_size
     SCREAMING_SNAKE_CASE_: Tuple     			=num_hidden_layers
     SCREAMING_SNAKE_CASE_: Any     			=num_hidden_groups
     SCREAMING_SNAKE_CASE_: List[Any]     			=num_attention_heads
     SCREAMING_SNAKE_CASE_: List[Any]     			=inner_group_num
     SCREAMING_SNAKE_CASE_: Optional[int]     			=hidden_act
     SCREAMING_SNAKE_CASE_: int     			=intermediate_size
     SCREAMING_SNAKE_CASE_: Any     			=hidden_dropout_prob
     SCREAMING_SNAKE_CASE_: Union[str, Any]     			=attention_probs_dropout_prob
     SCREAMING_SNAKE_CASE_: int     			=max_position_embeddings
     SCREAMING_SNAKE_CASE_: Any     			=type_vocab_size
     SCREAMING_SNAKE_CASE_: int     			=initializer_range
     SCREAMING_SNAKE_CASE_: List[Any]     			=layer_norm_eps
     SCREAMING_SNAKE_CASE_: Dict     			=classifier_dropout_prob
     SCREAMING_SNAKE_CASE_: int     			=position_embedding_type







class 					a	(  UpperCAmelCase__       ):



  @property
  def 	lowerCamelCase__       (						self :					Optional[int]		)     ->					Mapping[str, Mapping[int, str]]:


     '''simple docstring'''




     if self.task == "multiple-choice":
        SCREAMING_SNAKE_CASE_: str     			={0: """batch""", 1: """choice""", 2: """sequence"""}
     else:
        SCREAMING_SNAKE_CASE_: Dict     			={0: """batch""", 1: """sequence"""}
     return OrderedDict(
         [
             ("""input_ids""", dynamic_axis),
             ("""attention_mask""", dynamic_axis),
             ("""token_type_ids""", dynamic_axis),
         ]		)



