

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


   def __init__(					self     ,							_UpperCamelCase     ,							_UpperCamelCase=13     ,							_UpperCamelCase=3     ,							_UpperCamelCase=224     ,							_UpperCamelCase=30     ,							_UpperCamelCase=400     ,							_UpperCamelCase=True     ,							_UpperCamelCase=None     ,							_UpperCamelCase=True     ,							_UpperCamelCase=[0.5, 0.5, 0.5]     ,							_UpperCamelCase=[0.5, 0.5, 0.5]     ,							):





      """simple docstring"""





      _lowercase     : int     	=  size if size is not None else {"height": 18, "width": 18}
      _lowercase     : Optional[Any]     	=  parent
      _lowercase     : Any     	=  batch_size
      _lowercase     : List[Any]     	=  num_channels
      _lowercase     : int     	=  image_size
      _lowercase     : Union[str, Any]     	=  min_resolution
      _lowercase     : Tuple     	=  max_resolution
      _lowercase     : List[Any]     	=  do_resize
      _lowercase     : Optional[int]     	=  size
      _lowercase     : List[str]     	=  do_normalize
      _lowercase     : Tuple     	=  image_mean
      _lowercase     : int     	=  image_std






   def 		_lowerCamelCase  (					self    ):





      """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   a__    (				__lowerCAmelCase    , unittest.TestCase    ):
   _SCREAMING_SNAKE_CASE       :	Union[str, Any]      			=				ViTImageProcessor if is_vision_available() else None


   def 		_lowerCamelCase  (					self    ):





      """simple docstring"""





      _lowercase     : List[str]     	=  EfficientFormerImageProcessorTester(self    )


   @property
   def 		_lowerCamelCase  (					self    ):





      """simple docstring"""





      return self.image_proc_tester.prepare_image_processor_dict()


   def 		_lowerCamelCase  (					self    ):





      """simple docstring"""





      _lowercase     : List[str]     	=  self.image_processing_class(**self.image_processor_dict    )
      self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,							"image_mean"    )    )
      self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,							"image_std"    )    )
      self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,							"do_normalize"    )    )
      self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,							"do_resize"    )    )
      self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,							"size"    )    )


   def 		_lowerCamelCase  (					self    ):





      """simple docstring"""





      pass


   def 		_lowerCamelCase  (					self    ):





      """simple docstring"""





      _lowercase     : Any     	=  self.image_processing_class(**self.image_processor_dict    )
      # create random PIL images
      _lowercase     : Union[str, Any]     	=  prepare_image_inputs(self.image_proc_tester     ,							equal_resolution=_SCREAMING_SNAKE_CASE    )
      for image in image_inputs:
         self.assertIsInstance(_SCREAMING_SNAKE_CASE     ,							Image.Image    )

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

      # Test batched
      _lowercase     : Union[str, Any]     	=  image_processor(_SCREAMING_SNAKE_CASE     ,							return_tensors="pt"    ).pixel_values
      self.assertEqual(
          encoded_images.shape     ,							(
              self.image_proc_tester.batch_size,
              self.image_proc_tester.num_channels,
              self.image_proc_tester.size["height"],
              self.image_proc_tester.size["width"],
          )     ,							)


   def 		_lowerCamelCase  (					self    ):





      """simple docstring"""





      _lowercase     : str     	=  self.image_processing_class(**self.image_processor_dict    )
      # create random numpy tensors
      _lowercase     : Optional[int]     	=  prepare_image_inputs(self.image_proc_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
      _lowercase     : Dict     	=  image_processor(image_inputs[0]     ,							return_tensors="pt"    ).pixel_values
      self.assertEqual(
          encoded_images.shape     ,							(
              1,
              self.image_proc_tester.num_channels,
              self.image_proc_tester.size["height"],
              self.image_proc_tester.size["width"],
          )     ,							)

      # Test batched
      _lowercase     : Any     	=  image_processor(_SCREAMING_SNAKE_CASE     ,							return_tensors="pt"    ).pixel_values
      self.assertEqual(
          encoded_images.shape     ,							(
              self.image_proc_tester.batch_size,
              self.image_proc_tester.num_channels,
              self.image_proc_tester.size["height"],
              self.image_proc_tester.size["width"],
          )     ,							)






   def 		_lowerCamelCase  (					self    ):





      """simple docstring"""





      _lowercase     : Union[str, Any]     	=  self.image_processing_class(**self.image_processor_dict    )
      # create random PyTorch tensors
      _lowercase     : int     	=  prepare_image_inputs(self.image_proc_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
      _lowercase     : Any     	=  image_processor(image_inputs[0]     ,							return_tensors="pt"    ).pixel_values
      self.assertEqual(
          encoded_images.shape     ,							(
              1,
              self.image_proc_tester.num_channels,
              self.image_proc_tester.size["height"],
              self.image_proc_tester.size["width"],
          )     ,							)

      # Test batched
      _lowercase     : List[str]     	=  image_processor(_SCREAMING_SNAKE_CASE     ,							return_tensors="pt"    ).pixel_values
      self.assertEqual(
          encoded_images.shape     ,							(
              self.image_proc_tester.batch_size,
              self.image_proc_tester.num_channels,
              self.image_proc_tester.size["height"],
              self.image_proc_tester.size["width"],
          )     ,							)












'''simple docstring'''





from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase_		:     int          =		logging.get_logger(__name__)

UpperCamelCase_		:     Any          =		{
    '''tiiuae/falcon-40b''': '''https://huggingface.co/tiiuae/falcon-40b/resolve/main/config.json''',
    '''tiiuae/falcon-7b''': '''https://huggingface.co/tiiuae/falcon-7b/resolve/main/config.json''',
}

class   _a							(		__lowerCAmelCase				):
     SCREAMING_SNAKE_CASE_				:       List[str]       							=		"""falcon"""
     SCREAMING_SNAKE_CASE_				:       Optional[int]       							=		["""past_key_values"""]






     def __init__(					self   ,_SCREAMING_SNAKE_CASE=65_024   ,_SCREAMING_SNAKE_CASE=4_544   ,_SCREAMING_SNAKE_CASE=32   ,_SCREAMING_SNAKE_CASE=71   ,_SCREAMING_SNAKE_CASE=1e-5   ,_SCREAMING_SNAKE_CASE=0.0_2   ,_SCREAMING_SNAKE_CASE=True   ,_SCREAMING_SNAKE_CASE=0.0   ,_SCREAMING_SNAKE_CASE=0.0   ,_SCREAMING_SNAKE_CASE=None   ,_SCREAMING_SNAKE_CASE=False   ,_SCREAMING_SNAKE_CASE=False   ,_SCREAMING_SNAKE_CASE=True   ,_SCREAMING_SNAKE_CASE=True   ,_SCREAMING_SNAKE_CASE=False   ,_SCREAMING_SNAKE_CASE=11   ,_SCREAMING_SNAKE_CASE=11   ,**_SCREAMING_SNAKE_CASE   ,)				->     Dict:
          _snake_case				= vocab_size
          # Backward compatibility with n_embed kwarg
          _snake_case				= kwargs.pop("n_embed"   ,_SCREAMING_SNAKE_CASE       )
          _snake_case				= hidden_size if n_embed is None else n_embed
          _snake_case				= num_hidden_layers
          _snake_case				= num_attention_heads
          _snake_case				= layer_norm_epsilon
          _snake_case				= initializer_range
          _snake_case				= use_cache
          _snake_case				= hidden_dropout
          _snake_case				= attention_dropout

          _snake_case				= bos_token_id
          _snake_case				= eos_token_id
          _snake_case				= num_attention_heads if num_kv_heads is None else num_kv_heads
          _snake_case				= alibi
          _snake_case				= new_decoder_architecture
          _snake_case				= multi_query  # Ignored when new_decoder_architecture is True
          _snake_case				= parallel_attn
          _snake_case				= bias

          super().__init__(bos_token_id=_SCREAMING_SNAKE_CASE   ,eos_token_id=_SCREAMING_SNAKE_CASE   ,**_SCREAMING_SNAKE_CASE       )






     @property
     def 							_lowercase      (					self       )				->     Union[str, Any]:
          return self.hidden_size // self.num_attention_heads






     @property
     def 							_lowercase      (					self       )				->     Optional[int]:
          return not self.alibi


