
"""simple docstring"""




import unittest

import numpy as np

from transformers import RoFormerConfig, 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.roformer.modeling_flax_roformer import (
							    FlaxRoFormerForMaskedLM,
							    FlaxRoFormerForMultipleChoice,
							    FlaxRoFormerForQuestionAnswering,
							    FlaxRoFormerForSequenceClassification,
							    FlaxRoFormerForTokenClassification,
							    FlaxRoFormerModel,
							)



class 			lowerCAmelCase_		(unittest.TestCase						):


				"""simple docstring"""



				def __init__(self     , SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__=13     , SCREAMING_SNAKE_CASE__=7     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__=99     , SCREAMING_SNAKE_CASE__=32     , SCREAMING_SNAKE_CASE__=5     , SCREAMING_SNAKE_CASE__=4     , SCREAMING_SNAKE_CASE__=37     , SCREAMING_SNAKE_CASE__="gelu"     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__=5_12     , SCREAMING_SNAKE_CASE__=16     , SCREAMING_SNAKE_CASE__=2     , SCREAMING_SNAKE_CASE__=0.02     , SCREAMING_SNAKE_CASE__=4     , )      ->	Dict:



											"""simple docstring"""




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



				def 			__magic_name__					(self					)      ->	int:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Dict     =     ids_tensor([self.batch_size, self.seq_length]     , self.vocab_size					)

											SCREAMING_SNAKE_CASE__		: Any     =     None
											if self.use_attention_mask:
																		SCREAMING_SNAKE_CASE__		: List[Any]     =     random_attention_mask([self.batch_size, self.seq_length]					)

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

											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     RoFormerConfig(
											    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 			__magic_name__					(self					)      ->	Optional[int]:



											"""simple docstring"""




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






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


				"""simple docstring"""



				__UpperCamelCase   :		Optional[int]       =     True

				__UpperCamelCase   :		Tuple       =     (
				    (
				        FlaxRoFormerModel,
				        FlaxRoFormerForMaskedLM,
				        FlaxRoFormerForSequenceClassification,
				        FlaxRoFormerForTokenClassification,
				        FlaxRoFormerForMultipleChoice,
				        FlaxRoFormerForQuestionAnswering,
				    )
				    if is_flax_available()
				    else ()
				)



				def 			__magic_name__					(self					)      ->	int:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: int     =     FlaxRoFormerModelTester(self					)



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



											"""simple docstring"""




											for model_class_name in self.all_model_classes:
																		SCREAMING_SNAKE_CASE__		: List[Any]     =     model_class_name.from_pretrained("""junnyu/roformer_chinese_small"""     , from_pt=SCREAMING_SNAKE_CASE__					)
																		SCREAMING_SNAKE_CASE__		: List[str]     =     model(np.ones((1, 1)					)					)
																		self.assertIsNotNone(SCREAMING_SNAKE_CASE__					)






@require_flax
class 			lowerCAmelCase_		(unittest.TestCase						):


				"""simple docstring"""



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



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Dict     =     FlaxRoFormerForMaskedLM.from_pretrained("""junnyu/roformer_chinese_base"""					)
											SCREAMING_SNAKE_CASE__		: Dict     =     jnp.array([[0, 1, 2, 3, 4, 5]]					)
											SCREAMING_SNAKE_CASE__		: Tuple     =     model(SCREAMING_SNAKE_CASE__					)[0]

											SCREAMING_SNAKE_CASE__		: Optional[int]     =     5_00_00

											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     (1, 6, vocab_size)
											self.assertEqual(output.shape     , SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: Any     =     jnp.array(
											    [[[-0.1205, -1.0265, 0.2922], [-1.5134, 0.1974, 0.1519], [-5.0135, -3.9003, -0.8404]]]					)

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






"""simple docstring"""




def lowercase_						(     _snake_case     ,_snake_case		):
							return int((input_a, input_a).count(1		) != 0		)

def lowercase_						(     ):
							assert or_gate(0     ,0		) == 0
							assert or_gate(0     ,1		) == 1
							assert or_gate(1     ,0		) == 1
							assert or_gate(1     ,1		) == 1


if __name__ == "__main__":
					print(or_gate(0, 1))
					print(or_gate(1, 0))
					print(or_gate(0, 0))
					print(or_gate(1, 1))




