





import unittest
from typing import Tuple

import torch

from diffusers.utils import floats_tensor, randn_tensor, torch_all_close, torch_device
from diffusers.utils.testing_utils import require_torch



@require_torch
class        _SCREAMING_SNAKE_CASE						:







 '''simple docstring'''

 @property
 def 							SCREAMING_SNAKE_CASE_ (self    :       List[Any])	->Union[str, Any]:



   '''simple docstring'''



   return self.get_dummy_input()

 @property
 def 							SCREAMING_SNAKE_CASE_ (self    :       Union[str, Any])	->Optional[int]:



   '''simple docstring'''



   if self.block_type == "down":
     return (4, 32, 16, 16)
   elif self.block_type == "mid":
     return (4, 32, 32, 32)
   elif self.block_type == "up":
     return (4, 32, 64, 64)

   raise ValueError(F"""'{self.block_type}' is not a supported block_type. Set it to 'up', 'mid', or 'down'.""")

 def 							SCREAMING_SNAKE_CASE_ (self    :       Any	,			UpperCAmelCase_    :       int=True	,			UpperCAmelCase_    :       Union[str, Any]=False	,			UpperCAmelCase_    :       List[str]=False	,			UpperCAmelCase_    :       List[str]=False	,			)	->str:



   '''simple docstring'''



   lowerCamelCase__:				str        =4
   lowerCamelCase__:				Dict        =32
   lowerCamelCase__:				int        =(32, 32)

   lowerCamelCase__:				Optional[int]        =torch.manual_seed(0)
   lowerCamelCase__:				Dict        =torch.device(UpperCAmelCase_)
   lowerCamelCase__:				int        =(batch_size, num_channels) + sizes
   lowerCamelCase__:				Union[str, Any]        =randn_tensor(UpperCAmelCase_	,			generator=UpperCAmelCase_	,			device=UpperCAmelCase_)
   lowerCamelCase__:				Optional[Any]        ={"hidden_states": hidden_states}

   if include_temb:
     lowerCamelCase__:				Any        =128
     lowerCamelCase__:				Any        =randn_tensor((batch_size, temb_channels)	,			generator=UpperCAmelCase_	,			device=UpperCAmelCase_)

   if include_res_hidden_states_tuple:
     lowerCamelCase__:				Tuple        =torch.manual_seed(1)
     lowerCamelCase__:				int        =(randn_tensor(UpperCAmelCase_	,			generator=UpperCAmelCase_	,			device=UpperCAmelCase_),)

   if include_encoder_hidden_states:
     lowerCamelCase__:				List[Any]        =floats_tensor((batch_size, 32, 32)).to(UpperCAmelCase_)

   if include_skip_sample:
     lowerCamelCase__:				int        =randn_tensor(((batch_size, 3) + sizes)	,			generator=UpperCAmelCase_	,			device=UpperCAmelCase_)

   return dummy_input

 def 							SCREAMING_SNAKE_CASE_ (self    :       int)	->Any:



   '''simple docstring'''



   lowerCamelCase__:				Union[str, Any]        ={
       "in_channels": 32,
       "out_channels": 32,
       "temb_channels": 128,
   }
   if self.block_type == "up":
     lowerCamelCase__:				Any        =32

   if self.block_type == "mid":
     init_dict.pop("out_channels")

   lowerCamelCase__:				Tuple        =self.dummy_input
   return init_dict, inputs_dict

 def 							SCREAMING_SNAKE_CASE_ (self    :       Dict	,			UpperCAmelCase_    :       Optional[int])	->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__  , lowerCamelCase__:				List[Any]        =self.prepare_init_args_and_inputs_for_common()
   lowerCamelCase__:				Optional[int]        =self.block_class(**UpperCAmelCase_)
   unet_block.to(UpperCAmelCase_)
   unet_block.eval()

   with torch.no_grad():
     lowerCamelCase__:				Union[str, Any]        =unet_block(**UpperCAmelCase_)

   if isinstance(UpperCAmelCase_	,			UpperCAmelCase_):
     lowerCamelCase__:				Tuple        =output[0]

   self.assertEqual(output.shape	,			self.output_shape)

   lowerCamelCase__:				Optional[Any]        =output[0, -1, -3:, -3:]
   lowerCamelCase__:				str        =torch.tensor(UpperCAmelCase_).to(UpperCAmelCase_)
   assert torch_all_close(output_slice.flatten()	,			UpperCAmelCase_	,			atol=5E-3)







 @unittest.skipIf(torch_device == "mps"	,			"Training is not supported in mps")
 def 							SCREAMING_SNAKE_CASE_ (self    :       Optional[Any])	->Dict:



   '''simple docstring'''



   lowerCamelCase__  , lowerCamelCase__:				Optional[int]        =self.prepare_init_args_and_inputs_for_common()
   lowerCamelCase__:				Optional[int]        =self.block_class(**UpperCAmelCase_)
   model.to(UpperCAmelCase_)
   model.train()
   lowerCamelCase__:				Any        =model(**UpperCAmelCase_)

   if isinstance(UpperCAmelCase_	,			UpperCAmelCase_):
     lowerCamelCase__:				List[Any]        =output[0]

   lowerCamelCase__:				Dict        =torch.device(UpperCAmelCase_)
   lowerCamelCase__:				Optional[int]        =randn_tensor(output.shape	,			device=UpperCAmelCase_)
   lowerCamelCase__:				Dict        =torch.nn.functional.mse_loss(UpperCAmelCase_	,			UpperCAmelCase_)
   loss.backward()








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		)					->		Optional[int]:







  """simple docstring"""





  lowerCamelCase__:				List[Any]        =None

  # source code of `config_class`
  lowerCamelCase__:				List[Any]        =inspect.getsource(__a		)
  lowerCamelCase__:				str        =_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__:				str        =ckpt_link[:-1]

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

  return checkpoint





def 					lowerCAmelCase_			(	)					->		Tuple:







  """simple docstring"""





  lowerCamelCase__:				Union[str, Any]        =[]

  for config_class in list(CONFIG_MAPPING.values()		):
    # Skip deprecated models
    if "models.deprecated" in config_class.__module__:
      continue
    lowerCamelCase__:				List[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__:				List[str]        ="\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()

