





import inspect
import re

from transformers.utils import direct_transformers_import


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_config_docstrings.py
__A									=				"src/transformers"


# This is to make sure the transformers module imported is the one in the repo.
__A									=				direct_transformers_import(PATH_TO_TRANSFORMERS)

__A									=				transformers.models.auto.configuration_auto.CONFIG_MAPPING

# Regex pattern used to find the checkpoint mentioned in the docstring of `config_class`.
# For example, `[bert-base-uncased](https://huggingface.co/bert-base-uncased)`
__A									=				re.compile(R"\[(.+?)\]\((https://huggingface\.co/.+?)\)")


__A									=				{
    "DecisionTransformerConfig",
    "EncoderDecoderConfig",
    "MusicgenConfig",
    "RagConfig",
    "SpeechEncoderDecoderConfig",
    "TimmBackboneConfig",
    "VisionEncoderDecoderConfig",
    "VisionTextDualEncoderConfig",
    "LlamaConfig",
}





def      lowerCAmelCase_ (       __a		)     ->		int:







  """simple docstring"""





  lowerCamelCase__:      List[Any]			  =None

  # source code of `config_class`
  lowerCamelCase__:      List[str]			  =inspect.getsource(__a		)
  lowerCamelCase__:      List[Any]			  =_re_checkpoint.findall(__a		)

  # Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
  # For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
  for ckpt_name, ckpt_link in checkpoints:
    # allow the link to end with `/`
    if ckpt_link.endswith("/"		):
      lowerCamelCase__:      int			  =ckpt_link[:-1]

    # verify the checkpoint name corresponds to the checkpoint link
    lowerCamelCase__:      List[str]			  =F"""https://huggingface.co/{ckpt_name}"""
    if ckpt_link == ckpt_link_from_name:
      lowerCamelCase__:      str			  =ckpt_name
      break

  return checkpoint





def      lowerCAmelCase_ (       )     ->		List[str]:







  """simple docstring"""





  lowerCamelCase__:      List[Any]			  =[]

  for config_class in list(CONFIG_MAPPING.values()		):
    # Skip deprecated models
    if "models.deprecated" in config_class.__module__:
      continue
    lowerCamelCase__:      Union[str, Any]			  =get_checkpoint_from_config_class(__a		)

    lowerCamelCase__:      Tuple			  =config_class.__name__
    if checkpoint is None and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
      configs_without_checkpoint.append(__a		)

  if len(__a		) > 0:
    lowerCamelCase__:      Tuple			  ="\n".join(sorted(__a		)		)
    raise ValueError(F"""The following configurations don't contain any valid checkpoint:\n{message}"""		)


if __name__ == "__main__":
     check_config_docstrings_have_checkpoints()








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







 '''simple docstring'''

 def __init__(self				:   List[Any]       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   Dict=7       , UpperCAmelCase_				:   List[str]=3       , UpperCAmelCase_				:   str=30       , UpperCAmelCase_				:   List[str]=400       , UpperCAmelCase_				:   Optional[int]=True       , UpperCAmelCase_				:   Optional[int]=None       , UpperCAmelCase_				:   Tuple=0.9       , UpperCAmelCase_				:   str=None       , UpperCAmelCase_				:   int=True       , UpperCAmelCase_				:   Union[str, Any]=[0.5, 0.5, 0.5]       , UpperCAmelCase_				:   Optional[Any]=[0.5, 0.5, 0.5]       , )       ->str:



   '''simple docstring'''



   lowerCamelCase__:      List[Any]			  =size if size is not None else {"shortest_edge": 30}
   lowerCamelCase__:      Dict			  =crop_size if crop_size is not None else {"height": 30, "width": 30}
   lowerCamelCase__:      Any			  =parent
   lowerCamelCase__:      Any			  =batch_size
   lowerCamelCase__:      Optional[Any]			  =num_channels
   lowerCamelCase__:      Tuple			  =min_resolution
   lowerCamelCase__:      Union[str, Any]			  =max_resolution
   lowerCamelCase__:      Union[str, Any]			  =do_resize_and_center_crop
   lowerCamelCase__:      Optional[int]			  =size
   lowerCamelCase__:      str			  =crop_pct
   lowerCamelCase__:      Any			  =crop_size
   lowerCamelCase__:      List[str]			  =do_normalize
   lowerCamelCase__:      List[str]			  =image_mean
   lowerCamelCase__:      Tuple			  =image_std







 def 							SCREAMING_SNAKE_CASE_					(self				:   List[Any])       ->Optional[int]:



   '''simple docstring'''



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







 '''simple docstring'''
 lowercase_		=			PoolFormerImageProcessor if is_vision_available() else None

 def 							SCREAMING_SNAKE_CASE_					(self				:   Optional[int])       ->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:      Optional[int]			  =PoolFormerImageProcessingTester(self)

 @property
 def 							SCREAMING_SNAKE_CASE_					(self				:   str)       ->int:



   '''simple docstring'''



   return self.image_processor_tester.prepare_image_processor_dict()

 def 							SCREAMING_SNAKE_CASE_					(self				:   Optional[Any])       ->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:      Any			  =self.image_processing_class(**self.image_processor_dict)
   self.assertTrue(hasattr(UpperCAmelCase_       , "do_resize_and_center_crop"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "size"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "crop_pct"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "do_normalize"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "image_mean"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "image_std"))

 def 							SCREAMING_SNAKE_CASE_					(self				:   Any)       ->List[str]:



   '''simple docstring'''



   lowerCamelCase__:      List[str]			  =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__:      Union[str, Any]			  =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 							SCREAMING_SNAKE_CASE_					(self				:   int)       ->Optional[Any]:



   '''simple docstring'''



   pass

 def 							SCREAMING_SNAKE_CASE_					(self				:   Optional[Any])       ->Any:



   '''simple docstring'''



   lowerCamelCase__:      Union[str, 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=UpperCAmelCase_)
   for image in image_inputs:
     self.assertIsInstance(UpperCAmelCase_       , Image.Image)

   # 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__:      int			  =image_processing(UpperCAmelCase_       , 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 							SCREAMING_SNAKE_CASE_					(self				:   Optional[Any])       ->Dict:



   '''simple docstring'''



   lowerCamelCase__:      Any			  =self.image_processing_class(**self.image_processor_dict)
   # create random numpy tensors
   lowerCamelCase__:      Tuple			  =prepare_image_inputs(self.image_processor_tester       , equal_resolution=UpperCAmelCase_       , numpify=UpperCAmelCase_)
   for image in image_inputs:
     self.assertIsInstance(UpperCAmelCase_       , 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[str]			  =image_processing(UpperCAmelCase_       , 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 							SCREAMING_SNAKE_CASE_					(self				:   Union[str, Any])       ->Any:



   '''simple docstring'''



   lowerCamelCase__:      Optional[int]			  =self.image_processing_class(**self.image_processor_dict)
   # create random PyTorch tensors
   lowerCamelCase__:      Any			  =prepare_image_inputs(self.image_processor_tester       , equal_resolution=UpperCAmelCase_       , torchify=UpperCAmelCase_)
   for image in image_inputs:
     self.assertIsInstance(UpperCAmelCase_       , torch.Tensor)

   # 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(UpperCAmelCase_       , 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"],
       )       , )

