"""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


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image

     from transformers import SwinaSRImageProcessor
     from transformers.image_transforms import get_image_size






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=1 / 255 ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=8 ,				):


      '''simple docstring'''

      __lowerCamelCase    		=					parent
      __lowerCamelCase    		=					batch_size
      __lowerCamelCase    		=					num_channels
      __lowerCamelCase    		=					image_size
      __lowerCamelCase    		=					min_resolution
      __lowerCamelCase    		=					max_resolution
      __lowerCamelCase    		=					do_rescale
      __lowerCamelCase    		=					rescale_factor
      __lowerCamelCase    		=					do_pad
      __lowerCamelCase    		=					pad_size







   def    _A				(	self	):


      '''simple docstring'''

      return {
          "do_rescale": self.do_rescale,
          "rescale_factor": self.rescale_factor,
          "do_pad": self.do_pad,
          "pad_size": self.pad_size,
      }







   def    _A				(	self ,				_SCREAMING_SNAKE_CASE=False ,				_SCREAMING_SNAKE_CASE=False ,				_SCREAMING_SNAKE_CASE=False	):


      '''simple docstring'''

      assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

      if equal_resolution:
         __lowerCamelCase    		=					[]
         for i in range(self.batch_size	):
            image_inputs.append(
                np.random.randint(
                    255 ,				size=(self.num_channels, self.max_resolution, self.max_resolution) ,				dtype=np.uinta	)	)
      else:
         __lowerCamelCase    		=					[]
         for i in range(self.batch_size	):
            __lowerCamelCase		,__lowerCamelCase    		=					np.random.choice(np.arange(self.min_resolution ,				self.max_resolution	) ,				2	)
            image_inputs.append(np.random.randint(255 ,				size=(self.num_channels, width, height) ,				dtype=np.uinta	)	)

      if not numpify and not torchify:
         # PIL expects the channel dimension as last dimension
         __lowerCamelCase    		=					[Image.fromarray(np.moveaxis(_SCREAMING_SNAKE_CASE ,				0 ,				-1	)	) for x in image_inputs]

      if torchify:
         __lowerCamelCase    		=					[torch.from_numpy(_SCREAMING_SNAKE_CASE	) for x in image_inputs]

      return image_inputs






@require_torch
@require_vision
class      _SCREAMING_SNAKE_CASE							(			UpperCAmelCase    ,				unittest.TestCase				):



   '''simple docstring'''



   __UpperCAmelCase	:							List[str]    =    SwinaSRImageProcessor if is_vision_available() else None







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					SwinaSRImageProcessingTester(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 ,				'do_rescale'	)	)
      self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,				'rescale_factor'	)	)
      self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,				'do_pad'	)	)
      self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,				'pad_size'	)	)







   def    _A				(	self	):


      '''simple docstring'''

      pass







   def    _A				(	self ,				_SCREAMING_SNAKE_CASE	):


      '''simple docstring'''

      __lowerCamelCase		,__lowerCamelCase    		=					get_image_size(_SCREAMING_SNAKE_CASE	)
      __lowerCamelCase    		=					self.image_processor_tester.pad_size

      __lowerCamelCase    		=					(old_height // size + 1) * size - old_height
      __lowerCamelCase    		=					(old_width // size + 1) * size - old_width
      return old_height + pad_height, old_width + pad_width







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.image_processing_class(**self.image_processor_dict	)
      # create random PIL images
      __lowerCamelCase    		=					self.image_processor_tester.prepare_inputs(equal_resolution=_SCREAMING_SNAKE_CASE	)
      for image in image_inputs:
         self.assertIsInstance(_SCREAMING_SNAKE_CASE ,				Image.Image	)

      # Test not batched input
      __lowerCamelCase    		=					image_processor(image_inputs[0] ,				return_tensors='pt'	).pixel_values
      __lowerCamelCase		,__lowerCamelCase    		=					self.calculate_expected_size(np.array(image_inputs[0]	)	)
      self.assertEqual(
          encoded_images.shape ,				(
              1,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_width,
          ) ,				)







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.image_processing_class(**self.image_processor_dict	)
      # create random numpy tensors
      __lowerCamelCase    		=					self.image_processor_tester.prepare_inputs(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_processor(image_inputs[0] ,				return_tensors='pt'	).pixel_values
      __lowerCamelCase		,__lowerCamelCase    		=					self.calculate_expected_size(image_inputs[0]	)
      self.assertEqual(
          encoded_images.shape ,				(
              1,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_width,
          ) ,				)







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.image_processing_class(**self.image_processor_dict	)
      # create random PyTorch tensors
      __lowerCamelCase    		=					self.image_processor_tester.prepare_inputs(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_processor(image_inputs[0] ,				return_tensors='pt'	).pixel_values
      __lowerCamelCase		,__lowerCamelCase    		=					self.calculate_expected_size(image_inputs[0]	)
      self.assertEqual(
          encoded_images.shape ,				(
              1,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_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






