






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







 def __init__(		self :       int							,       SCREAMING_SNAKE_CASE :       Dict							,       SCREAMING_SNAKE_CASE :       Any=13							,       SCREAMING_SNAKE_CASE :       Optional[int]=7							,       SCREAMING_SNAKE_CASE :       List[Any]=True							,       SCREAMING_SNAKE_CASE :       Optional[int]=True							,       SCREAMING_SNAKE_CASE :       Any=True							,       SCREAMING_SNAKE_CASE :       Tuple=True							,       SCREAMING_SNAKE_CASE :       Tuple=99							,       SCREAMING_SNAKE_CASE :       Tuple=32							,       SCREAMING_SNAKE_CASE :       Tuple=5							,       SCREAMING_SNAKE_CASE :       List[str]=4							,       SCREAMING_SNAKE_CASE :       Tuple=37							,       SCREAMING_SNAKE_CASE :       Union[str, Any]="gelu"							,       SCREAMING_SNAKE_CASE :       Optional[Any]=0.1							,       SCREAMING_SNAKE_CASE :       Any=0.1							,       SCREAMING_SNAKE_CASE :       Tuple=5_12							,       SCREAMING_SNAKE_CASE :       str=16							,       SCREAMING_SNAKE_CASE :       int=2							,       SCREAMING_SNAKE_CASE :       str=0.0_2							,       SCREAMING_SNAKE_CASE :       int=4							,       ):


      '''simple docstring'''






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







 def  __lowercase (		self :       Union[str, Any]						):


      '''simple docstring'''






      UpperCamelCase__      :       List[str]	    =  ids_tensor([self.batch_size, self.seq_length]							,       self.vocab_size						)

      UpperCamelCase__      :       Optional[int]	    =  None
      if self.use_attention_mask:
           UpperCamelCase__      :       Tuple	    =  random_attention_mask([self.batch_size, self.seq_length]						)

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

      UpperCamelCase__      :       Optional[Any]	    =  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  __lowercase (		self :       Tuple						):


      '''simple docstring'''






      UpperCamelCase__      :       Dict	    =  self.prepare_config_and_inputs()
      UpperCamelCase__    ,					UpperCamelCase__    ,					UpperCamelCase__    ,					UpperCamelCase__      :       Union[str, Any]	    =  config_and_inputs
      UpperCamelCase__      :       Optional[Any]	    =  {"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	):
 _lowerCAmelCase	:	Optional[Any]				=			(
     (
         FlaxAlbertModel,
         FlaxAlbertForPreTraining,
         FlaxAlbertForMaskedLM,
         FlaxAlbertForMultipleChoice,
         FlaxAlbertForQuestionAnswering,
         FlaxAlbertForSequenceClassification,
         FlaxAlbertForTokenClassification,
         FlaxAlbertForQuestionAnswering,
     )
     if is_flax_available()
     else ()
 )







 def  __lowercase (		self :       Dict						):


      '''simple docstring'''






      UpperCamelCase__      :       Dict	    =  FlaxAlbertModelTester(self						)







 @slow
 def  __lowercase (		self :       List[Any]						):


      '''simple docstring'''






      for model_class_name in self.all_model_classes:
           UpperCamelCase__      :       str	    =  model_class_name.from_pretrained("albert-base-v2"						)
           UpperCamelCase__      :       List[Any]	    =  model(np.ones((1, 1)						)						)
           self.assertIsNotNone(_lowerCamelCase						)







@require_flax
class       __a  (   unittest.TestCase	):







 @slow
 def  __lowercase (		self :       Optional[int]						):


      '''simple docstring'''






      UpperCamelCase__      :       List[Any]	    =  FlaxAlbertModel.from_pretrained("albert-base-v2"						)
      UpperCamelCase__      :       List[Any]	    =  np.array([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]]						)
      UpperCamelCase__      :       Tuple	    =  np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
      UpperCamelCase__      :       List[str]	    =  model(_lowerCamelCase							,       attention_mask=_lowerCamelCase						)[0]
      UpperCamelCase__      :       str	    =  (1, 11, 7_68)
      self.assertEqual(output.shape							,       _lowerCamelCase						)
      UpperCamelCase__      :       str	    =  np.array(
          [[[-0.6_5_1_3, 1.5_0_3_5, -0.2_7_6_6], [-0.6_5_1_5, 1.5_0_4_6, -0.2_7_8_0], [-0.6_5_1_2, 1.5_0_4_9, -0.2_7_8_4]]]						)

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







import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import GLPNImageProcessor





class       __a  (   unittest.TestCase	):







 def __init__(		self :       Tuple							,       SCREAMING_SNAKE_CASE :       Optional[int]							,       SCREAMING_SNAKE_CASE :       List[Any]=7							,       SCREAMING_SNAKE_CASE :       str=3							,       SCREAMING_SNAKE_CASE :       Dict=18							,       SCREAMING_SNAKE_CASE :       str=30							,       SCREAMING_SNAKE_CASE :       Union[str, Any]=4_00							,       SCREAMING_SNAKE_CASE :       int=True							,       SCREAMING_SNAKE_CASE :       Any=32							,       SCREAMING_SNAKE_CASE :       int=True							,       ):


      '''simple docstring'''






      UpperCamelCase__      :       Optional[int]	    =  parent
      UpperCamelCase__      :       Dict	    =  batch_size
      UpperCamelCase__      :       Optional[Any]	    =  num_channels
      UpperCamelCase__      :       int	    =  image_size
      UpperCamelCase__      :       Dict	    =  min_resolution
      UpperCamelCase__      :       List[str]	    =  max_resolution
      UpperCamelCase__      :       Union[str, Any]	    =  do_resize
      UpperCamelCase__      :       Optional[Any]	    =  size_divisor
      UpperCamelCase__      :       int	    =  do_rescale







 def  __lowercase (		self :       Union[str, Any]						):


      '''simple docstring'''






      return {
          "do_resize": self.do_resize,
          "size_divisor": self.size_divisor,
          "do_rescale": self.do_rescale,
      }







@require_torch
@require_vision
class       __a  (   A__	,       unittest.TestCase	):
 _lowerCAmelCase	:	List[Any]				=			GLPNImageProcessor if is_vision_available() else None







 def  __lowercase (		self :       Optional[int]						):


      '''simple docstring'''






      UpperCamelCase__      :       Tuple	    =  GLPNImageProcessingTester(self						)







 @property
 def  __lowercase (		self :       int						):


      '''simple docstring'''






      return self.image_processor_tester.prepare_image_processor_dict()







 def  __lowercase (		self :       List[Any]						):


      '''simple docstring'''






      UpperCamelCase__      :       Optional[Any]	    =  self.image_processing_class(**self.image_processor_dict						)
      self.assertTrue(hasattr(SCREAMING_SNAKE_CASE							,       "do_resize"						)						)
      self.assertTrue(hasattr(SCREAMING_SNAKE_CASE							,       "size_divisor"						)						)
      self.assertTrue(hasattr(SCREAMING_SNAKE_CASE							,       "resample"						)						)
      self.assertTrue(hasattr(SCREAMING_SNAKE_CASE							,       "do_rescale"						)						)







 def  __lowercase (		self :       List[str]						):


      '''simple docstring'''






      pass







 def  __lowercase (		self :       Optional[Any]						):


      '''simple docstring'''






      UpperCamelCase__      :       Any	    =  self.image_processing_class(**self.image_processor_dict						)
      # create random PIL images
      UpperCamelCase__      :       Tuple	    =  prepare_image_inputs(self.image_processor_tester							,       equal_resolution=SCREAMING_SNAKE_CASE						)
      for image in image_inputs:
           self.assertIsInstance(SCREAMING_SNAKE_CASE							,       Image.Image						)

      # Test not batched input (GLPNImageProcessor doesn't support batching)
      UpperCamelCase__      :       List[Any]	    =  image_processing(image_inputs[0]							,       return_tensors="pt"						).pixel_values
      self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0						)
      self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0						)







 def  __lowercase (		self :       Any						):


      '''simple docstring'''






      UpperCamelCase__      :       Optional[Any]	    =  self.image_processing_class(**self.image_processor_dict						)
      # create random numpy tensors
      UpperCamelCase__      :       Optional[Any]	    =  prepare_image_inputs(self.image_processor_tester							,       equal_resolution=SCREAMING_SNAKE_CASE							,       numpify=SCREAMING_SNAKE_CASE						)
      for image in image_inputs:
           self.assertIsInstance(SCREAMING_SNAKE_CASE							,       np.ndarray						)

      # Test not batched input (GLPNImageProcessor doesn't support batching)
      UpperCamelCase__      :       str	    =  image_processing(image_inputs[0]							,       return_tensors="pt"						).pixel_values
      self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0						)
      self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0						)







 def  __lowercase (		self :       Optional[Any]						):


      '''simple docstring'''






      UpperCamelCase__      :       int	    =  self.image_processing_class(**self.image_processor_dict						)
      # create random PyTorch tensors
      UpperCamelCase__      :       Tuple	    =  prepare_image_inputs(self.image_processor_tester							,       equal_resolution=SCREAMING_SNAKE_CASE							,       torchify=SCREAMING_SNAKE_CASE						)
      for image in image_inputs:
           self.assertIsInstance(SCREAMING_SNAKE_CASE							,       torch.Tensor						)

      # Test not batched input (GLPNImageProcessor doesn't support batching)
      UpperCamelCase__      :       Dict	    =  image_processing(image_inputs[0]							,       return_tensors="pt"						).pixel_values
      self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0						)
      self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0						)