



'''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 					lowerCamelCase_    (				unittest.TestCase     ):
  """simple docstring"""




  def __init__( self      :	Any			,	_a      :	Any			,	_a      :	Union[str, Any]=13			,	_a      :	int=7			,	_a      :	int=True			,	_a      :	Optional[int]=True			,	_a      :	Optional[Any]=True			,	_a      :	Tuple=True			,	_a      :	str=99			,	_a      :	Optional[Any]=32			,	_a      :	Union[str, Any]=5			,	_a      :	Optional[Any]=4			,	_a      :	Optional[int]=37			,	_a      :	str="gelu"			,	_a      :	List[Any]=0.1			,	_a      :	int=0.1			,	_a      :	List[Any]=512			,	_a      :	Any=16			,	_a      :	Optional[Any]=2			,	_a      :	Optional[int]=0.02			,	_a      :	Any=4			,	)					->					int:
    __lowerCamelCase       :       Optional[int]           = parent
    __lowerCamelCase       :       Optional[Any]           = batch_size
    __lowerCamelCase       :       Optional[Any]           = seq_length
    __lowerCamelCase       :       Any           = is_training
    __lowerCamelCase       :       List[Any]           = use_attention_mask
    __lowerCamelCase       :       List[Any]           = use_token_type_ids
    __lowerCamelCase       :       Any           = use_labels
    __lowerCamelCase       :       int           = vocab_size
    __lowerCamelCase       :       Dict           = hidden_size
    __lowerCamelCase       :       List[Any]           = num_hidden_layers
    __lowerCamelCase       :       List[str]           = num_attention_heads
    __lowerCamelCase       :       Optional[Any]           = intermediate_size
    __lowerCamelCase       :       Dict           = hidden_act
    __lowerCamelCase       :       List[str]           = hidden_dropout_prob
    __lowerCamelCase       :       Dict           = attention_probs_dropout_prob
    __lowerCamelCase       :       List[Any]           = max_position_embeddings
    __lowerCamelCase       :       Optional[Any]           = type_vocab_size
    __lowerCamelCase       :       Optional[int]           = type_sequence_label_size
    __lowerCamelCase       :       int           = initializer_range
    __lowerCamelCase       :       List[Any]           = num_choices




  def 						_lowercase     ( self      :	List[str]   )					->					Any:
    __lowerCamelCase       :       Tuple           = ids_tensor([self.batch_size, self.seq_length]			,	self.vocab_size   )

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

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

    __lowerCamelCase       :       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 						_lowercase     ( self      :	List[str]   )					->					Union[str, Any]:
    __lowerCamelCase       :       Any           = self.prepare_config_and_inputs()
    __lowerCamelCase       ,__lowerCamelCase       ,__lowerCamelCase       ,__lowerCamelCase       :       Any           = config_and_inputs
    __lowerCamelCase       :       Union[str, Any]           = {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
    return config, inputs_dict






@require_flax
class 					lowerCamelCase_    (				SCREAMING_SNAKE_CASE_   ,   unittest.TestCase     ):
  """simple docstring"""




  a_												=(
      (
          FlaxAlbertModel,
          FlaxAlbertForPreTraining,
          FlaxAlbertForMaskedLM,
          FlaxAlbertForMultipleChoice,
          FlaxAlbertForQuestionAnswering,
          FlaxAlbertForSequenceClassification,
          FlaxAlbertForTokenClassification,
          FlaxAlbertForQuestionAnswering,
      )
      if is_flax_available()
      else ()
  )




  def 						_lowercase     ( self      :	Union[str, Any]   )					->					int:
    __lowerCamelCase       :       Dict           = FlaxAlbertModelTester(self   )




  @slow
  def 						_lowercase     ( self      :	List[str]   )					->					Tuple:
    for model_class_name in self.all_model_classes:
      __lowerCamelCase       :       Optional[int]           = model_class_name.from_pretrained('albert-base-v2'   )
      __lowerCamelCase       :       Optional[int]           = model(np.ones((1, 1)   )   )
      self.assertIsNotNone(_a   )






@require_flax
class 					lowerCamelCase_    (				unittest.TestCase     ):
  """simple docstring"""




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











'''simple docstring'''





_UpperCamelCase											=						tuple[float, float, float]
_UpperCamelCase											=						tuple[float, float, float]

def        a_     (							_lowerCAmelCase       ,_lowerCAmelCase       )      ->      Vectorad:
  __lowerCamelCase       :       Any           = end_pointa[0] - end_pointa[0]
  __lowerCamelCase       :       str           = end_pointa[1] - end_pointa[1]
  __lowerCamelCase       :       Tuple           = end_pointa[2] - end_pointa[2]
  return (x, y, z)

def        a_     (							_lowerCAmelCase       ,_lowerCAmelCase       )      ->      Vectorad:
  __lowerCamelCase       :       List[str]           = ab[1] * ac[2] - ab[2] * ac[1]  # *i
  __lowerCamelCase       :       Dict           = (ab[0] * ac[2] - ab[2] * ac[0]) * -1  # *j
  __lowerCamelCase       :       List[Any]           = ab[0] * ac[1] - ab[1] * ac[0]  # *k
  return (x, y, z)

def        a_     (							_lowerCAmelCase       ,_lowerCAmelCase       )      ->      bool:
  return tuple(round(_lowerCAmelCase       ,_lowerCAmelCase       ) for x in vector       ) == (0, 0, 0)


def        a_     (							_lowerCAmelCase       ,_lowerCAmelCase       ,_lowerCAmelCase       ,_lowerCAmelCase = 10       )      ->      bool:
  __lowerCamelCase       :       str           = create_vector(_lowerCAmelCase       ,_lowerCAmelCase       )
  __lowerCamelCase       :       Dict           = create_vector(_lowerCAmelCase       ,_lowerCAmelCase       )
  return is_zero_vector(get_ad_vectors_cross(_lowerCAmelCase       ,_lowerCAmelCase       )       ,_lowerCAmelCase       )






