



"""simple docstring"""







import argparse
import os
import re

import packaging.version


lowercase__				   =     """examples/"""
lowercase__				   =     {
    """examples""": (re.compile(R"""^check_min_version\(\"[^\"]+\"\)\s*$""", re.MULTILINE), """check_min_version(\"VERSION\")\n"""),
    """init""": (re.compile(R"""^__version__\s+=\s+\"([^\"]+)\"\s*$""", re.MULTILINE), """__version__ = \"VERSION\"\n"""),
    """setup""": (re.compile(R"""^(\s*)version\s*=\s*\"[^\"]+\",""", re.MULTILINE), R"""\1version=\"VERSION\","""),
    """doc""": (re.compile(R"""^(\s*)release\s*=\s*\"[^\"]+\"$""", re.MULTILINE), """release = \"VERSION\"\n"""),
}
lowercase__				   =     {
    """init""": """src/diffusers/__init__.py""",
    """setup""": """setup.py""",
}
lowercase__				   =     """README.md"""

def     UpperCamelCase_   (   lowerCAmelCase__				:    Optional[int]   ,       lowerCAmelCase__				:    Optional[int]   ,       lowerCAmelCase__				:    Union[str, Any]						)						->       List[str]:

  """simple docstring"""




  with open(lowerCAmelCase__   ,       'r'   ,       encoding='utf-8'   ,       newline='\n'						) as f:
    lowerCAmelCase_       :    Union[str, Any]								=			f.read()
  lowerCAmelCase_       :    List[Any]								=			REPLACE_PATTERNS[pattern]
  lowerCAmelCase_       :    str								=			replace.replace('VERSION'   ,       lowerCAmelCase__						)
  lowerCAmelCase_       :    List[str]								=			re_pattern.sub(lowerCAmelCase__   ,       lowerCAmelCase__						)
  with open(lowerCAmelCase__   ,       'w'   ,       encoding='utf-8'   ,       newline='\n'						) as f:
    f.write(lowerCAmelCase__						)

def     UpperCamelCase_   (   lowerCAmelCase__				:    List[str]						)						->       Optional[Any]:

  """simple docstring"""




  for folder, directories, fnames in os.walk(lowerCAmelCase__						):
    # Removing some of the folders with non-actively maintained examples from the walk
    if "research_projects" in directories:
      directories.remove('research_projects'						)
    if "legacy" in directories:
      directories.remove('legacy'						)
    for fname in fnames:
      if fname.endswith('.py'						):
        update_version_in_file(os.path.join(lowerCAmelCase__   ,       lowerCAmelCase__						)   ,       lowerCAmelCase__   ,       pattern='examples'						)

def     UpperCamelCase_   (   lowerCAmelCase__				:    Optional[Any]   ,       lowerCAmelCase__				:    str=False						)						->       int:

  """simple docstring"""




  for pattern, fname in REPLACE_FILES.items():
    update_version_in_file(lowerCAmelCase__   ,       lowerCAmelCase__   ,       lowerCAmelCase__						)
  if not patch:
    update_version_in_examples(lowerCAmelCase__						)

def     UpperCamelCase_   (   )						->       List[Any]:

  """simple docstring"""




  lowerCAmelCase_       :    Tuple								=			'🤗 Transformers currently provides the following architectures'
  lowerCAmelCase_       :    List[Any]								=			'1. Want to contribute a new model?'
  with open(lowerCAmelCase__   ,       'r'   ,       encoding='utf-8'   ,       newline='\n'						) as f:
    lowerCAmelCase_       :    str								=			f.readlines()

  # Find the start of the list.
  lowerCAmelCase_       :    Dict								=			0
  while not lines[start_index].startswith(_start_prompt						):
    start_index += 1
  start_index += 1

  lowerCAmelCase_       :    Optional[Any]								=			start_index
  # Update the lines in the model list.
  while not lines[index].startswith(_end_prompt						):
    if lines[index].startswith('1.'						):
      lowerCAmelCase_       :    List[str]								=			lines[index].replace(
          'https://huggingface.co/docs/diffusers/main/model_doc'   ,       'https://huggingface.co/docs/diffusers/model_doc'   ,       )
    index += 1

  with open(lowerCAmelCase__   ,       'w'   ,       encoding='utf-8'   ,       newline='\n'						) as f:
    f.writelines(lowerCAmelCase__						)

def     UpperCamelCase_   (   )						->       List[str]:

  """simple docstring"""




  with open(REPLACE_FILES['init']   ,       'r'						) as f:
    lowerCAmelCase_       :    Any								=			f.read()
  lowerCAmelCase_       :    int								=			REPLACE_PATTERNS['init'][0].search(lowerCAmelCase__						).groups()[0]
  return packaging.version.parse(lowerCAmelCase__						)

def     UpperCamelCase_   (   lowerCAmelCase__				:    Tuple=False						)						->       Optional[int]:

  """simple docstring"""




  lowerCAmelCase_       :    Optional[Any]								=			get_version()
  if patch and default_version.is_devrelease:
    raise ValueError('Can\'t create a patch version from the dev branch, checkout a released version!'						)
  if default_version.is_devrelease:
    lowerCAmelCase_       :    str								=			default_version.base_version
  elif patch:
    lowerCAmelCase_       :    List[Any]								=			f"{default_version.major}.{default_version.minor}.{default_version.micro + 1}"
  else:
    lowerCAmelCase_       :    List[Any]								=			f"{default_version.major}.{default_version.minor + 1}.0"

  # Now let's ask nicely if that's the right one.
  lowerCAmelCase_       :    Optional[Any]								=			input(f"Which version are you releasing? [{default_version}]"						)
  if len(lowerCAmelCase__						) == 0:
    lowerCAmelCase_       :    List[Any]								=			default_version

  print(f"Updating version to {version}."						)
  global_version_update(lowerCAmelCase__   ,       patch=lowerCAmelCase__						)

def     UpperCamelCase_   (   )						->       int:

  """simple docstring"""




  lowerCAmelCase_       :    Dict								=			get_version()
  lowerCAmelCase_       :    Dict								=			f"{current_version.major}.{current_version.minor + 1}.0.dev0"
  lowerCAmelCase_       :    Optional[int]								=			current_version.base_version

  # Check with the user we got that right.
  lowerCAmelCase_       :    int								=			input(f"Which version are we developing now? [{dev_version}]"						)
  if len(lowerCAmelCase__						) == 0:
    lowerCAmelCase_       :    str								=			dev_version

  print(f"Updating version to {version}."						)
  global_version_update(lowerCAmelCase__						)


#    print("Cleaning main README, don't forget to run `make fix-copies`.")
#    clean_main_ref_in_model_list()


if __name__ == "__main__":
     lowercase__				   =     argparse.ArgumentParser()
     parser.add_argument("""--post_release""", action="""store_true""", help="""Whether this is pre or post release.""")
     parser.add_argument("""--patch""", action="""store_true""", help="""Whether or not this is a patch release.""")
     lowercase__				   =     parser.parse_args()
     if not args.post_release:
          pre_release_work(patch=args.patch)
     elif args.patch:
          print("""Nothing to do after a patch :-)""")
     else:
          post_release_work()










"""simple docstring"""







from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


lowercase__		:    Optional[int]				   =     logging.get_logger(__name__)







class 				UpperCamelCase__       (     lowercase_, lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE      =					"""maskformer-swin"""

      _SCREAMING_SNAKE_CASE      =					{
          """num_attention_heads""": """num_heads""",
          """num_hidden_layers""": """num_layers""",
      }



      def __init__(				self    :				Tuple   ,      SCREAMING_SNAKE_CASE_    :				Optional[Any]=2_2_4   ,      SCREAMING_SNAKE_CASE_    :				Union[str, Any]=4   ,      SCREAMING_SNAKE_CASE_    :				int=3   ,      SCREAMING_SNAKE_CASE_    :				Dict=9_6   ,      SCREAMING_SNAKE_CASE_    :				Optional[int]=[2, 2, 6, 2]   ,      SCREAMING_SNAKE_CASE_    :				List[Any]=[3, 6, 1_2, 2_4]   ,      SCREAMING_SNAKE_CASE_    :				List[str]=7   ,      SCREAMING_SNAKE_CASE_    :				Union[str, Any]=4.0   ,      SCREAMING_SNAKE_CASE_    :				Optional[Any]=True   ,      SCREAMING_SNAKE_CASE_    :				Tuple=0.0   ,      SCREAMING_SNAKE_CASE_    :				Union[str, Any]=0.0   ,      SCREAMING_SNAKE_CASE_    :				int=0.1   ,      SCREAMING_SNAKE_CASE_    :				Union[str, Any]="gelu"   ,      SCREAMING_SNAKE_CASE_    :				Dict=False   ,      SCREAMING_SNAKE_CASE_    :				Union[str, Any]=0.02   ,      SCREAMING_SNAKE_CASE_    :				int=1E-5   ,      SCREAMING_SNAKE_CASE_    :				Dict=None   ,      SCREAMING_SNAKE_CASE_    :				Optional[int]=None   ,      **SCREAMING_SNAKE_CASE_    :				str   ,      ):
        super().__init__(**SCREAMING_SNAKE_CASE_	)

        lowerCAmelCase_       :    Dict								=			image_size
        lowerCAmelCase_       :    Optional[Any]								=			patch_size
        lowerCAmelCase_       :    Optional[int]								=			num_channels
        lowerCAmelCase_       :    List[str]								=			embed_dim
        lowerCAmelCase_       :    Dict								=			depths
        lowerCAmelCase_       :    Optional[Any]								=			len(SCREAMING_SNAKE_CASE_	)
        lowerCAmelCase_       :    Tuple								=			num_heads
        lowerCAmelCase_       :    List[str]								=			window_size
        lowerCAmelCase_       :    Any								=			mlp_ratio
        lowerCAmelCase_       :    Any								=			qkv_bias
        lowerCAmelCase_       :    List[Any]								=			hidden_dropout_prob
        lowerCAmelCase_       :    List[Any]								=			attention_probs_dropout_prob
        lowerCAmelCase_       :    Tuple								=			drop_path_rate
        lowerCAmelCase_       :    List[str]								=			hidden_act
        lowerCAmelCase_       :    Any								=			use_absolute_embeddings
        lowerCAmelCase_       :    Optional[Any]								=			layer_norm_eps
        lowerCAmelCase_       :    str								=			initializer_range
        # we set the hidden_size attribute in order to make Swin work with VisionEncoderDecoderModel
        # this indicates the channel dimension after the last stage of the model
        lowerCAmelCase_       :    List[str]								=			int(embed_dim * 2 ** (len(SCREAMING_SNAKE_CASE_	) - 1)	)
        lowerCAmelCase_       :    List[Any]								=			['stem'] + [F"stage{idx}" for idx in range(1   ,      len(SCREAMING_SNAKE_CASE_	) + 1	)]
        lowerCAmelCase_						,lowerCAmelCase_       :    Tuple								=			get_aligned_output_features_output_indices(
            out_features=SCREAMING_SNAKE_CASE_   ,      out_indices=SCREAMING_SNAKE_CASE_   ,      stage_names=self.stage_names	)





