





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 DeiTImageProcessor

class 	__snake_case					(      unittest.TestCase ):






    '''simple docstring'''





    def __init__( self    :		Dict      ,    snake_case    :		Optional[int]      ,    snake_case    :		int=7      ,    snake_case    :		str=3      ,    snake_case    :		List[Any]=18      ,    snake_case    :		List[Any]=30      ,    snake_case    :		List[Any]=400      ,    snake_case    :		Union[str, Any]=True      ,    snake_case    :		List[str]=None      ,    snake_case    :		str=True      ,    snake_case    :		int=None      ,    snake_case    :		List[Any]=True      ,    snake_case    :		Any=[0.5, 0.5, 0.5]      ,    snake_case    :		Optional[int]=[0.5, 0.5, 0.5]      ,    ):

      """simple docstring"""





      __lowerCAmelCase								=					size if size is not None else {'''height''': 20, '''width''': 20}
      __lowerCAmelCase								=					crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

      __lowerCAmelCase								=					parent
      __lowerCAmelCase								=					batch_size
      __lowerCAmelCase								=					num_channels
      __lowerCAmelCase								=					image_size
      __lowerCAmelCase								=					min_resolution
      __lowerCAmelCase								=					max_resolution
      __lowerCAmelCase								=					do_resize
      __lowerCAmelCase								=					size
      __lowerCAmelCase								=					do_center_crop
      __lowerCAmelCase								=					crop_size
      __lowerCAmelCase								=					do_normalize
      __lowerCAmelCase								=					image_mean
      __lowerCAmelCase								=					image_std





    def 						A		( self    :		int				):

      """simple docstring"""





      return {
          "do_resize": self.do_resize,
          "size": self.size,
          "do_center_crop": self.do_center_crop,
          "crop_size": self.crop_size,
          "do_normalize": self.do_normalize,
          "image_mean": self.image_mean,
          "image_std": self.image_std,
      }


@require_torch
@require_vision
class 	__snake_case					(      __SCREAMING_SNAKE_CASE							,					unittest.TestCase ):






    '''simple docstring'''
    _lowerCAmelCase  =						DeiTImageProcessor if is_vision_available() else None
    _lowerCAmelCase  =						True





    def 						A		( self    :		Any				):

      """simple docstring"""





      __lowerCAmelCase								=					DeiTImageProcessingTester(self				)





    @property
    def 						A		( self    :		Optional[int]				):

      """simple docstring"""





      return self.image_processor_tester.prepare_image_processor_dict()





    def 						A		( self    :		int				):

      """simple docstring"""





      __lowerCAmelCase								=					self.image_processing_class(**self.image_processor_dict				)
      self.assertTrue(hasattr(__UpperCamelCase      ,    '''do_resize'''				)				)
      self.assertTrue(hasattr(__UpperCamelCase      ,    '''size'''				)				)
      self.assertTrue(hasattr(__UpperCamelCase      ,    '''do_center_crop'''				)				)
      self.assertTrue(hasattr(__UpperCamelCase      ,    '''center_crop'''				)				)
      self.assertTrue(hasattr(__UpperCamelCase      ,    '''do_normalize'''				)				)
      self.assertTrue(hasattr(__UpperCamelCase      ,    '''image_mean'''				)				)
      self.assertTrue(hasattr(__UpperCamelCase      ,    '''image_std'''				)				)





    def 						A		( self    :		Tuple				):

      """simple docstring"""





      __lowerCAmelCase								=					self.image_processing_class.from_dict(self.image_processor_dict				)
      self.assertEqual(image_processor.size      ,    {'''height''': 20, '''width''': 20}				)
      self.assertEqual(image_processor.crop_size      ,    {'''height''': 18, '''width''': 18}				)

      __lowerCAmelCase								=					self.image_processing_class.from_dict(self.image_processor_dict      ,    size=42      ,    crop_size=84				)
      self.assertEqual(image_processor.size      ,    {'''height''': 42, '''width''': 42}				)
      self.assertEqual(image_processor.crop_size      ,    {'''height''': 84, '''width''': 84}				)





    def 						A		( self    :		Tuple				):

      """simple docstring"""





      pass





    def 						A		( self    :		str				):

      """simple docstring"""





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

      # Test not batched input
      __lowerCAmelCase								=					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.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          )      ,    )

      # Test batched
      __lowerCAmelCase								=					image_processing(__UpperCamelCase      ,    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.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          )      ,    )





    def 						A		( self    :		Any				):

      """simple docstring"""





      __lowerCAmelCase								=					self.image_processing_class(**self.image_processor_dict				)
      # create random numpy tensors
      __lowerCAmelCase								=					prepare_image_inputs(self.image_processor_tester      ,    equal_resolution=__UpperCamelCase      ,    numpify=__UpperCamelCase				)
      for image in image_inputs:
        self.assertIsInstance(__UpperCamelCase      ,    np.ndarray				)

      # Test not batched input
      __lowerCAmelCase								=					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.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          )      ,    )

      # Test batched
      __lowerCAmelCase								=					image_processing(__UpperCamelCase      ,    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.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          )      ,    )





    def 						A		( self    :		Optional[int]				):

      """simple docstring"""





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

      # Test not batched input
      __lowerCAmelCase								=					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.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          )      ,    )

      # Test batched
      __lowerCAmelCase								=					image_processing(__UpperCamelCase      ,    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.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          )      ,    )


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


_A							=       logging.get_logger(__name__)

_A							=       {
    '''facebook/opt-125m''': '''https://huggingface.co/facebook/opt-125m/blob/main/config.json''',
    '''facebook/opt-350m''': '''https://huggingface.co/facebook/opt-350m/blob/main/config.json''',
    '''facebook/opt-1.3b''': '''https://huggingface.co/facebook/opt-1.3b/blob/main/config.json''',
    '''facebook/opt-2.7b''': '''https://huggingface.co/facebook/opt-2.7b/blob/main/config.json''',
    '''facebook/opt-6.7b''': '''https://huggingface.co/facebook/opt-6.7b/blob/main/config.json''',
    '''facebook/opt-13b''': '''https://huggingface.co/facebook/opt-13b/blob/main/config.json''',
}

class 		lowercase_							(							__SCREAMING_SNAKE_CASE					):
 A__    :					Dict    =     """opt"""
 A__    :					int    =     ["""past_key_values"""]

 def __init__(   self  ,						__UpperCamelCase=5_0_2_7_2  ,						__UpperCamelCase=7_6_8  ,						__UpperCamelCase=1_2  ,						__UpperCamelCase=3_0_7_2  ,						__UpperCamelCase=2_0_4_8  ,						__UpperCamelCase=True  ,						__UpperCamelCase=False  ,						__UpperCamelCase=None  ,						__UpperCamelCase=0.1  ,						__UpperCamelCase=0.0  ,						__UpperCamelCase=1_2  ,						__UpperCamelCase="relu"  ,						__UpperCamelCase=0.0  ,						__UpperCamelCase=0.02  ,						__UpperCamelCase=True  ,						__UpperCamelCase=1  ,						__UpperCamelCase=2  ,						__UpperCamelCase=2  ,						__UpperCamelCase=True  ,						__UpperCamelCase=True  ,						**__UpperCamelCase  ,						):




        """simple docstring"""


        super().__init__(
            pad_token_id=__UpperCamelCase  ,						bos_token_id=__UpperCamelCase  ,						eos_token_id=__UpperCamelCase  ,						**__UpperCamelCase  ,						)
        UpperCamelCase_											=							vocab_size
        UpperCamelCase_											=							max_position_embeddings
        UpperCamelCase_											=							num_attention_heads
        UpperCamelCase_											=							word_embed_proj_dim if word_embed_proj_dim is not None else hidden_size
        UpperCamelCase_											=							ffn_dim
        UpperCamelCase_											=							hidden_size
        UpperCamelCase_											=							num_hidden_layers
        UpperCamelCase_											=							dropout
        UpperCamelCase_											=							attention_dropout
        UpperCamelCase_											=							activation_function
        UpperCamelCase_											=							init_std
        UpperCamelCase_											=							layerdrop
        UpperCamelCase_											=							use_cache
        UpperCamelCase_											=							do_layer_norm_before
        # We keep these variables at `True` for backward compatibility.
        UpperCamelCase_											=							enable_bias
        UpperCamelCase_											=							layer_norm_elementwise_affine

        # Note that the only purpose of `_remove_final_layer_norm` is to keep backward compatibility
        # with checkpoints that have been fine-tuned before transformers v4.20.1
        # see https://github.com/facebookresearch/metaseq/pull/164
        UpperCamelCase_											=							_remove_final_layer_norm



