






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


class 	_UpperCamelCase ( unittest.TestCase							):



    '''simple docstring'''


    def __init__(      self   ,			__lowercase   ,			__lowercase=13   ,			__lowercase=3   ,			__lowercase=18   ,			__lowercase=30   ,			__lowercase=400   ,			__lowercase=True   ,			__lowercase=None   ,			__lowercase=True   ,			__lowercase=[0.5, 0.5, 0.5]   ,			__lowercase=[0.5, 0.5, 0.5]   ,			):
     UpperCAmelCase__ 						=				size if size is not None else {"""height""": 18, """width""": 18}
     UpperCAmelCase__ 						=				parent
     UpperCAmelCase__ 						=				batch_size
     UpperCAmelCase__ 						=				num_channels
     UpperCAmelCase__ 						=				image_size
     UpperCAmelCase__ 						=				min_resolution
     UpperCAmelCase__ 						=				max_resolution
     UpperCAmelCase__ 						=				do_resize
     UpperCAmelCase__ 						=				size
     UpperCAmelCase__ 						=				do_normalize
     UpperCAmelCase__ 						=				image_mean
     UpperCAmelCase__ 						=				image_std






    def 		A__      (      self			):
     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 	_UpperCamelCase ( __UpperCamelCase		,     unittest.TestCase							):



    '''simple docstring'''


    __lowercase    :   Tuple											=						EfficientNetImageProcessor if is_vision_available() else None


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				EfficientNetImageProcessorTester(self			)


    @property
    def 		A__      (      self			):
     return self.image_processor_tester.prepare_image_processor_dict()


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				self.image_processing_class(**self.image_processor_dict			)
     self.assertTrue(hasattr(__lowercase   ,			"""image_mean"""			)			)
     self.assertTrue(hasattr(__lowercase   ,			"""image_std"""			)			)
     self.assertTrue(hasattr(__lowercase   ,			"""do_normalize"""			)			)
     self.assertTrue(hasattr(__lowercase   ,			"""do_resize"""			)			)
     self.assertTrue(hasattr(__lowercase   ,			"""size"""			)			)


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				self.image_processing_class.from_dict(self.image_processor_dict			)
     self.assertEqual(image_processor.size   ,			{"""height""": 18, """width""": 18}			)

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


    def 		A__      (      self			):
     # Initialize image_processing
     UpperCAmelCase__ 						=				self.image_processing_class(**self.image_processor_dict			)
     # create random PIL images
     UpperCAmelCase__ 						=				prepare_image_inputs(self.image_processor_tester   ,			equal_resolution=__lowercase			)
     for image in image_inputs:
      self.assertIsInstance(__lowercase   ,			Image.Image			)

     # Test not batched input
     UpperCAmelCase__ 						=				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
     UpperCAmelCase__ 						=				image_processing(__lowercase   ,			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			):
     # Initialize image_processing
     UpperCAmelCase__ 						=				self.image_processing_class(**self.image_processor_dict			)
     # create random numpy tensors
     UpperCAmelCase__ 						=				prepare_image_inputs(self.image_processor_tester   ,			equal_resolution=__lowercase   ,			numpify=__lowercase			)
     for image in image_inputs:
      self.assertIsInstance(__lowercase   ,			np.ndarray			)

     # Test not batched input
     UpperCAmelCase__ 						=				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
     UpperCAmelCase__ 						=				image_processing(__lowercase   ,			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			):
     # Initialize image_processing
     UpperCAmelCase__ 						=				self.image_processing_class(**self.image_processor_dict			)
     # create random PyTorch tensors
     UpperCAmelCase__ 						=				prepare_image_inputs(self.image_processor_tester   ,			equal_resolution=__lowercase   ,			torchify=__lowercase			)
     for image in image_inputs:
      self.assertIsInstance(__lowercase   ,			torch.Tensor			)

     # Test not batched input
     UpperCAmelCase__ 						=				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
     UpperCAmelCase__ 						=				image_processing(__lowercase   ,			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


a  :						Optional[Any]					       =							logging.get_logger(__name__)

a  :						int					       =							{
    '''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 	_UpperCamelCase ( __UpperCamelCase							):



    '''simple docstring'''


    __lowercase    :   Optional[Any]											=						'opt'
    __lowercase    :   str											=						['past_key_values']


    def __init__(      self   ,			__lowercase=50272   ,			__lowercase=768   ,			__lowercase=12   ,			__lowercase=3072   ,			__lowercase=2048   ,			__lowercase=True   ,			__lowercase=False   ,			__lowercase=None   ,			__lowercase=0.1   ,			__lowercase=0.0   ,			__lowercase=12   ,			__lowercase="relu"   ,			__lowercase=0.0   ,			__lowercase=0.02   ,			__lowercase=True   ,			__lowercase=1   ,			__lowercase=2   ,			__lowercase=2   ,			__lowercase=True   ,			__lowercase=True   ,			**__lowercase   ,			):
     super().__init__(
         pad_token_id=__lowercase   ,			bos_token_id=__lowercase   ,			eos_token_id=__lowercase   ,			**__lowercase   ,			)
     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



