



"""simple docstring"""
import argparse
import os

import numpy as np
import tensorflow as tf
import torch

from transformers import BertModel





def      __magic_name__				(							lowercase							,			lowercase							,			lowercase ):
   SCREAMING_SNAKE_CASE_: Any     			=('''dense.weight''', '''attention.self.query''', '''attention.self.key''', '''attention.self.value''')

   SCREAMING_SNAKE_CASE_: Any     			=(
       ('''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(__UpperCamelCase ):
      os.makedirs(__UpperCamelCase )

   SCREAMING_SNAKE_CASE_: str     			=model.state_dict()

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

   def create_tf_var(lowercase							,			lowercase							,			lowercase ):
      SCREAMING_SNAKE_CASE_: Tuple     			=tf.dtypes.as_dtype(tensor.dtype )
      SCREAMING_SNAKE_CASE_: str     			=tf.get_variable(dtype=__UpperCamelCase							,			shape=tensor.shape							,			name=__UpperCamelCase							,			initializer=tf.zeros_initializer() )
      session.run(tf.variables_initializer([tf_var] ) )
      session.run(__UpperCamelCase )
      return tf_var

   tf.reset_default_graph()
   with tf.Session() as session:
      for var_name in state_dict:
         SCREAMING_SNAKE_CASE_: Tuple     			=to_tf_var_name(__UpperCamelCase )
         SCREAMING_SNAKE_CASE_: List[str]     			=state_dict[var_name].numpy()
         if any(x in var_name for x in tensors_to_transpose ):
            SCREAMING_SNAKE_CASE_: Any     			=torch_tensor.T
         SCREAMING_SNAKE_CASE_: int     			=create_tf_var(tensor=__UpperCamelCase							,			name=__UpperCamelCase							,			session=__UpperCamelCase )
         tf.keras.backend.set_value(__UpperCamelCase							,			__UpperCamelCase )
         SCREAMING_SNAKE_CASE_: List[Any]     			=session.run(__UpperCamelCase )
         print(f'''Successfully created {tf_name}: {np.allclose(__UpperCamelCase							,			__UpperCamelCase )}''' )

      SCREAMING_SNAKE_CASE_: Any     			=tf.train.Saver(tf.trainable_variables() )
      saver.save(__UpperCamelCase							,			os.path.join(__UpperCamelCase							,			model_name.replace("""-"""							,			"""_""" ) + """.ckpt""" ) )





def      __magic_name__				(							lowercase=None ):
   SCREAMING_SNAKE_CASE_: Optional[int]     			=argparse.ArgumentParser()
   parser.add_argument("""--model_name"""							,			type=__UpperCamelCase							,			required=__UpperCamelCase							,			help="""model name e.g. bert-base-uncased""" )
   parser.add_argument(
       """--cache_dir"""							,			type=__UpperCamelCase							,			default=__UpperCamelCase							,			required=__UpperCamelCase							,			help="""Directory containing pytorch model""" )
   parser.add_argument("""--pytorch_model_path"""							,			type=__UpperCamelCase							,			required=__UpperCamelCase							,			help="""/path/to/<pytorch-model-name>.bin""" )
   parser.add_argument("""--tf_cache_dir"""							,			type=__UpperCamelCase							,			required=__UpperCamelCase							,			help="""Directory in which to save tensorflow model""" )
   SCREAMING_SNAKE_CASE_: Dict     			=parser.parse_args(__UpperCamelCase )

   SCREAMING_SNAKE_CASE_: List[Any]     			=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=__UpperCamelCase							,			ckpt_dir=args.tf_cache_dir							,			model_name=args.model_name )


if __name__ == "__main__":
   main()








"""simple docstring"""
def      __magic_name__				(							lowercase							,			lowercase ):
   return int((input_a, input_a).count(0 ) == 0 )





def      __magic_name__				(							):
   assert and_gate(0							,			0 ) == 0
   assert and_gate(0							,			1 ) == 0
   assert and_gate(1							,			0 ) == 0
   assert and_gate(1							,			1 ) == 1


if __name__ == "__main__":
   test_and_gate()
   print(and_gate(1, 0))
   print(and_gate(0, 0))
   print(and_gate(0, 1))
   print(and_gate(1, 1))



