

'''simple docstring'''






from __future__ import annotations

import math


def 		_A     (    A__      ):






 """simple docstring"""



 if 1 < number < 4:
  # 2 and 3 are primes
  return True
 elif number < 2 or number % 2 == 0 or number % 3 == 0:
  # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
  return False

 # All primes number are in format of 6k +/- 1
 for i in range(5     ,				int(math.sqrt(A__      ) + 1      )     ,				6      ):
  if number % i == 0 or number % (i + 2) == 0:
   return False
 return True


def 		_A     (    A__      ):






 """simple docstring"""



 __lowercase							  = str(A__      )
 __lowercase							  = [n]
 for i in range(1     ,				len(A__      )      ):
  list_nums.append(int(str_num[i:]      )      )
  list_nums.append(int(str_num[:-i]      )      )
 return list_nums


def 		_A     (    A__      ):






 """simple docstring"""



 if len(str(A__      )      ) > 3:
  if not is_prime(int(str(A__      )[-3:]      )      ) or not is_prime(int(str(A__      )[:3]      )      ):
   return False
 return True


def 		_A     (    A__ = 11      ):






 """simple docstring"""



 __lowercase							  = []
 __lowercase							  = 13
 while len(A__      ) != count:
  if validate(A__      ):
   __lowercase							  = list_truncated_nums(A__      )
   if all(is_prime(A__      ) for i in list_nums      ):
    list_truncated_primes.append(A__      )
  num += 2
 return list_truncated_primes


def 		_A     (    ):






 """simple docstring"""



 return sum(compute_truncated_primes(11      )      )


if __name__ == "__main__":
 print(f'{sum(compute_truncated_primes(11)) = }')



import argparse
import os

import numpy as np
import tensorflow as tf
import torch

from transformers import BertModel



def        UpperCamelCase    (							lowerCAmelCase__ ,			lowerCAmelCase__ ,			lowerCAmelCase__		):
					'''simple docstring'''
					lowercase							=						('''dense.weight''', '''attention.self.query''', '''attention.self.key''', '''attention.self.value''')

					lowercase							=						(
					    ('''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__		)

					lowercase							=						model.state_dict()

					def to_tf_var_name(lowerCAmelCase__		):
										for patt, repl in iter(lowerCAmelCase__		):
															lowercase							=						name.replace(lowerCAmelCase__ ,			lowerCAmelCase__		)
										return f'bert/{name}'

					def create_tf_var(lowerCAmelCase__ ,			lowerCAmelCase__ ,			lowerCAmelCase__		):
										lowercase							=						tf.dtypes.as_dtype(tensor.dtype		)
										lowercase							=						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:
															lowercase							=						to_tf_var_name(lowerCAmelCase__		)
															lowercase							=						state_dict[var_name].numpy()
															if any(x in var_name for x in tensors_to_transpose		):
																				lowercase							=						torch_tensor.T
															lowercase							=						create_tf_var(tensor=lowerCAmelCase__ ,			name=lowerCAmelCase__ ,			session=lowerCAmelCase__		)
															tf.keras.backend.set_value(lowerCAmelCase__ ,			lowerCAmelCase__		)
															lowercase							=						session.run(lowerCAmelCase__		)
															print(f'Successfully created {tf_name}: {np.allclose(lowerCAmelCase__ ,			lowerCAmelCase__		)}'		)

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



def        UpperCamelCase    (							lowerCAmelCase__=None		):
					'''simple docstring'''
					lowercase							=						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'''		)
					lowercase							=						parser.parse_args(lowerCAmelCase__		)

					lowercase							=						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()




