






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 		lowercase_					(	unittest.TestCase   ):






      '''simple docstring'''




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




       """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       __lowerCAmelCase					(      self      :						Union[str, Any]  )    ->Optional[int]:




       """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=lowerCAmelCase__ ,					initializer_range=self.initializer_range ,					)

       return config, input_ids, token_type_ids, attention_mask







      def       __lowerCAmelCase					(      self      :						str  )    ->str:




       """simple docstring"""


       a		  =      self.prepare_config_and_inputs()
       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 		lowercase_					(	lowerCamelCase__ ,  unittest.TestCase   ):






      '''simple docstring'''




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







      def       __lowerCAmelCase					(      self      :						Dict  )    ->Optional[int]:




       """simple docstring"""


       a		  =      FlaxAlbertModelTester(self  )







      @slow
      def       __lowerCAmelCase					(      self      :						List[Any]  )    ->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(lowerCAmelCase__  )






@require_flax
class 		lowercase_					(	unittest.TestCase   ):






      '''simple docstring'''




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




       """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(lowerCAmelCase__ ,					attention_mask=lowerCAmelCase__  )[0]
       a		  =      (1, 11, 768)
       self.assertEqual(output.shape ,					lowerCAmelCase__  )
       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] ,					lowerCAmelCase__ ,					atol=1e-4  )  )







'''simple docstring'''




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCamelCase__       :	Any    = {
    '''configuration_instructblip''': [
        '''INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''InstructBlipConfig''',
        '''InstructBlipQFormerConfig''',
        '''InstructBlipVisionConfig''',
    ],
    '''processing_instructblip''': ['''InstructBlipProcessor'''],
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						UpperCamelCase__       :	Optional[Any]    = [
						    '''INSTRUCTBLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''InstructBlipQFormerModel''',
						    '''InstructBlipPreTrainedModel''',
						    '''InstructBlipForConditionalGeneration''',
						    '''InstructBlipVisionModel''',
						]

if TYPE_CHECKING:
						from .configuration_instructblip import (
						    INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
						    InstructBlipConfig,
						    InstructBlipQFormerConfig,
						    InstructBlipVisionConfig,
						)
						from .processing_instructblip import InstructBlipProcessor

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_instructblip import (
												    INSTRUCTBLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
												    InstructBlipForConditionalGeneration,
												    InstructBlipPreTrainedModel,
												    InstructBlipQFormerModel,
												    InstructBlipVisionModel,
												)

else:
						import sys

						UpperCamelCase__       :	str    = _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)