





"""simple docstring"""
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 ViTImageProcessor
class lowerCamelCase__  (    unittest.TestCase				):



   def __init__(       self      ,   snake_case      ,   snake_case=7      ,   snake_case=3      ,   snake_case=1_8      ,   snake_case=3_0      ,   snake_case=4_0_0      ,   snake_case=True      ,   snake_case=None      ,   snake_case=True      ,   snake_case=[0.5, 0.5, 0.5]      ,   snake_case=[0.5, 0.5, 0.5]      ,   ) ->    Optional[int]:







      """simple docstring"""
      lowercase    :			str  =       size if size is not None else {"""height""": 1_8, """width""": 1_8}
      lowercase    :			Any  =       parent
      lowercase    :			Optional[int]  =       batch_size
      lowercase    :			int  =       num_channels
      lowercase    :			Any  =       image_size
      lowercase    :			str  =       min_resolution
      lowercase    :			Dict  =       max_resolution
      lowercase    :			str  =       do_resize
      lowercase    :			Dict  =       size
      lowercase    :			Optional[int]  =       do_normalize
      lowercase    :			Optional[Any]  =       image_mean
      lowercase    :			Dict  =       image_std





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







      """simple docstring"""
      return {
          "image_mean": self.image_mean,
          "image_std": self.image_std,
          "do_normalize": self.do_normalize,
          "do_resize": self.do_resize,
          "size": self.size,
      }




@require_torch
@require_vision
class lowerCamelCase__  (    __UpperCamelCase  ,				unittest.TestCase				):
   __UpperCAmelCase        =					ViTImageProcessor if is_vision_available() else None



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







      """simple docstring"""
      lowercase    :			int  =       ViTImageProcessingTester(self	)



   @property
   def    _UpperCAmelCase	(       self	) ->    List[Any]:







      """simple docstring"""
      return self.image_processor_tester.prepare_image_processor_dict()



   def    _UpperCAmelCase	(       self	) ->    List[Any]:







      """simple docstring"""
      lowercase    :			Any  =       self.image_processing_class(**self.image_processor_dict	)
      self.assertTrue(hasattr(snake_case      ,   """image_mean"""	)	)
      self.assertTrue(hasattr(snake_case      ,   """image_std"""	)	)
      self.assertTrue(hasattr(snake_case      ,   """do_normalize"""	)	)
      self.assertTrue(hasattr(snake_case      ,   """do_resize"""	)	)
      self.assertTrue(hasattr(snake_case      ,   """size"""	)	)



   def    _UpperCAmelCase	(       self	) ->    int:







      """simple docstring"""
      lowercase    :			str  =       self.image_processing_class.from_dict(self.image_processor_dict	)
      self.assertEqual(image_processor.size      ,   {"""height""": 1_8, """width""": 1_8}	)

      lowercase    :			Optional[int]  =       self.image_processing_class.from_dict(self.image_processor_dict      ,   size=4_2	)
      self.assertEqual(image_processor.size      ,   {"""height""": 4_2, """width""": 4_2}	)



   def    _UpperCAmelCase	(       self	) ->    int:







      """simple docstring"""
      pass



   def    _UpperCAmelCase	(       self	) ->    Tuple:







      """simple docstring"""
      lowercase    :			Tuple  =       self.image_processing_class(**self.image_processor_dict	)
      # create random PIL images
      lowercase    :			Tuple  =       prepare_image_inputs(self.image_processor_tester      ,   equal_resolution=snake_case	)
      for image in image_inputs:
         self.assertIsInstance(snake_case      ,   Image.Image	)

      # Test not batched input
      lowercase    :			Optional[int]  =       image_processing(image_inputs[0]      ,   return_tensors="""pt"""	).pixel_values
      self.assertEqual(
          encoded_images.shape      ,   (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["""height"""],
              self.image_processor_tester.size["""width"""],
          )      ,   )

      # Test batched
      lowercase    :			Optional[int]  =       image_processing(snake_case      ,   return_tensors="""pt"""	).pixel_values
      self.assertEqual(
          encoded_images.shape      ,   (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["""height"""],
              self.image_processor_tester.size["""width"""],
          )      ,   )



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







      """simple docstring"""
      lowercase    :			List[str]  =       self.image_processing_class(**self.image_processor_dict	)
      # create random numpy tensors
      lowercase    :			Union[str, Any]  =       prepare_image_inputs(self.image_processor_tester      ,   equal_resolution=snake_case      ,   numpify=snake_case	)
      for image in image_inputs:
         self.assertIsInstance(snake_case      ,   np.ndarray	)

      # Test not batched input
      lowercase    :			List[str]  =       image_processing(image_inputs[0]      ,   return_tensors="""pt"""	).pixel_values
      self.assertEqual(
          encoded_images.shape      ,   (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["""height"""],
              self.image_processor_tester.size["""width"""],
          )      ,   )

      # Test batched
      lowercase    :			int  =       image_processing(snake_case      ,   return_tensors="""pt"""	).pixel_values
      self.assertEqual(
          encoded_images.shape      ,   (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["""height"""],
              self.image_processor_tester.size["""width"""],
          )      ,   )





   def    _UpperCAmelCase	(       self	) ->    int:







      """simple docstring"""
      lowercase    :			Tuple  =       self.image_processing_class(**self.image_processor_dict	)
      # create random PyTorch tensors
      lowercase    :			Tuple  =       prepare_image_inputs(self.image_processor_tester      ,   equal_resolution=snake_case      ,   torchify=snake_case	)
      for image in image_inputs:
         self.assertIsInstance(snake_case      ,   torch.Tensor	)

      # Test not batched input
      lowercase    :			Tuple  =       image_processing(image_inputs[0]      ,   return_tensors="""pt"""	).pixel_values
      self.assertEqual(
          encoded_images.shape      ,   (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["""height"""],
              self.image_processor_tester.size["""width"""],
          )      ,   )

      # Test batched
      lowercase    :			Optional[Any]  =       image_processing(snake_case      ,   return_tensors="""pt"""	).pixel_values
      self.assertEqual(
          encoded_images.shape      ,   (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["""height"""],
              self.image_processor_tester.size["""width"""],
          )      ,   )









"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase:	int							      =logging.get_logger(__name__)

lowerCAmelCase:	int							      ={
    "bert-base-uncased": "https://huggingface.co/bert-base-uncased/resolve/main/config.json",
    # QDQBERT models can be loaded from any BERT checkpoint, available at https://huggingface.co/models?filter=bert
}
class lowerCamelCase__  (    __UpperCamelCase				):
   __UpperCAmelCase        =					"""qdqbert"""



   def __init__(       self      ,   snake_case=3_0_5_2_2      ,   snake_case=7_6_8      ,   snake_case=1_2      ,   snake_case=1_2      ,   snake_case=3_0_7_2      ,   snake_case="gelu"      ,   snake_case=0.1      ,   snake_case=0.1      ,   snake_case=5_1_2      ,   snake_case=2      ,   snake_case=0.02      ,   snake_case=1E-12      ,   snake_case=True      ,   snake_case=1      ,   snake_case=0      ,   snake_case=2      ,   **snake_case      ,   ) ->    List[str]:







      """simple docstring"""
      super().__init__(pad_token_id=snake_case      ,   bos_token_id=snake_case      ,   eos_token_id=snake_case      ,   **snake_case	)

      lowercase    :			Optional[Any]  =       vocab_size
      lowercase    :			int  =       max_position_embeddings
      lowercase    :			Dict  =       hidden_size
      lowercase    :			Union[str, Any]  =       num_hidden_layers
      lowercase    :			str  =       num_attention_heads
      lowercase    :			List[str]  =       intermediate_size
      lowercase    :			List[str]  =       hidden_act
      lowercase    :			List[str]  =       hidden_dropout_prob
      lowercase    :			Optional[Any]  =       attention_probs_dropout_prob
      lowercase    :			Optional[Any]  =       initializer_range
      lowercase    :			str  =       type_vocab_size
      lowercase    :			Optional[int]  =       layer_norm_eps
      lowercase    :			Optional[int]  =       use_cache


