"""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 PoolFormerImageProcessor
class 						__A							( unittest.TestCase		):






     def __init__(		self				,     a__				,     a__=7				,     a__=3				,     a__=30				,     a__=400				,     a__=True				,     a__=None				,     a__=0.9				,     a__=None				,     a__=True				,     a__=[0.5, 0.5, 0.5]				,     a__=[0.5, 0.5, 0.5]				,     ):
       _lowerCAmelCase						:       Dict  			=     size if size is not None else {"""shortest_edge""": 30}
       _lowerCAmelCase						:       Union[str, Any]  			=     crop_size if crop_size is not None else {"""height""": 30, """width""": 30}
       _lowerCAmelCase						:       List[str]  			=     parent
       _lowerCAmelCase						:       int  			=     batch_size
       _lowerCAmelCase						:       Optional[Any]  			=     num_channels
       _lowerCAmelCase						:       List[Any]  			=     min_resolution
       _lowerCAmelCase						:       Tuple  			=     max_resolution
       _lowerCAmelCase						:       Optional[int]  			=     do_resize_and_center_crop
       _lowerCAmelCase						:       Dict  			=     size
       _lowerCAmelCase						:       int  			=     crop_pct
       _lowerCAmelCase						:       Optional[Any]  			=     crop_size
       _lowerCAmelCase						:       Tuple  			=     do_normalize
       _lowerCAmelCase						:       List[str]  			=     image_mean
       _lowerCAmelCase						:       Optional[Any]  			=     image_std






     def     __A  (		self  ):
       return {
           "size": self.size,
           "do_resize_and_center_crop": self.do_resize_and_center_crop,
           "crop_pct": self.crop_pct,
           "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 						__A							( SCREAMING_SNAKE_CASE_    ,	unittest.TestCase		):
     _UpperCamelCase							:			List[Any]							=		PoolFormerImageProcessor if is_vision_available() else None






     def     __A  (		self  ):
       _lowerCAmelCase						:       Tuple  			=     PoolFormerImageProcessingTester(self  )






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






     def     __A  (		self  ):
       _lowerCAmelCase						:       Dict  			=     self.image_processing_class(**self.image_processor_dict  )
       self.assertTrue(hasattr(a__				,     """do_resize_and_center_crop"""  )  )
       self.assertTrue(hasattr(a__				,     """size"""  )  )
       self.assertTrue(hasattr(a__				,     """crop_pct"""  )  )
       self.assertTrue(hasattr(a__				,     """do_normalize"""  )  )
       self.assertTrue(hasattr(a__				,     """image_mean"""  )  )
       self.assertTrue(hasattr(a__				,     """image_std"""  )  )






     def     __A  (		self  ):
       _lowerCAmelCase						:       List[Any]  			=     self.image_processing_class.from_dict(self.image_processor_dict  )
       self.assertEqual(image_processor.size				,     {"""shortest_edge""": 30}  )
       self.assertEqual(image_processor.crop_size				,     {"""height""": 30, """width""": 30}  )

       _lowerCAmelCase						:       str  			=     self.image_processing_class.from_dict(self.image_processor_dict				,     size=42				,     crop_size=84  )
       self.assertEqual(image_processor.size				,     {"""shortest_edge""": 42}  )
       self.assertEqual(image_processor.crop_size				,     {"""height""": 84, """width""": 84}  )






     def     __A  (		self  ):
       pass






     def     __A  (		self  ):
       # Initialize image_processing
       _lowerCAmelCase						:       Optional[Any]  			=     self.image_processing_class(**self.image_processor_dict  )
       # create random PIL images
       _lowerCAmelCase						:       Union[str, Any]  			=     prepare_image_inputs(self.image_processor_tester				,     equal_resolution=a__  )
       for image in image_inputs:
         self.assertIsInstance(a__				,     Image.Image  )

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

       # Test not batched input
       _lowerCAmelCase						:       Union[str, Any]  			=     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						:       List[Any]  			=     image_processing(a__				,     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  ):
       # Initialize image_processing
       _lowerCAmelCase						:       str  			=     self.image_processing_class(**self.image_processor_dict  )
       # create random PyTorch tensors
       _lowerCAmelCase						:       Dict  			=     prepare_image_inputs(self.image_processor_tester				,     equal_resolution=a__				,     torchify=a__  )
       for image in image_inputs:
         self.assertIsInstance(a__				,     torch.Tensor  )

       # Test not batched input
       _lowerCAmelCase						:       Dict  			=     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						:       Any  			=     image_processing(a__				,     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


__lowercase							 =					logging.get_logger(__name__)

__lowercase							 =					{'''ctrl''': '''https://huggingface.co/ctrl/resolve/main/config.json'''}


class 	lowerCamelCase_     (   UpperCAmelCase_ ):






    '''simple docstring'''






    a__	:						str						=      """ctrl"""
    a__	:						Dict						=      ["""past_key_values"""]
    a__	:						Tuple						=      {
        """max_position_embeddings""": """n_positions""",
        """hidden_size""": """n_embd""",
        """num_attention_heads""": """n_head""",
        """num_hidden_layers""": """n_layer""",
    }







    def __init__(	self , __lowercase=246_534 , __lowercase=256 , __lowercase=1_280 , __lowercase=8_192 , __lowercase=48 , __lowercase=16 , __lowercase=0.1 , __lowercase=0.1 , __lowercase=1E-6 , __lowercase=0.02 , __lowercase=True , **__lowercase , )       ->	List[Any]:
        __UpperCamelCase     :List[str]			  =		vocab_size
        __UpperCamelCase     :Optional[Any]			  =		n_positions
        __UpperCamelCase     :Dict			  =		n_embd
        __UpperCamelCase     :Dict			  =		n_layer
        __UpperCamelCase     :List[Any]			  =		n_head
        __UpperCamelCase     :int			  =		dff
        __UpperCamelCase     :Union[str, Any]			  =		resid_pdrop
        __UpperCamelCase     :Optional[int]			  =		embd_pdrop
        __UpperCamelCase     :List[Any]			  =		layer_norm_epsilon
        __UpperCamelCase     :Dict			  =		initializer_range

        __UpperCamelCase     :Any			  =		use_cache

        super().__init__(**__lowercase)





