





import argparse
import os

import numpy as np
import tensorflow as tf
import torch

from transformers import BertModel


def 	UpperCamelCase__(       UpperCamelCase__			:       Optional[Any] ,     UpperCamelCase__			:       Optional[Any] ,     UpperCamelCase__			:       Optional[int]  )->List[Any]:
       A__											=						("dense.weight", "attention.self.query", "attention.self.key", "attention.self.value")

       A__											=						(
           ("layer.", "layer_"),
           ("word_embeddings.weight", "word_embeddings"),
           ("position_embeddings.weight", "position_embeddings"),
           ("token_type_embeddings.weight", "token_type_embeddings"),
           (".", "/"),
           ("LayerNorm/weight", "LayerNorm/gamma"),
           ("LayerNorm/bias", "LayerNorm/beta"),
           ("weight", "kernel"),
       )

       if not os.path.isdir(_lowerCAmelCase  ):
              os.makedirs(_lowerCAmelCase  )

       A__											=						model.state_dict()

       def to_tf_var_name(UpperCamelCase__			:       Dict  ):
              for patt, repl in iter(_lowerCAmelCase  ):
                     A__											=						name.replace(_lowerCAmelCase ,     _lowerCAmelCase  )
              return f"bert/{name}"

       def create_tf_var(UpperCamelCase__			:       int ,     UpperCamelCase__			:       Dict ,     UpperCamelCase__			:       List[str]  ):
              A__											=						tf.dtypes.as_dtype(tensor.dtype  )
              A__											=						tf.get_variable(dtype=_lowerCAmelCase ,     shape=tensor.shape ,     name=_lowerCAmelCase ,     initializer=tf.zeros_initializer()  )
              session.run(tf.variables_initializer([tf_var]  )  )
              session.run(_lowerCAmelCase  )
              return tf_var

       tf.reset_default_graph()
       with tf.Session() as session:
              for var_name in state_dict:
                     A__											=						to_tf_var_name(_lowerCAmelCase  )
                     A__											=						state_dict[var_name].numpy()
                     if any(x in var_name for x in tensors_to_transpose  ):
                            A__											=						torch_tensor.T
                     A__											=						create_tf_var(tensor=_lowerCAmelCase ,     name=_lowerCAmelCase ,     session=_lowerCAmelCase  )
                     tf.keras.backend.set_value(_lowerCAmelCase ,     _lowerCAmelCase  )
                     A__											=						session.run(_lowerCAmelCase  )
                     print(f"Successfully created {tf_name}: {np.allclose(_lowerCAmelCase ,     _lowerCAmelCase  )}"  )

              A__											=						tf.train.Saver(tf.trainable_variables()  )
              saver.save(_lowerCAmelCase ,     os.path.join(_lowerCAmelCase ,     model_name.replace('''-''' ,     '''_'''  ) + '''.ckpt'''  )  )


def 	UpperCamelCase__(       UpperCamelCase__			:       int=None  )->Dict:
       A__											=						argparse.ArgumentParser()
       parser.add_argument('''--model_name''' ,     type=_lowerCAmelCase ,     required=_lowerCAmelCase ,     help='''model name e.g. bert-base-uncased'''  )
       parser.add_argument(
           '''--cache_dir''' ,     type=_lowerCAmelCase ,     default=_lowerCAmelCase ,     required=_lowerCAmelCase ,     help='''Directory containing pytorch model'''  )
       parser.add_argument('''--pytorch_model_path''' ,     type=_lowerCAmelCase ,     required=_lowerCAmelCase ,     help='''/path/to/<pytorch-model-name>.bin'''  )
       parser.add_argument('''--tf_cache_dir''' ,     type=_lowerCAmelCase ,     required=_lowerCAmelCase ,     help='''Directory in which to save tensorflow model'''  )
       A__											=						parser.parse_args(_lowerCAmelCase  )

       A__											=						BertModel.from_pretrained(
           pretrained_model_name_or_path=args.model_name ,     state_dict=torch.load(args.pytorch_model_path  ) ,     cache_dir=args.cache_dir ,     )

       convert_pytorch_checkpoint_to_tf(model=_lowerCAmelCase ,     ckpt_dir=args.tf_cache_dir ,     model_name=args.model_name  )


if __name__ == "__main__":
       main()












from __future__ import annotations

from functools import lru_cache
from math import ceil

__lowerCamelCase       :     str   =     100

__lowerCamelCase       :     Any   =     set(range(3, NUM_PRIMES, 2))
primes.add(2)
__lowerCamelCase       :     int

for prime in range(3, ceil(NUM_PRIMES**0.5), 2):
    if prime not in primes:
        continue
    primes.difference_update(set(range(prime * prime, NUM_PRIMES, prime)))



@lru_cache(maxsize=100     )
def 		A_				(     _lowerCAmelCase     )						-> set[int]:
 if number_to_partition < 0:
  return set()
 elif number_to_partition == 0:
  return {1}

 UpperCamelCase	:					set[int]       	=   set()
 UpperCamelCase	:					int
 UpperCamelCase	:					int

 for prime in primes:
  if prime > number_to_partition:
   continue
  for sub in partition(number_to_partition - prime     ):
   ret.add(sub * prime     )

 return ret



def 		A_				(     _lowerCAmelCase = 5000     )						-> int | None:
 for number_to_partition in range(1							,   _lowerCAmelCase     ):
  if len(partition(_lowerCAmelCase     )     ) > number_unique_partitions:
   return number_to_partition
 return None


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