





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


__lowercase							:str							=	get_logger(__name__)







def    UpperCAmelCase				(  _lowerCamelCase   :	str      , _lowerCamelCase   :	str  ):





						'''simple docstring'''


						if text.startswith(_lowerCamelCase  ):
												return text[len(_lowerCamelCase  ) :]
						return text  # or whatever







def    UpperCAmelCase				(  _lowerCamelCase   :	List[Any]  ):





						'''simple docstring'''


						return {remove_prefix(_lowerCamelCase      , "model."  ): v for k, v in sd.items()}







def    UpperCAmelCase				(  _lowerCamelCase   :	List[Dict[str, torch.Tensor]]  ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__  :					str =       {}
						for k in state_dicts[0].keys():
												SCREAMING_SNAKE_CASE__  :					List[str] =       [sd[k] for sd in state_dicts]
												SCREAMING_SNAKE_CASE__  :					Any =       sum(_lowerCamelCase  ) / len(_lowerCamelCase  )
												assert isinstance(_lowerCamelCase      , torch.Tensor  )
												SCREAMING_SNAKE_CASE__  :					Tuple =       new_t
						return new_sd







def    UpperCAmelCase				(  _lowerCamelCase   :	str      , _lowerCamelCase   :	str      , _lowerCamelCase   :	str  ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__  :					List[Any] =       AutoModelForSeqaSeqLM.from_pretrained(_lowerCamelCase  )
						if os.path.isfile(_lowerCamelCase  ):
												SCREAMING_SNAKE_CASE__  :					Optional[int] =       [pl_ckpt_path]
						else:
												assert os.path.isdir(_lowerCamelCase  )
												SCREAMING_SNAKE_CASE__  :					str =       list(Path(_lowerCamelCase  ).glob("*.ckpt"  )  )
												assert ckpt_files, f"""could not find any ckpt files inside the {pl_ckpt_path} directory"""

						if len(_lowerCamelCase  ) > 1:
												logger.info(f"""averaging the weights of {ckpt_files}"""  )

						SCREAMING_SNAKE_CASE__  :					Any =       [sanitize(torch.load(_lowerCamelCase      , map_location="cpu"  )["state_dict"]  ) for x in ckpt_files]
						SCREAMING_SNAKE_CASE__  :					Optional[Any] =       average_state_dicts(_lowerCamelCase  )

						SCREAMING_SNAKE_CASE__,				SCREAMING_SNAKE_CASE__  :					List[str] =       hf_model.load_state_dict(_lowerCamelCase      , strict=_lowerCamelCase  )
						assert not missing, f"""missing keys: {missing}"""
						hf_model.save_pretrained(_lowerCamelCase  )
						try:
												SCREAMING_SNAKE_CASE__  :					Optional[int] =       AutoTokenizer.from_pretrained(_lowerCamelCase  )
												tok.save_pretrained(_lowerCamelCase  )
						except Exception:
												pass
												# dont copy tokenizer if cant


if __name__ == "__main__":
				fire.Fire(convert_pl_to_hf)






from itertools import combinations_with_replacement







def    UpperCAmelCase				(  _lowerCamelCase   :	int = 100  ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__  :					list[int] =       [*list(range(1      , 21  )  ), 25]
						SCREAMING_SNAKE_CASE__  :					list[int] =       [2 * x for x in range(1      , 21  )] + [50]
						SCREAMING_SNAKE_CASE__  :					list[int] =       [3 * x for x in range(1      , 21  )]
						SCREAMING_SNAKE_CASE__  :					list[int] =       singles + doubles + triples + [0]

						SCREAMING_SNAKE_CASE__  :					int =       0
						SCREAMING_SNAKE_CASE__  :					int
						SCREAMING_SNAKE_CASE__  :					int
						SCREAMING_SNAKE_CASE__  :					int
						SCREAMING_SNAKE_CASE__  :					int

						for double in doubles:
												for throwa, throwa in combinations_with_replacement(_lowerCamelCase      , 2  ):
																		SCREAMING_SNAKE_CASE__  :					int =       double + throwa + throwa
																		if checkout_total < limit:
																								num_checkouts += 1

						return num_checkouts


if __name__ == "__main__":
				print(f"{solution() = }")