






'''simple docstring'''
import inspect
import unittest

from transformers import SegformerConfig, is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import (
      MODEL_MAPPING,
      SegformerForImageClassification,
      SegformerForSemanticSegmentation,
      SegformerModel,
  )
  from transformers.models.segformer.modeling_segformer import SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
  from PIL import Image

  from transformers import SegformerImageProcessor






class        __SCREAMING_SNAKE_CASE (     lowerCamelCase			):




 def        __magic_name__		( self		:							Optional[int] )		->  str:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=self.config_class(**self.inputs_dict )
       self.parent.assertTrue(hasattr(__lowercase   , '''hidden_sizes''' ) )
       self.parent.assertTrue(hasattr(__lowercase   , '''num_attention_heads''' ) )
       self.parent.assertTrue(hasattr(__lowercase   , '''num_encoder_blocks''' ) )






class        __SCREAMING_SNAKE_CASE :




 def __init__( self		:							Any   , __lowercase		:							List[Any]   , __lowercase		:							Optional[Any]=13   , __lowercase		:							Tuple=64   , __lowercase		:							int=3   , __lowercase		:							Dict=4   , __lowercase		:							Dict=[2, 2, 2, 2]   , __lowercase		:							Tuple=[8, 4, 2, 1]   , __lowercase		:							List[str]=[16, 32, 64, 1_28]   , __lowercase		:							Any=[1, 4, 8, 16]   , __lowercase		:							str=[1, 2, 4, 8]   , __lowercase		:							Optional[Any]=True   , __lowercase		:							int=True   , __lowercase		:							Optional[Any]="gelu"   , __lowercase		:							Tuple=0.1   , __lowercase		:							List[str]=0.1   , __lowercase		:							int=0.02   , __lowercase		:							Dict=3   , __lowercase		:							Dict=None   , )		->  str:
       SCREAMING_SNAKE_CASE__       :			str													=parent
       SCREAMING_SNAKE_CASE__       :			List[Any]													=batch_size
       SCREAMING_SNAKE_CASE__       :			List[str]													=image_size
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=num_channels
       SCREAMING_SNAKE_CASE__       :			int													=num_encoder_blocks
       SCREAMING_SNAKE_CASE__       :			Any													=sr_ratios
       SCREAMING_SNAKE_CASE__       :			Dict													=depths
       SCREAMING_SNAKE_CASE__       :			Tuple													=hidden_sizes
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=downsampling_rates
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=num_attention_heads
       SCREAMING_SNAKE_CASE__       :			List[str]													=is_training
       SCREAMING_SNAKE_CASE__       :			Tuple													=use_labels
       SCREAMING_SNAKE_CASE__       :			List[Any]													=hidden_act
       SCREAMING_SNAKE_CASE__       :			List[str]													=hidden_dropout_prob
       SCREAMING_SNAKE_CASE__       :			Any													=attention_probs_dropout_prob
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=initializer_range
       SCREAMING_SNAKE_CASE__       :			int													=num_labels
       SCREAMING_SNAKE_CASE__       :			List[Any]													=scope




 def        __magic_name__		( self		:							Optional[Any] )		->  Tuple:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size] )

       SCREAMING_SNAKE_CASE__       :			int													=None
       if self.use_labels:
             SCREAMING_SNAKE_CASE__       :			Optional[Any]													=ids_tensor([self.batch_size, self.image_size, self.image_size]   , self.num_labels )

       SCREAMING_SNAKE_CASE__       :			str													=self.get_config()
       return config, pixel_values, labels




 def        __magic_name__		( self		:							List[Any] )		->  Optional[int]:
       return SegformerConfig(
           image_size=self.image_size   , num_channels=self.num_channels   , num_encoder_blocks=self.num_encoder_blocks   , depths=self.depths   , hidden_sizes=self.hidden_sizes   , num_attention_heads=self.num_attention_heads   , hidden_act=self.hidden_act   , hidden_dropout_prob=self.hidden_dropout_prob   , attention_probs_dropout_prob=self.attention_probs_dropout_prob   , initializer_range=self.initializer_range   , )




 def        __magic_name__		( self		:							Optional[Any]   , __lowercase		:							List[Any]   , __lowercase		:							Union[str, Any]   , __lowercase		:							Dict )		->  Optional[int]:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=SegformerModel(config=__lowercase )
       model.to(__lowercase )
       model.eval()
       SCREAMING_SNAKE_CASE__       :			Tuple													=model(__lowercase )
       SCREAMING_SNAKE_CASE__       :			Any													=self.image_size // (self.downsampling_rates[-1] * 2)
       self.parent.assertEqual(
           result.last_hidden_state.shape   , (self.batch_size, self.hidden_sizes[-1], expected_height, expected_width) )




 def        __magic_name__		( self		:							List[Any]   , __lowercase		:							Optional[int]   , __lowercase		:							List[Any]   , __lowercase		:							str )		->  Tuple:
       SCREAMING_SNAKE_CASE__       :			Any													=self.num_labels
       SCREAMING_SNAKE_CASE__       :			List[Any]													=SegformerForSemanticSegmentation(__lowercase )
       model.to(__lowercase )
       model.eval()
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=model(__lowercase )
       self.parent.assertEqual(
           result.logits.shape   , (self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4) )
       SCREAMING_SNAKE_CASE__       :			Tuple													=model(__lowercase   , labels=__lowercase )
       self.parent.assertEqual(
           result.logits.shape   , (self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4) )
       self.parent.assertGreater(result.loss   , 0.0 )




 def        __magic_name__		( self		:							Any   , __lowercase		:							Union[str, Any]   , __lowercase		:							Union[str, Any]   , __lowercase		:							str )		->  List[str]:
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=1
       SCREAMING_SNAKE_CASE__       :			Tuple													=SegformerForSemanticSegmentation(config=__lowercase )
       model.to(__lowercase )
       model.eval()
       SCREAMING_SNAKE_CASE__       :			str													=torch.randint(0   , 1   , (self.batch_size, self.image_size, self.image_size) ).to(__lowercase )
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=model(__lowercase   , labels=__lowercase )
       self.parent.assertGreater(result.loss   , 0.0 )




 def        __magic_name__		( self		:							Any )		->  str:
       SCREAMING_SNAKE_CASE__       :			str													=self.prepare_config_and_inputs()
       SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__       :			str													=config_and_inputs
       SCREAMING_SNAKE_CASE__       :			Tuple													={'''pixel_values''': pixel_values}
       return config, inputs_dict






@require_torch
class        __SCREAMING_SNAKE_CASE (     lowerCamelCase		,			lowerCamelCase		,			unittest.TestCase			):
 snake_case_												=							(
     (
         SegformerModel,
         SegformerForSemanticSegmentation,
         SegformerForImageClassification,
     )
     if is_torch_available()
     else ()
 )
 snake_case_												=							(
     {
         """feature-extraction""": SegformerModel,
         """image-classification""": SegformerForImageClassification,
         """image-segmentation""": SegformerForSemanticSegmentation,
     }
     if is_torch_available()
     else {}
 )

 snake_case_												=							True
 snake_case_												=							False
 snake_case_												=							False
 snake_case_												=							False




 def        __magic_name__		( self		:							Any )		->  List[Any]:
       SCREAMING_SNAKE_CASE__       :			Tuple													=SegformerModelTester(self )
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=SegformerConfigTester(self   , config_class=__lowercase )




 def        __magic_name__		( self		:							Tuple )		->  Any:
       self.config_tester.run_common_tests()




 def        __magic_name__		( self		:							List[Any] )		->  int:
       SCREAMING_SNAKE_CASE__       :			str													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*__lowercase )




 def        __magic_name__		( self		:							List[Any] )		->  Union[str, Any]:
       SCREAMING_SNAKE_CASE__       :			List[str]													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_binary_image_segmentation(*__lowercase )




 def        __magic_name__		( self		:							Any )		->  Union[str, Any]:
       SCREAMING_SNAKE_CASE__       :			int													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_segmentation(*__lowercase )




 @unittest.skip('''SegFormer does not use inputs_embeds''' )
 def        __magic_name__		( self		:							Union[str, Any] )		->  Optional[int]:
       pass




 @unittest.skip('''SegFormer does not have get_input_embeddings method and get_output_embeddings methods''' )
 def        __magic_name__		( self		:							List[Any] )		->  int:
       pass




 def        __magic_name__		( self		:							int )		->  Union[str, Any]:
       SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__       :			List[Any]													=self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
             SCREAMING_SNAKE_CASE__       :			Optional[Any]													=model_class(__lowercase )
             SCREAMING_SNAKE_CASE__       :			List[str]													=inspect.signature(model.forward )
             # signature.parameters is an OrderedDict => so arg_names order is deterministic
             SCREAMING_SNAKE_CASE__       :			Optional[Any]													=[*signature.parameters.keys()]

             SCREAMING_SNAKE_CASE__       :			Any													=['''pixel_values''']
             self.assertListEqual(arg_names[:1]   , __lowercase )




 def        __magic_name__		( self		:							int )		->  int:
       SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__       :			Any													=self.model_tester.prepare_config_and_inputs_for_common()
       SCREAMING_SNAKE_CASE__       :			List[str]													=True

       for model_class in self.all_model_classes:
             SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=True
             SCREAMING_SNAKE_CASE__       :			Optional[Any]													=False
             SCREAMING_SNAKE_CASE__       :			Dict													=True
             SCREAMING_SNAKE_CASE__       :			str													=model_class(__lowercase )
             model.to(__lowercase )
             model.eval()
             with torch.no_grad():
                   SCREAMING_SNAKE_CASE__       :			str													=model(**self._prepare_for_class(__lowercase   , __lowercase ) )
             SCREAMING_SNAKE_CASE__       :			int													=outputs.attentions

             SCREAMING_SNAKE_CASE__       :			Optional[int]													=sum(self.model_tester.depths )
             self.assertEqual(len(__lowercase )   , __lowercase )

             # check that output_attentions also work using config
             del inputs_dict["output_attentions"]
             SCREAMING_SNAKE_CASE__       :			Optional[Any]													=True
             SCREAMING_SNAKE_CASE__       :			Optional[int]													=model_class(__lowercase )
             model.to(__lowercase )
             model.eval()
             with torch.no_grad():
                   SCREAMING_SNAKE_CASE__       :			Optional[Any]													=model(**self._prepare_for_class(__lowercase   , __lowercase ) )
             SCREAMING_SNAKE_CASE__       :			int													=outputs.attentions

             self.assertEqual(len(__lowercase )   , __lowercase )

             # verify the first attentions (first block, first layer)
             SCREAMING_SNAKE_CASE__       :			str													=(self.model_tester.image_size // 4) ** 2
             SCREAMING_SNAKE_CASE__       :			int													=(self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
             self.assertListEqual(
                 list(attentions[0].shape[-3:] )   , [self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]   , )

             # verify the last attentions (last block, last layer)
             SCREAMING_SNAKE_CASE__       :			List[str]													=(self.model_tester.image_size // 32) ** 2
             SCREAMING_SNAKE_CASE__       :			Optional[int]													=(self.model_tester.image_size // (32 * self.model_tester.sr_ratios[-1])) ** 2
             self.assertListEqual(
                 list(attentions[-1].shape[-3:] )   , [self.model_tester.num_attention_heads[-1], expected_seq_len, expected_reduced_seq_len]   , )
             SCREAMING_SNAKE_CASE__       :			str													=len(__lowercase )

             # Check attention is always last and order is fine
             SCREAMING_SNAKE_CASE__       :			Optional[int]													=True
             SCREAMING_SNAKE_CASE__       :			List[str]													=True
             SCREAMING_SNAKE_CASE__       :			Any													=model_class(__lowercase )
             model.to(__lowercase )
             model.eval()
             with torch.no_grad():
                   SCREAMING_SNAKE_CASE__       :			Optional[Any]													=model(**self._prepare_for_class(__lowercase   , __lowercase ) )

             self.assertEqual(out_len + 1   , len(__lowercase ) )

             SCREAMING_SNAKE_CASE__       :			Tuple													=outputs.attentions

             self.assertEqual(len(__lowercase )   , __lowercase )
             # verify the first attentions (first block, first layer)
             SCREAMING_SNAKE_CASE__       :			List[Any]													=(self.model_tester.image_size // 4) ** 2
             SCREAMING_SNAKE_CASE__       :			Optional[int]													=(self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
             self.assertListEqual(
                 list(self_attentions[0].shape[-3:] )   , [self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]   , )




 def        __magic_name__		( self		:							Optional[int] )		->  Dict:
       def check_hidden_states_output(__lowercase		:							List[Any]   , __lowercase		:							Tuple   , __lowercase		:							int ):
             SCREAMING_SNAKE_CASE__       :			List[Any]													=model_class(__lowercase )
             model.to(__lowercase )
             model.eval()

             with torch.no_grad():
                   SCREAMING_SNAKE_CASE__       :			Any													=model(**self._prepare_for_class(__lowercase   , __lowercase ) )

             SCREAMING_SNAKE_CASE__       :			int													=outputs.hidden_states

             SCREAMING_SNAKE_CASE__       :			Dict													=self.model_tester.num_encoder_blocks
             self.assertEqual(len(__lowercase )   , __lowercase )

             # verify the first hidden states (first block)
             self.assertListEqual(
                 list(hidden_states[0].shape[-3:] )   , [
                     self.model_tester.hidden_sizes[0],
                     self.model_tester.image_size // 4,
                     self.model_tester.image_size // 4,
                 ]   , )

       SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__       :			str													=self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
             SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=True
             check_hidden_states_output(__lowercase   , __lowercase   , __lowercase )

             # check that output_hidden_states also work using config
             del inputs_dict["output_hidden_states"]
             SCREAMING_SNAKE_CASE__       :			Any													=True

             check_hidden_states_output(__lowercase   , __lowercase   , __lowercase )




 def        __magic_name__		( self		:							Optional[int] )		->  Optional[Any]:
       if not self.model_tester.is_training:
             return

       SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__       :			Dict													=self.model_tester.prepare_config_and_inputs_for_common()
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=True

       for model_class in self.all_model_classes:
             if model_class in get_values(__lowercase ):
                   continue

             SCREAMING_SNAKE_CASE__       :			Optional[Any]													=model_class(__lowercase )
             model.to(__lowercase )
             model.train()
             SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=self._prepare_for_class(__lowercase   , __lowercase   , return_labels=__lowercase )
             SCREAMING_SNAKE_CASE__       :			Optional[Any]													=model(**__lowercase ).loss
             loss.backward()




 @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.''' )
 def        __magic_name__		( self		:							List[Any] )		->  List[str]:
       pass




 @slow
 def        __magic_name__		( self		:							Tuple )		->  Any:
       for model_name in SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             SCREAMING_SNAKE_CASE__       :			Any													=SegformerModel.from_pretrained(__lowercase )
             self.assertIsNotNone(__lowercase )





def 	_a(					):




      '''simple docstring'''






      SCREAMING_SNAKE_CASE__       :			int													=Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)
      return image







@require_torch
class        __SCREAMING_SNAKE_CASE (     unittest.TestCase			):




 @slow
 def        __magic_name__		( self		:							List[str] )		->  str:
       # only resize + normalize
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=SegformerImageProcessor(
           image_scale=(5_12, 5_12)   , keep_ratio=__lowercase   , align=__lowercase   , do_random_crop=__lowercase )
       SCREAMING_SNAKE_CASE__       :			List[str]													=SegformerForSemanticSegmentation.from_pretrained('''nvidia/segformer-b0-finetuned-ade-512-512''' ).to(
           __lowercase )

       SCREAMING_SNAKE_CASE__       :			List[Any]													=prepare_img()
       SCREAMING_SNAKE_CASE__       :			Tuple													=image_processor(images=__lowercase   , return_tensors='''pt''' )
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=encoded_inputs.pixel_values.to(__lowercase )

       with torch.no_grad():
             SCREAMING_SNAKE_CASE__       :			int													=model(__lowercase )

       SCREAMING_SNAKE_CASE__       :			Any													=torch.Size((1, model.config.num_labels, 1_28, 1_28) )
       self.assertEqual(outputs.logits.shape   , __lowercase )

       SCREAMING_SNAKE_CASE__       :			int													=torch.tensor(
           [
               [[-4.6310, -5.5232, -6.2356], [-5.1921, -6.1444, -6.5996], [-5.4424, -6.2790, -6.7574]],
               [[-12.1391, -13.3122, -13.9554], [-12.8732, -13.9352, -14.3563], [-12.9438, -13.8226, -14.2513]],
               [[-12.5134, -13.4686, -14.4915], [-12.8669, -14.4343, -14.7758], [-13.2523, -14.5819, -15.0694]],
           ] ).to(__lowercase )
       self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]   , __lowercase   , atol=1e-4 ) )




 @slow
 def        __magic_name__		( self		:							str )		->  str:
       # only resize + normalize
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=SegformerImageProcessor(
           image_scale=(5_12, 5_12)   , keep_ratio=__lowercase   , align=__lowercase   , do_random_crop=__lowercase )
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=SegformerForSemanticSegmentation.from_pretrained(
           '''nvidia/segformer-b1-finetuned-cityscapes-1024-1024''' ).to(__lowercase )

       SCREAMING_SNAKE_CASE__       :			Tuple													=prepare_img()
       SCREAMING_SNAKE_CASE__       :			Tuple													=image_processor(images=__lowercase   , return_tensors='''pt''' )
       SCREAMING_SNAKE_CASE__       :			List[str]													=encoded_inputs.pixel_values.to(__lowercase )

       with torch.no_grad():
             SCREAMING_SNAKE_CASE__       :			Optional[int]													=model(__lowercase )

       SCREAMING_SNAKE_CASE__       :			Any													=torch.Size((1, model.config.num_labels, 1_28, 1_28) )
       self.assertEqual(outputs.logits.shape   , __lowercase )

       SCREAMING_SNAKE_CASE__       :			List[Any]													=torch.tensor(
           [
               [[-13.5748, -13.9111, -12.6500], [-14.3500, -15.3683, -14.2328], [-14.7532, -16.0424, -15.6087]],
               [[-17.1651, -15.8725, -12.9653], [-17.2580, -17.3718, -14.8223], [-16.6058, -16.8783, -16.7452]],
               [[-3.6456, -3.0209, -1.4203], [-3.0797, -3.1959, -2.0000], [-1.8757, -1.9217, -1.6997]],
           ] ).to(__lowercase )
       self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]   , __lowercase   , atol=1e-1 ) )




 @slow
 def        __magic_name__		( self		:							str )		->  Union[str, Any]:
       # only resize + normalize
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=SegformerImageProcessor(
           image_scale=(5_12, 5_12)   , keep_ratio=__lowercase   , align=__lowercase   , do_random_crop=__lowercase )
       SCREAMING_SNAKE_CASE__       :			int													=SegformerForSemanticSegmentation.from_pretrained('''nvidia/segformer-b0-finetuned-ade-512-512''' ).to(
           __lowercase )

       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=prepare_img()
       SCREAMING_SNAKE_CASE__       :			List[Any]													=image_processor(images=__lowercase   , return_tensors='''pt''' )
       SCREAMING_SNAKE_CASE__       :			List[str]													=encoded_inputs.pixel_values.to(__lowercase )

       with torch.no_grad():
             SCREAMING_SNAKE_CASE__       :			Optional[Any]													=model(__lowercase )

       SCREAMING_SNAKE_CASE__       :			Any													=outputs.logits.detach().cpu()

       SCREAMING_SNAKE_CASE__       :			List[Any]													=image_processor.post_process_semantic_segmentation(outputs=__lowercase   , target_sizes=[(5_00, 3_00)] )
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=torch.Size((5_00, 3_00) )
       self.assertEqual(segmentation[0].shape   , __lowercase )

       SCREAMING_SNAKE_CASE__       :			int													=image_processor.post_process_semantic_segmentation(outputs=__lowercase )
       SCREAMING_SNAKE_CASE__       :			int													=torch.Size((1_28, 1_28) )
       self.assertEqual(segmentation[0].shape   , __lowercase )







'''simple docstring'''
import argparse
import os
import re


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_dummies.py
a_					=	'src/diffusers'

# Matches is_xxx_available()
a_					=	re.compile(R'is\_([a-z_]*)_available\(\)')
# Matches from xxx import bla
a_					=	re.compile(R'\s+from\s+\S*\s+import\s+([^\(\s].*)\n')


a_					=	'\n{0} = None\n'

a_					=	'\nclass {0}(metaclass=DummyObject):\n    _backends = {1}\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, {1})\n\n    @classmethod\n    def from_config(cls, *args, **kwargs):\n        requires_backends(cls, {1})\n\n    @classmethod\n    def from_pretrained(cls, *args, **kwargs):\n        requires_backends(cls, {1})\n'


a_					=	'\ndef {0}(*args, **kwargs):\n    requires_backends({0}, {1})\n'





def 	_a(					UpperCamelCase__			:  Any							):




      '''simple docstring'''






      SCREAMING_SNAKE_CASE__       :			Dict													=_re_backend.findall(UpperCamelCase__							)
      if len(UpperCamelCase__							) == 0:
            return None

      return "_and_".join(UpperCamelCase__							)





def 	_a(					):




      '''simple docstring'''






      with open(os.path.join(UpperCamelCase__,		'''__init__.py'''							),		'''r''',		encoding='''utf-8''',		newline='''\n'''							) as f:
            SCREAMING_SNAKE_CASE__       :			List[str]													=f.readlines()

      # Get to the point we do the actual imports for type checking
      SCREAMING_SNAKE_CASE__       :			Optional[int]													=0
      SCREAMING_SNAKE_CASE__       :			List[str]													={}
      # Go through the end of the file
      while line_index < len(UpperCamelCase__							):
            # If the line contains is_backend_available, we grab all objects associated with the `else` block
            SCREAMING_SNAKE_CASE__       :			List[Any]													=find_backend(lines[line_index]							)
            if backend is not None:
                  while not lines[line_index].startswith('''else:'''							):
                        line_index += 1
                  line_index += 1
                  SCREAMING_SNAKE_CASE__       :			List[Any]													=[]
                  # Until we unindent, add backend objects to the list
                  while line_index < len(UpperCamelCase__							) and len(lines[line_index]							) > 1:
                        SCREAMING_SNAKE_CASE__       :			Optional[Any]													=lines[line_index]
                        SCREAMING_SNAKE_CASE__       :			Optional[Any]													=_re_single_line_import.search(UpperCamelCase__							)
                        if single_line_import_search is not None:
                              objects.extend(single_line_import_search.groups()[0].split(''', '''							)							)
                        elif line.startswith(''' ''' * 8							):
                              objects.append(line[8:-2]							)
                        line_index += 1

                  if len(UpperCamelCase__							) > 0:
                        SCREAMING_SNAKE_CASE__       :			Any													=objects
            else:
                  line_index += 1

      return backend_specific_objects





def 	_a(					UpperCamelCase__			:  Union[str, Any],		UpperCamelCase__			:  List[Any]							):




      '''simple docstring'''






      if name.isupper():
            return DUMMY_CONSTANT.format(UpperCamelCase__							)
      elif name.islower():
            return DUMMY_FUNCTION.format(UpperCamelCase__,		UpperCamelCase__							)
      else:
            return DUMMY_CLASS.format(UpperCamelCase__,		UpperCamelCase__							)





def 	_a(					UpperCamelCase__			:  Any=None							):




      '''simple docstring'''






      if backend_specific_objects is None:
            SCREAMING_SNAKE_CASE__       :			int													=read_init()
      # For special correspondence backend to module name as used in the function requires_modulename
      SCREAMING_SNAKE_CASE__       :			Optional[int]													={}

      for backend, objects in backend_specific_objects.items():
            SCREAMING_SNAKE_CASE__       :			Tuple													='''[''' + ''', '''.join(f"\"{b}\"" for b in backend.split('''_and_'''							)							) + ''']'''
            SCREAMING_SNAKE_CASE__       :			List[str]													='''# This file is autogenerated by the command `make fix-copies`, do not edit.\n'''
            dummy_file += "from ..utils import DummyObject, requires_backends\n\n"
            dummy_file += "\n".join([create_dummy_object(UpperCamelCase__,		UpperCamelCase__							) for o in objects]							)
            SCREAMING_SNAKE_CASE__       :			Tuple													=dummy_file

      return dummy_files





def 	_a(					UpperCamelCase__			:  Any=False							):




      '''simple docstring'''






      SCREAMING_SNAKE_CASE__       :			Tuple													=create_dummy_files()
      # For special correspondence backend to shortcut as used in utils/dummy_xxx_objects.py
      SCREAMING_SNAKE_CASE__       :			List[str]													={'''torch''': '''pt'''}

      # Locate actual dummy modules and read their content.
      SCREAMING_SNAKE_CASE__       :			List[str]													=os.path.join(UpperCamelCase__,		'''utils'''							)
      SCREAMING_SNAKE_CASE__       :			Union[str, Any]													={
          backend: os.path.join(UpperCamelCase__,		f"dummy_{short_names.get(UpperCamelCase__,		UpperCamelCase__							)}_objects.py"							)
          for backend in dummy_files.keys()
      }

      SCREAMING_SNAKE_CASE__       :			str													={}
      for backend, file_path in dummy_file_paths.items():
            if os.path.isfile(UpperCamelCase__							):
                  with open(UpperCamelCase__,		'''r''',		encoding='''utf-8''',		newline='''\n'''							) as f:
                        SCREAMING_SNAKE_CASE__       :			List[Any]													=f.read()
            else:
                  SCREAMING_SNAKE_CASE__       :			int													=''''''

      for backend in dummy_files.keys():
            if dummy_files[backend] != actual_dummies[backend]:
                  if overwrite:
                        print(
                            f"Updating diffusers.utils.dummy_{short_names.get(UpperCamelCase__,		UpperCamelCase__							)}_objects.py as the main "
                            '''__init__ has new objects.'''							)
                        with open(dummy_file_paths[backend],		'''w''',		encoding='''utf-8''',		newline='''\n'''							) as f:
                              f.write(dummy_files[backend]							)
                  else:
                        raise ValueError(
                            '''The main __init__ has objects that are not present in '''
                            f"diffusers.utils.dummy_{short_names.get(UpperCamelCase__,		UpperCamelCase__							)}_objects.py. Run `make fix-copies` "
                            '''to fix this.'''							)


if __name__ == "__main__":
  a_					=	argparse.ArgumentParser()
  parser.add_argument('--fix_and_overwrite', action='store_true', help='Whether to fix inconsistencies.')
  a_					=	parser.parse_args()

  check_dummies(args.fix_and_overwrite)