'''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 				_lowercase     (				unittest.TestCase			):


 '''simple docstring'''






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





 def a					(      self   :	Union[str, Any]							)  ->    Tuple:
  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 				_lowercase     (				UpperCAmelCase__  ,							unittest.TestCase			):


 '''simple docstring'''






 _SCREAMING_SNAKE_CASE     :       List[str]      	=					PoolFormerImageProcessor if is_vision_available() else None
 def a					(      self   :	Optional[int]							)  ->    Dict:
  __lowerCAmelCase											=						PoolFormerImageProcessingTester(self							)
 @property
 def a					(      self   :	Tuple							)  ->    Tuple:
  return self.image_processor_tester.prepare_image_processor_dict()
 def a					(      self   :	List[Any]							)  ->    List[Any]:
  __lowerCAmelCase											=						self.image_processing_class(**self.image_processor_dict							)
  self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__      ,       """do_resize_and_center_crop"""							)							)
  self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__      ,       """size"""							)							)
  self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__      ,       """crop_pct"""							)							)
  self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__      ,       """do_normalize"""							)							)
  self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__      ,       """image_mean"""							)							)
  self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__      ,       """image_std"""							)							)
 def a					(      self   :	int							)  ->    str:
  __lowerCAmelCase											=						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											=						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   :	List[str]							)  ->    int:
  pass
 def a					(      self   :	List[Any]							)  ->    Dict:
  # Initialize image_processing
  __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.crop_size["""height"""],
          self.image_processor_tester.crop_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.crop_size["""height"""],
          self.image_processor_tester.crop_size["""width"""],
      )      ,       )
 def a					(      self   :	str							)  ->    Union[str, Any]:
  # Initialize image_processing
  __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.crop_size["""height"""],
          self.image_processor_tester.crop_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.crop_size["""height"""],
          self.image_processor_tester.crop_size["""width"""],
      )      ,       )





 def a					(      self   :	Tuple							)  ->    List[Any]:
  # Initialize image_processing
  __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.crop_size["""height"""],
          self.image_processor_tester.crop_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.crop_size["""height"""],
          self.image_processor_tester.crop_size["""width"""],
      )      ,       )







'''simple docstring'''

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


_A			:      int					      =				logging.get_logger(__name__)

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







class 				_lowercase     (				UpperCAmelCase__			):


 '''simple docstring'''






 _SCREAMING_SNAKE_CASE     :       Any      	=					"""ctrl"""
 _SCREAMING_SNAKE_CASE     :       Optional[Any]      	=					["""past_key_values"""]
 _SCREAMING_SNAKE_CASE     :       Union[str, Any]      	=					{
     """max_position_embeddings""": """n_positions""",
     """hidden_size""": """n_embd""",
     """num_attention_heads""": """n_head""",
     """num_hidden_layers""": """n_layer""",
 }
 def __init__(      self   :	Any      ,       SCREAMING_SNAKE_CASE__   :	Optional[Any]=24_65_34      ,       SCREAMING_SNAKE_CASE__   :	Optional[int]=2_56      ,       SCREAMING_SNAKE_CASE__   :	Optional[Any]=12_80      ,       SCREAMING_SNAKE_CASE__   :	str=81_92      ,       SCREAMING_SNAKE_CASE__   :	List[str]=48      ,       SCREAMING_SNAKE_CASE__   :	Tuple=16      ,       SCREAMING_SNAKE_CASE__   :	str=0.1      ,       SCREAMING_SNAKE_CASE__   :	Dict=0.1      ,       SCREAMING_SNAKE_CASE__   :	Dict=1e-6      ,       SCREAMING_SNAKE_CASE__   :	Any=0.0_2      ,       SCREAMING_SNAKE_CASE__   :	Tuple=True      ,       **SCREAMING_SNAKE_CASE__   :	Optional[int]      ,       )  ->    Tuple:
  __lowerCAmelCase											=						vocab_size
  __lowerCAmelCase											=						n_positions
  __lowerCAmelCase											=						n_embd
  __lowerCAmelCase											=						n_layer
  __lowerCAmelCase											=						n_head
  __lowerCAmelCase											=						dff
  __lowerCAmelCase											=						resid_pdrop
  __lowerCAmelCase											=						embd_pdrop
  __lowerCAmelCase											=						layer_norm_epsilon
  __lowerCAmelCase											=						initializer_range

  __lowerCAmelCase											=						use_cache

  super().__init__(**SCREAMING_SNAKE_CASE__							)






