code: 
  
  
  
  '''simple docstring'''
  
  
  
  import glob
  import os
  from typing import Dict, List, Union
  
  import torch
  
  from diffusers.utils import is_safetensors_available
  
  
  if is_safetensors_available():
   import safetensors.torch
  
  from huggingface_hub import snapshot_download
  
  from diffusers import DiffusionPipeline, __version__
  from diffusers.schedulers.scheduling_utils import SCHEDULER_CONFIG_NAME
  from diffusers.utils import CONFIG_NAME, DIFFUSERS_CACHE, ONNX_WEIGHTS_NAME, WEIGHTS_NAME
  class        UpperCAmelCase__  (    A_):
  
  
  
   def __init__(  self			)  ->							Any:
    self.register_to_config()
    super().__init__()
  
  
  
   def    __lowerCamelCase				(  self		,	lowercase		,	lowercase			)  ->							Optional[int]:
    if dicta == dicta:
     return True
    else:
     __UpperCamelCase      ,		__UpperCamelCase				      =  self._remove_meta_keys(lowercase			)
     __UpperCamelCase      ,		__UpperCamelCase				      =  self._remove_meta_keys(lowercase			)
     if configa == configa:
      print(f"Warning !: Mismatch in keys {meta_keysa} and {meta_keysa}."			)
      return True
    return False
  
  
  
   def    __lowerCamelCase				(  self		,	lowercase			)  ->							Optional[Any]:
    __UpperCamelCase				      =  []
    __UpperCamelCase				      =  config_dict.copy()
    for key in config_dict.keys():
     if key.startswith("""_"""			):
      temp_dict.pop(lowercase			)
      meta_keys.append(lowercase			)
    return (temp_dict, meta_keys)
  
  
  
   @torch.no_grad()
   def    __lowerCamelCase				(  self		,	lowercase		,	**lowercase			)  ->							Tuple:
    __UpperCamelCase				      =  kwargs.pop("""cache_dir"""		,	lowercase			)
    __UpperCamelCase				      =  kwargs.pop("""resume_download"""		,	lowercase			)
    __UpperCamelCase				      =  kwargs.pop("""force_download"""		,	lowercase			)
    __UpperCamelCase				      =  kwargs.pop("""proxies"""		,	lowercase			)
    __UpperCamelCase				      =  kwargs.pop("""local_files_only"""		,	lowercase			)
    __UpperCamelCase				      =  kwargs.pop("""use_auth_token"""		,	lowercase			)
    __UpperCamelCase				      =  kwargs.pop("""revision"""		,	lowercase			)
    __UpperCamelCase				      =  kwargs.pop("""torch_dtype"""		,	lowercase			)
    __UpperCamelCase				      =  kwargs.pop("""device_map"""		,	lowercase			)
  
    __UpperCamelCase				      =  kwargs.pop("""alpha"""		,	0.5			)
    __UpperCamelCase				      =  kwargs.pop("""interp"""		,	lowercase			)
  
    print("""Received list"""		,	lowercase			)
    print(f"Combining with alpha={alpha}, interpolation mode={interp}"			)
  
    __UpperCamelCase				      =  len(lowercase			)
    # Ignore result from model_index_json comparision of the two checkpoints
    __UpperCamelCase				      =  kwargs.pop("""force"""		,	lowercase			)
  
    # If less than 2 checkpoints, nothing to merge. If more than 3, not supported for now.
    if checkpoint_count > 3 or checkpoint_count < 2:
     raise ValueError(
         """Received incorrect number of checkpoints to merge. Ensure that either 2 or 3 checkpoints are being"""
         """ passed."""			)
  
    print("""Received the right number of checkpoints"""			)
    # chkpt0, chkpt1 = pretrained_model_name_or_path_list[0:2]
    # chkpt2 = pretrained_model_name_or_path_list[2] if checkpoint_count == 3 else None
  
    # Validate that the checkpoints can be merged
    # Step 1: Load the model config and compare the checkpoints. We'll compare the model_index.json first while ignoring the keys starting with '_'
    __UpperCamelCase				      =  []
    for pretrained_model_name_or_path in pretrained_model_name_or_path_list:
     __UpperCamelCase				      =  DiffusionPipeline.load_config(
         lowercase		,	cache_dir=lowercase		,	resume_download=lowercase		,	force_download=lowercase		,	proxies=lowercase		,	local_files_only=lowercase		,	use_auth_token=lowercase		,	revision=lowercase		,	)
     config_dicts.append(lowercase			)
  
    __UpperCamelCase				      =  True
    for idx in range(1		,	len(lowercase			)			):
     comparison_result &= self._compare_model_configs(config_dicts[idx - 1]		,	config_dicts[idx]			)
     if not force and comparison_result is False:
      raise ValueError("""Incompatible checkpoints. Please check model_index.json for the models."""			)
      print(config_dicts[0]		,	config_dicts[1]			)
    print("""Compatible model_index.json files found"""			)
    # Step 2: Basic Validation has succeeded. Let's download the models and save them into our local files.
    __UpperCamelCase				      =  []
    for pretrained_model_name_or_path, config_dict in zip(lowercase		,	lowercase			):
     __UpperCamelCase				      =  [k for k in config_dict.keys() if not k.startswith("""_"""			)]
     __UpperCamelCase				      =  [os.path.join(lowercase		,	"""*"""			) for k in folder_names]
     allow_patterns += [
         WEIGHTS_NAME,
         SCHEDULER_CONFIG_NAME,
         CONFIG_NAME,
         ONNX_WEIGHTS_NAME,
         DiffusionPipeline.config_name,
     ]
     __UpperCamelCase				      =  config_dict.get("""_class_name"""			)
     __UpperCamelCase				      =  {"""diffusers""": __version__, """pipeline_class""": requested_pipeline_class}
  
     __UpperCamelCase				      =  (
         pretrained_model_name_or_path
         if os.path.isdir(lowercase			)
         else snapshot_download(
             lowercase		,	cache_dir=lowercase		,	resume_download=lowercase		,	proxies=lowercase		,	local_files_only=lowercase		,	use_auth_token=lowercase		,	revision=lowercase		,	allow_patterns=lowercase		,	user_agent=lowercase		,	)
     )
     print("""Cached Folder"""		,	lowercase			)
     cached_folders.append(lowercase			)
  
    # Step 3:-
    # Load the first checkpoint as a diffusion pipeline and modify its module state_dict in place
    __UpperCamelCase				      =  DiffusionPipeline.from_pretrained(
        cached_folders[0]		,	torch_dtype=lowercase		,	device_map=lowercase			)
    final_pipe.to(self.device			)
  
    __UpperCamelCase				      =  None
    if len(lowercase			) > 2:
     __UpperCamelCase				      =  os.path.join(cached_folders[2]			)
  
    if interp == "sigmoid":
     __UpperCamelCase				      =  CheckpointMergerPipeline.sigmoid
    elif interp == "inv_sigmoid":
     __UpperCamelCase				      =  CheckpointMergerPipeline.inv_sigmoid
    elif interp == "add_diff":
     __UpperCamelCase				      =  CheckpointMergerPipeline.add_difference
    else:
     __UpperCamelCase				      =  CheckpointMergerPipeline.weighted_sum
  
    # Find each module's state dict.
    for attr in final_pipe.config.keys():
     if not attr.startswith("""_"""			):
      __UpperCamelCase				      =  os.path.join(cached_folders[1]		,	lowercase			)
      if os.path.exists(lowercase			):
       __UpperCamelCase				      =  [
           *glob.glob(os.path.join(lowercase		,	"""*.safetensors"""			)			),
           *glob.glob(os.path.join(lowercase		,	"""*.bin"""			)			),
       ]
       __UpperCamelCase				      =  files[0] if len(lowercase			) > 0 else None
      if len(lowercase			) < 3:
       __UpperCamelCase				      =  None
      else:
       __UpperCamelCase				      =  os.path.join(cached_folders[2]		,	lowercase			)
       if os.path.exists(lowercase			):
        __UpperCamelCase				      =  [
            *glob.glob(os.path.join(lowercase		,	"""*.safetensors"""			)			),
            *glob.glob(os.path.join(lowercase		,	"""*.bin"""			)			),
        ]
        __UpperCamelCase				      =  files[0] if len(lowercase			) > 0 else None
                  # For an attr if both checkpoint_path_1 and 2 are None, ignore.
                  # If atleast one is present, deal with it according to interp method, of course only if the state_dict keys match.
      if checkpoint_path_a is None and checkpoint_path_a is None:
       print(f"Skipping {attr}: not present in 2nd or 3d model"			)
       continue
      try:
       __UpperCamelCase				      =  getattr(lowercase		,	lowercase			)
       if isinstance(lowercase		,	lowercase			):  # ignore requires_safety_checker boolean
        continue
       __UpperCamelCase				      =  getattr(lowercase		,	"""state_dict"""			)
       __UpperCamelCase				      =  theta_a()
  
       __UpperCamelCase				      =  getattr(lowercase		,	"""load_state_dict"""			)
       __UpperCamelCase				      =  (
           safetensors.torch.load_file(lowercase			)
           if (is_safetensors_available() and checkpoint_path_a.endswith(""".safetensors"""			))
           else torch.load(lowercase		,	map_location="""cpu"""			)
       )
       __UpperCamelCase				      =  None
       if checkpoint_path_a:
        __UpperCamelCase				      =  (
            safetensors.torch.load_file(lowercase			)
            if (is_safetensors_available() and checkpoint_path_a.endswith(""".safetensors"""			))
            else torch.load(lowercase		,	map_location="""cpu"""			)
        )
  
       if not theta_a.keys() == theta_a.keys():
        print(f"Skipping {attr}: key mismatch"			)
        continue
       if theta_a and not theta_a.keys() == theta_a.keys():
        print(f"Skipping {attr}:y mismatch"			)
      except Exception as e:
       print(f"Skipping {attr} do to an unexpected error: {str(lowercase			)}"			)
       continue
      print(f"MERGING {attr}"			)
  
      for key in theta_a.keys():
       if theta_a:
        __UpperCamelCase				      =  theta_func(theta_a[key]		,	theta_a[key]		,	theta_a[key]		,	lowercase			)
       else:
        __UpperCamelCase				      =  theta_func(theta_a[key]		,	theta_a[key]		,	lowercase		,	lowercase			)
  
      del theta_a
      del theta_a
      update_theta_a(lowercase			)
  
      del theta_a
    return final_pipe
  
  
  
   @staticmethod
   def    __lowerCamelCase				(  lowercase		,	lowercase		,	lowercase		,	lowercase			)  ->							str:
    return ((1 - alpha) * thetaa) + (alpha * thetaa)
  
  
  
   @staticmethod
   def    __lowerCamelCase				(  lowercase		,	lowercase		,	lowercase		,	lowercase			)  ->							str:
    __UpperCamelCase				      =  alpha * alpha * (3 - (2 * alpha))
    return thetaa + ((thetaa - thetaa) * alpha)
  
  
  
   @staticmethod
   def    __lowerCamelCase				(  lowercase		,	lowercase		,	lowercase		,	lowercase			)  ->							Any:
    import math
  
    __UpperCamelCase				      =  0.5 - math.sin(math.asin(1.0 - 2.0 * alpha			) / 3.0			)
    return thetaa + ((thetaa - thetaa) * alpha)
  
  
  
  
   @staticmethod
   def    __lowerCamelCase				(  lowercase		,	lowercase		,	lowercase		,	lowercase			)  ->							Optional[Any]:
    return thetaa + (thetaa - thetaa) * (1.0 - alpha)
  
  
  
  
  
  
style_context: 
  
  
  
  '''simple docstring'''
  
  
  
  import argparse
  
  from transformers import TaConfig, TaForConditionalGeneration, load_tf_weights_in_ta
  from transformers.utils import logging
  
  
  logging.set_verbosity_info()
  
  
  
  
  
  
  
  def _lowercase   (  __A							,__A							,__A       ):
  
  
  
   '''simple docstring'''
  
  
  
   __UpperCamelCase				      =  TaConfig.from_json_file(__A       )
   print(f"Building PyTorch model from configuration: {config}"       )
   __UpperCamelCase				      =  TaForConditionalGeneration(__A       )
  
   # Load weights from tf checkpoint
   load_tf_weights_in_ta(__A							,__A							,__A       )
  
   # Save pytorch-model
   print(f"Save PyTorch model to {pytorch_dump_path}"       )
   model.save_pretrained(__A       )
  
  
  if __name__ == "__main__":
   a__						:			int										=			argparse.ArgumentParser()
   # Required parameters
   parser.add_argument(
       '--tf_checkpoint_path', default=None, type=str, required=True, help='Path to the TensorFlow checkpoint path.'
   )
   parser.add_argument(
       '--config_file',
       default=None,
       type=str,
       required=True,
       help=(
           'The config json file corresponding to the pre-trained T5 model. \nThis specifies the model architecture.'
       ),
   )
   parser.add_argument(
       '--pytorch_dump_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
   )
   a__						:			Optional[Any]										=			parser.parse_args()
   convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path)
  
  
  
  
  
  