




from __future__ import annotations

from collections import Counter

def       UpperCAmelCase_							(   __UpperCAmelCase		:			List[str]							)      ->				list[int]:
      SCREAMING_SNAKE_CASE_					=    [True] * n
      SCREAMING_SNAKE_CASE_					=    False
      SCREAMING_SNAKE_CASE_					=    False
      SCREAMING_SNAKE_CASE_					=    True

      for i in range(3    ,    int(n**0.5 + 1							)    ,    2							):
            SCREAMING_SNAKE_CASE_					=    i * 2
            while index < n:
                  SCREAMING_SNAKE_CASE_					=    False
                  SCREAMING_SNAKE_CASE_					=    index + i

      SCREAMING_SNAKE_CASE_					=    [2]

      for i in range(3    ,    __UpperCAmelCase    ,    2							):
            if is_prime[i]:
                  primes.append(__UpperCAmelCase							)

      return primes

def       UpperCAmelCase_							(   __UpperCAmelCase		:			Any							)      ->				list[list[int]]:
      SCREAMING_SNAKE_CASE_					=    str(__UpperCAmelCase							)
      SCREAMING_SNAKE_CASE_					=    []
      SCREAMING_SNAKE_CASE_					=    ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

      for duplicate in Counter(__UpperCAmelCase							) - Counter(set(__UpperCAmelCase							)							):
            SCREAMING_SNAKE_CASE_					=    [int(number_str.replace(__UpperCAmelCase    ,    __UpperCAmelCase							)							) for digit in digits]
            replacements.append(__UpperCAmelCase							)

      return replacements

def       UpperCAmelCase_							(   __UpperCAmelCase		:			Tuple = 8							)      ->				int:
      SCREAMING_SNAKE_CASE_					=    set()

      # Filter primes with less than 3 replaceable digits
      SCREAMING_SNAKE_CASE_					=    {
          x for x in set(prime_sieve(1_00_00_00							)							) if len(str(__UpperCAmelCase							)							) - len(set(str(__UpperCAmelCase							)							)							) >= 3
      }

      for prime in primes:
            if prime in numbers_checked:
                  continue

            SCREAMING_SNAKE_CASE_					=    digit_replacements(__UpperCAmelCase							)

            for family in replacements:
                  numbers_checked.update(__UpperCAmelCase							)
                  SCREAMING_SNAKE_CASE_					=    primes.intersection(__UpperCAmelCase							)

                  if len(__UpperCAmelCase							) != family_length:
                        continue

                  return min(__UpperCAmelCase							)

      return -1


if __name__ == "__main__":
   print(solution())





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


lowerCamelCase__				:     Optional[Any]			       =							get_logger(__name__)

def       UpperCAmelCase_							(   __UpperCAmelCase		:			str    ,    __UpperCAmelCase		:			str							)      ->				List[str]:
      if text.startswith(__UpperCAmelCase							):
            return text[len(__UpperCAmelCase							) :]
      return text  # or whatever

def       UpperCAmelCase_							(   __UpperCAmelCase		:			Union[str, Any]							)      ->				List[Any]:
      return {remove_prefix(__UpperCAmelCase    ,    'model.'							): v for k, v in sd.items()}

def       UpperCAmelCase_							(   __UpperCAmelCase		:			List[Dict[str, torch.Tensor]]							)      ->				Dict:
      SCREAMING_SNAKE_CASE_					=    {}
      for k in state_dicts[0].keys():
            SCREAMING_SNAKE_CASE_					=    [sd[k] for sd in state_dicts]
            SCREAMING_SNAKE_CASE_					=    sum(__UpperCAmelCase							) / len(__UpperCAmelCase							)
            assert isinstance(__UpperCAmelCase    ,    torch.Tensor							)
            SCREAMING_SNAKE_CASE_					=    new_t
      return new_sd

def       UpperCAmelCase_							(   __UpperCAmelCase		:			str    ,    __UpperCAmelCase		:			str    ,    __UpperCAmelCase		:			str							)      ->				None:
      SCREAMING_SNAKE_CASE_					=    AutoModelForSeqaSeqLM.from_pretrained(__UpperCAmelCase							)
      if os.path.isfile(__UpperCAmelCase							):
            SCREAMING_SNAKE_CASE_					=    [pl_ckpt_path]
      else:
            assert os.path.isdir(__UpperCAmelCase							)
            SCREAMING_SNAKE_CASE_					=    list(Path(__UpperCAmelCase							).glob('*.ckpt'							)							)
            assert ckpt_files, f"could not find any ckpt files inside the {pl_ckpt_path} directory"

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

      SCREAMING_SNAKE_CASE_					=    [sanitize(torch.load(__UpperCAmelCase    ,    map_location='cpu'							)['state_dict']							) for x in ckpt_files]
      SCREAMING_SNAKE_CASE_					=    average_state_dicts(__UpperCAmelCase							)

      SCREAMING_SNAKE_CASE_		,				SCREAMING_SNAKE_CASE_					=    hf_model.load_state_dict(__UpperCAmelCase    ,    strict=__UpperCAmelCase							)
      assert not missing, f"missing keys: {missing}"
      hf_model.save_pretrained(__UpperCAmelCase							)
      try:
            SCREAMING_SNAKE_CASE_					=    AutoTokenizer.from_pretrained(__UpperCAmelCase							)
            tok.save_pretrained(__UpperCAmelCase							)
      except Exception:
            pass
            # dont copy tokenizer if cant


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