code: 
  
  
  
  
  """simple docstring"""
  
  
  
  import os
  from pathlib import Path
  from typing import Dict, List
  
  import fire
  import torch
  
  from transformers import AutoModelForSeqaSeqLM, AutoTokenizer
  from transformers.utils.logging import get_logger
  
  
  SCREAMING_SNAKE_CASE       = get_logger(__name__)
  
  
  
  
  
  
  
  def 						_SCREAMING_SNAKE_CASE     (							lowercase_    ,				lowercase_		)		->	Any:
   if text.startswith(lowercase_		):
    return text[len(lowercase_		) :]
   return text  # or whatever
  
  
  
  
  
  
  
  def 						_SCREAMING_SNAKE_CASE     (							lowercase_		)		->	Optional[Any]:
   return {remove_prefix(lowercase_    ,				"model."		): v for k, v in sd.items()}
  
  
  
  
  
  
  
  def 						_SCREAMING_SNAKE_CASE     (							lowercase_		)		->	Optional[Any]:
   A__ =       {}
   for k in state_dicts[0].keys():
    A__ =       [sd[k] for sd in state_dicts]
    A__ =       sum(lowercase_		) / len(lowercase_		)
    assert isinstance(lowercase_    ,				torch.Tensor		)
    A__ =       new_t
   return new_sd
  
  
  
  
  
  
  
  def 						_SCREAMING_SNAKE_CASE     (							lowercase_    ,				lowercase_    ,				lowercase_		)		->	None:
   A__ =       AutoModelForSeqaSeqLM.from_pretrained(lowercase_		)
   if os.path.isfile(lowercase_		):
    A__ =       [pl_ckpt_path]
   else:
    assert os.path.isdir(lowercase_		)
    A__ =       list(Path(lowercase_		).glob("*.ckpt"		)		)
    assert ckpt_files, f"""could not find any ckpt files inside the {pl_ckpt_path} directory"""
  
   if len(lowercase_		) > 1:
    logger.info(f"""averaging the weights of {ckpt_files}"""		)
  
   A__ =       [sanitize(torch.load(lowercase_    ,				map_location="cpu"		)["state_dict"]		) for x in ckpt_files]
   A__ =       average_state_dicts(lowercase_		)
  
   A__ =       hf_model.load_state_dict(lowercase_    ,				strict=lowercase_		)
   assert not missing, f"""missing keys: {missing}"""
   hf_model.save_pretrained(lowercase_		)
   try:
    A__ =       AutoTokenizer.from_pretrained(lowercase_		)
    tok.save_pretrained(lowercase_		)
   except Exception:
    pass
    # dont copy tokenizer if cant
  
  
  if __name__ == "__main__":
         fire.Fire(convert_pl_to_hf)
  
  
  
  
  
  
style_context: 
  
  
  
  
  """simple docstring"""
  
  
  
  from transformers import PretrainedConfig
  
  
  
  
  class 			UpperCAmelCase_						(		A_							):
      lowercase__		      =   '''custom'''
  
  
  
  
      def __init__(					self		: Any			,				snake_case_		: List[Any]=1			,				**snake_case_		: Any   )   ->							str:
  
  
  
  
       '''simple docstring'''
  
       A__ =       attribute
       super().__init__(**snake_case_   )
  
  
  
  
  
  
  class 			UpperCAmelCase_						(		A_							):
      lowercase__		      =   '''custom'''
  
  
  
  
      def __init__(					self		: Any			,				snake_case_		: Tuple=1			,				**snake_case_		: Dict   )   ->							Any:
  
  
  
  
       '''simple docstring'''
  
       A__ =       attribute
  
  
  
  
  
  