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



   '''simple docstring'''



   def __init__(	self ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE=7 ,				_SCREAMING_SNAKE_CASE=3 ,				_SCREAMING_SNAKE_CASE=18 ,				_SCREAMING_SNAKE_CASE=30 ,				_SCREAMING_SNAKE_CASE=400 ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=None ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5] ,				_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5] ,				):


      '''simple docstring'''

      __lowerCamelCase    		=					size if 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_normalize
      __lowerCamelCase    		=					image_mean
      __lowerCamelCase    		=					image_std







   def    _A				(	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      _SCREAMING_SNAKE_CASE							(			UpperCAmelCase    ,				unittest.TestCase				):



   '''simple docstring'''



   __UpperCAmelCase	:							Any    =    ViTImageProcessor if is_vision_available() else None







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					ViTImageProcessingTester(self	)







   @property
   def    _A				(	self	):


      '''simple docstring'''

      return self.image_processor_tester.prepare_image_processor_dict()







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					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    _A				(	self	):


      '''simple docstring'''

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

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







   def    _A				(	self	):


      '''simple docstring'''

      pass







   def    _A				(	self	):


      '''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=_SCREAMING_SNAKE_CASE	)
      for image in image_inputs:
         self.assertIsInstance(_SCREAMING_SNAKE_CASE ,				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.size['height'],
              self.image_processor_tester.size['width'],
          ) ,				)

      # Test batched
      __lowerCamelCase    		=					image_processing(_SCREAMING_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    _A				(	self	):


      '''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=_SCREAMING_SNAKE_CASE ,				numpify=_SCREAMING_SNAKE_CASE	)
      for image in image_inputs:
         self.assertIsInstance(_SCREAMING_SNAKE_CASE ,				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.size['height'],
              self.image_processor_tester.size['width'],
          ) ,				)

      # Test batched
      __lowerCamelCase    		=					image_processing(_SCREAMING_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    _A				(	self	):


      '''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=_SCREAMING_SNAKE_CASE ,				torchify=_SCREAMING_SNAKE_CASE	)
      for image in image_inputs:
         self.assertIsInstance(_SCREAMING_SNAKE_CASE ,				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.size['height'],
              self.image_processor_tester.size['width'],
          ) ,				)

      # Test batched
      __lowerCamelCase    		=					image_processing(_SCREAMING_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


_SCREAMING_SNAKE_CASE	:		str   =   logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE	:		Any   =   {
    '''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      _SCREAMING_SNAKE_CASE							(			UpperCAmelCase				):



   '''simple docstring'''



   __UpperCAmelCase	:							Tuple    =    "opt"
   __UpperCAmelCase	:							Any    =    ["past_key_values"]







   def __init__(	self ,				_SCREAMING_SNAKE_CASE=50272 ,				_SCREAMING_SNAKE_CASE=768 ,				_SCREAMING_SNAKE_CASE=12 ,				_SCREAMING_SNAKE_CASE=3072 ,				_SCREAMING_SNAKE_CASE=2048 ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=False ,				_SCREAMING_SNAKE_CASE=None ,				_SCREAMING_SNAKE_CASE=0.1 ,				_SCREAMING_SNAKE_CASE=0.0 ,				_SCREAMING_SNAKE_CASE=12 ,				_SCREAMING_SNAKE_CASE="relu" ,				_SCREAMING_SNAKE_CASE=0.0 ,				_SCREAMING_SNAKE_CASE=0.02 ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=1 ,				_SCREAMING_SNAKE_CASE=2 ,				_SCREAMING_SNAKE_CASE=2 ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=True ,				**_SCREAMING_SNAKE_CASE ,				):


      '''simple docstring'''

      super().__init__(
          pad_token_id=_SCREAMING_SNAKE_CASE ,				bos_token_id=_SCREAMING_SNAKE_CASE ,				eos_token_id=_SCREAMING_SNAKE_CASE ,				**_SCREAMING_SNAKE_CASE ,				)
      __lowerCamelCase    		=					vocab_size
      __lowerCamelCase    		=					max_position_embeddings
      __lowerCamelCase    		=					num_attention_heads
      __lowerCamelCase    		=					word_embed_proj_dim if word_embed_proj_dim is not None else hidden_size
      __lowerCamelCase    		=					ffn_dim
      __lowerCamelCase    		=					hidden_size
      __lowerCamelCase    		=					num_hidden_layers
      __lowerCamelCase    		=					dropout
      __lowerCamelCase    		=					attention_dropout
      __lowerCamelCase    		=					activation_function
      __lowerCamelCase    		=					init_std
      __lowerCamelCase    		=					layerdrop
      __lowerCamelCase    		=					use_cache
      __lowerCamelCase    		=					do_layer_norm_before
      # We keep these variables at `True` for backward compatibility.
      __lowerCamelCase    		=					enable_bias
      __lowerCamelCase    		=					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
      __lowerCamelCase    		=					_remove_final_layer_norm






