






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							,  ) ->		int:

     """simple docstring"""



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


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

     """simple docstring"""



     _UpperCAmelCase				:      List[Any]			  =				ids_tensor([self.batch_size, self.seq_length]							,  self.vocab_size)

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

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

     _UpperCAmelCase				:      List[str]			  =				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  snake_case__				(	self) ->		Optional[int]:

     """simple docstring"""



     _UpperCAmelCase				:      Dict			  =				self.prepare_config_and_inputs()
     _UpperCAmelCase				:      Any			  =				config_and_inputs
     _UpperCAmelCase				:      Union[str, Any]			  =				{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
     return config, inputs_dict



@require_flax
class 							A_    (						__lowercase ,   unittest.TestCase			):






 '''simple docstring'''




 _SCREAMING_SNAKE_CASE							:			Union[str, Any] =					(
     (
         FlaxAlbertModel,
         FlaxAlbertForPreTraining,
         FlaxAlbertForMaskedLM,
         FlaxAlbertForMultipleChoice,
         FlaxAlbertForQuestionAnswering,
         FlaxAlbertForSequenceClassification,
         FlaxAlbertForTokenClassification,
         FlaxAlbertForQuestionAnswering,
     )
     if is_flax_available()
     else ()
 )


 def  snake_case__				(	self) ->		str:

     """simple docstring"""



     _UpperCAmelCase				:      int			  =				FlaxAlbertModelTester(self)


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

     """simple docstring"""



     for model_class_name in self.all_model_classes:
         _UpperCAmelCase				:      Dict			  =				model_class_name.from_pretrained('''albert-base-v2''')
         _UpperCAmelCase				:      Union[str, Any]			  =				model(np.ones((1, 1)))
         self.assertIsNotNone(_A)



@require_flax
class 							A_    (						unittest.TestCase			):






 '''simple docstring'''




 @slow
 def  snake_case__				(	self) ->		Optional[int]:

     """simple docstring"""



     _UpperCAmelCase				:      Optional[Any]			  =				FlaxAlbertModel.from_pretrained('''albert-base-v2''')
     _UpperCAmelCase				:      Optional[int]			  =				np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]])
     _UpperCAmelCase				:      List[Any]			  =				np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
     _UpperCAmelCase				:      str			  =				model(_A							,  attention_mask=_A)[0]
     _UpperCAmelCase				:      Dict			  =				(1, 11, 768)
     self.assertEqual(output.shape							,  _A)
     _UpperCAmelCase				:      Tuple			  =				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))












import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


SCREAMING_SNAKE_CASE 							=						'\nHugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.\n\nIn March 2021, Hugging Face raised $40 million in a Series B funding round.[3]\n\nOn April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]\n'
class 							A_    (						unittest.TestCase ,   __lowercase			):






 '''simple docstring'''




 def  snake_case__				(	self) ->		int:

     """simple docstring"""



     _UpperCAmelCase				:      int			  =				load_tool('''text-question-answering''')
     self.tool.setup()
     _UpperCAmelCase				:      Any			  =				load_tool('''text-question-answering'''							,  remote=_A)


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

     """simple docstring"""



     _UpperCAmelCase				:      Optional[Any]			  =				self.tool(_A							,  '''What did Hugging Face do in April 2021?''')
     self.assertEqual(_A							,  '''launched the BigScience Research Workshop''')


 def  snake_case__				(	self) ->		str:

     """simple docstring"""



     _UpperCAmelCase				:      str			  =				self.remote_tool(_A							,  '''What did Hugging Face do in April 2021?''')
     self.assertEqual(_A							,  '''launched the BigScience Research Workshop''')


 def  snake_case__				(	self) ->		Optional[int]:

     """simple docstring"""



     _UpperCAmelCase				:      Dict			  =				self.tool(text=_A							,  question='''What did Hugging Face do in April 2021?''')
     self.assertEqual(_A							,  '''launched the BigScience Research Workshop''')


 def  snake_case__				(	self) ->		Dict:

     """simple docstring"""



     _UpperCAmelCase				:      Optional[int]			  =				self.remote_tool(text=_A							,  question='''What did Hugging Face do in April 2021?''')
     self.assertEqual(_A							,  '''launched the BigScience Research Workshop''')




