

from ...configuration_utils import PretrainedConfig
from ...utils import logging


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

UpperCAmelCase_							:					Optional[int]		 =   {
    '''funnel-transformer/small''': '''https://huggingface.co/funnel-transformer/small/resolve/main/config.json''',
    '''funnel-transformer/small-base''': '''https://huggingface.co/funnel-transformer/small-base/resolve/main/config.json''',
    '''funnel-transformer/medium''': '''https://huggingface.co/funnel-transformer/medium/resolve/main/config.json''',
    '''funnel-transformer/medium-base''': '''https://huggingface.co/funnel-transformer/medium-base/resolve/main/config.json''',
    '''funnel-transformer/intermediate''': (
        '''https://huggingface.co/funnel-transformer/intermediate/resolve/main/config.json'''
    ),
    '''funnel-transformer/intermediate-base''': (
        '''https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/config.json'''
    ),
    '''funnel-transformer/large''': '''https://huggingface.co/funnel-transformer/large/resolve/main/config.json''',
    '''funnel-transformer/large-base''': '''https://huggingface.co/funnel-transformer/large-base/resolve/main/config.json''',
    '''funnel-transformer/xlarge''': '''https://huggingface.co/funnel-transformer/xlarge/resolve/main/config.json''',
    '''funnel-transformer/xlarge-base''': '''https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/config.json''',
}






class      lowerCamelCase_      (	_lowercase	):
	_lowercase		:   Optional[Any]     					=				'''funnel'''
	_lowercase		:   Tuple     					=				{
	    '''hidden_size''': '''d_model''',
	    '''num_attention_heads''': '''n_head''',
	}




	def __init__(     self						:     Union[str, Any]					,      __A						:     List[Any]=3_0522					,      __A						:     List[str]=[4, 4, 4]					,      __A						:     Optional[int]=None					,      __A						:     List[str]=2					,      __A						:     Optional[Any]=768					,      __A						:     int=12					,      __A						:     List[Any]=64					,      __A						:     Optional[Any]=3072					,      __A						:     str="gelu_new"					,      __A						:     Optional[Any]=0.1					,      __A						:     Optional[int]=0.1					,      __A						:     List[Any]=0.0					,      __A						:     List[str]=0.1					,      __A						:     Union[str, Any]=None					,      __A						:     Tuple=1e-9					,      __A						:     Optional[Any]="mean"					,      __A						:     Optional[int]="relative_shift"					,      __A						:     List[str]=True					,      __A						:     Union[str, Any]=True					,      __A						:     Union[str, Any]=True					,      **__A						:     Tuple					,      ):
		__A :			Tuple		    =			vocab_size
		__A :			Tuple		    =			block_sizes
		__A :			Optional[int]		    =			[1] * len(__A							) if block_repeats is None else block_repeats
		assert len(__A							) == len(
		    self.block_repeats							), "`block_sizes` and `block_repeats` should have the same length."
		__A :			Tuple		    =			num_decoder_layers
		__A :			Optional[int]		    =			d_model
		__A :			Union[str, Any]		    =			n_head
		__A :			Dict		    =			d_head
		__A :			List[str]		    =			d_inner
		__A :			Optional[Any]		    =			hidden_act
		__A :			Union[str, Any]		    =			hidden_dropout
		__A :			Tuple		    =			attention_dropout
		__A :			Optional[int]		    =			activation_dropout
		__A :			Optional[Any]		    =			initializer_range
		__A :			int		    =			initializer_std
		__A :			List[str]		    =			layer_norm_eps
		assert pooling_type in [
		    "mean",
		    "max",
		], F"""Got {pooling_type} for `pooling_type` but only 'mean' and 'max' are supported."""
		__A :			List[str]		    =			pooling_type
		assert attention_type in [
		    "relative_shift",
		    "factorized",
		], F"""Got {attention_type} for `attention_type` but only 'relative_shift' and 'factorized' are supported."""
		__A :			int		    =			attention_type
		__A :			str		    =			separate_cls
		__A :			List[Any]		    =			truncate_seq
		__A :			List[str]		    =			pool_q_only

		super().__init__(**__A							)




	@property
	def        lowerCAmelCase_       (     self						:     Dict							):
		return sum(self.block_sizes							)




	@num_hidden_layers.setter
	def        lowerCAmelCase_       (     self						:     Optional[Any]					,      __A						:     str							):
		raise NotImplementedError(
		    """This model does not support the setting of `num_hidden_layers`. Please set `block_sizes`."""							)




	@property
	def        lowerCAmelCase_       (     self						:     Optional[Any]							):
		return len(self.block_sizes							)




	@num_blocks.setter
	def        lowerCAmelCase_       (     self						:     List[Any]					,      __A						:     List[Any]							):
		raise NotImplementedError("""This model does not support the setting of `num_blocks`. Please set `block_sizes`."""							)










'''simple docstring'''





import unittest

import numpy as np

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

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
  import jax.numpy as jnp

  from transformers.models.albert.modeling_flax_albert import (
      FlaxAlbertForMaskedLM,
      FlaxAlbertForMultipleChoice,
      FlaxAlbertForPreTraining,
      FlaxAlbertForQuestionAnswering,
      FlaxAlbertForSequenceClassification,
      FlaxAlbertForTokenClassification,
      FlaxAlbertModel,
  )






class __A     (    unittest.TestCase		):



 '''simple docstring'''







 def __init__(self					,  A					,  A=13					,  A=7					,  A=True					,  A=True					,  A=True					,  A=True					,  A=99					,  A=32					,  A=5					,  A=4					,  A=37					,  A="gelu"					,  A=0.1					,  A=0.1					,  A=512					,  A=16					,  A=2					,  A=0.02					,  A=4					,  )       ->	List[str]:


      """simple docstring"""



      _a           =    parent
      _a           =    batch_size
      _a           =    seq_length
      _a           =    is_training
      _a           =    use_attention_mask
      _a           =    use_token_type_ids
      _a           =    use_labels
      _a           =    vocab_size
      _a           =    hidden_size
      _a           =    num_hidden_layers
      _a           =    num_attention_heads
      _a           =    intermediate_size
      _a           =    hidden_act
      _a           =    hidden_dropout_prob
      _a           =    attention_probs_dropout_prob
      _a           =    max_position_embeddings
      _a           =    type_vocab_size
      _a           =    type_sequence_label_size
      _a           =    initializer_range
      _a           =    num_choices



 def    a__    (self			)       ->	str:


      """simple docstring"""



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

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

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

      _a           =    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					,  is_decoder=A					,  initializer_range=self.initializer_range					,  )

      return config, input_ids, token_type_ids, attention_mask



 def    a__    (self			)       ->	List[str]:


      """simple docstring"""



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






@require_flax
class __A     (    A  ,  unittest.TestCase		):



 '''simple docstring'''







 __lowerCamelCase       :			Optional[int]		=			(
     (
         FlaxAlbertModel,
         FlaxAlbertForPreTraining,
         FlaxAlbertForMaskedLM,
         FlaxAlbertForMultipleChoice,
         FlaxAlbertForQuestionAnswering,
         FlaxAlbertForSequenceClassification,
         FlaxAlbertForTokenClassification,
         FlaxAlbertForQuestionAnswering,
     )
     if is_flax_available()
     else ()
 )



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


      """simple docstring"""



      _a           =    FlaxAlbertModelTester(self			)



 @slow
 def    a__    (self			)       ->	str:


      """simple docstring"""



      for model_class_name in self.all_model_classes:
           _a           =    model_class_name.from_pretrained('''albert-base-v2'''			)
           _a           =    model(np.ones((1, 1)			)			)
           self.assertIsNotNone(A			)






@require_flax
class __A     (    unittest.TestCase		):



 '''simple docstring'''







 @slow
 def    a__    (self			)       ->	Dict:


      """simple docstring"""



      _a           =    FlaxAlbertModel.from_pretrained('''albert-base-v2'''			)
      _a           =    np.array([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]			)
      _a           =    np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]			)
      _a           =    model(A					,  attention_mask=A			)[0]
      _a           =    (1, 11, 768)
      self.assertEqual(output.shape					,  A			)
      _a           =    np.array(
          [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]			)

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



