code: 
  
  
  
  import os
  from typing import List, Union
  
  import tensorflow as tf
  from tensorflow_text import BertTokenizer as BertTokenizerLayer
  from tensorflow_text import FastBertTokenizer, ShrinkLongestTrimmer, case_fold_utfa, combine_segments, pad_model_inputs
  
  from .tokenization_bert import BertTokenizer
  
  
  
  class 		_snake_case      (			tf.keras.layers.Layer				):
  
  
  
  
  
   """simple docstring"""
  
  
  
   def __init__(						self	,    a	,    a	,    a = None	,    a = None	,    a = None	,    a = "longest"	,    a = True	,    a = 5_1_2	,    a = None	,    a = True	,    a = True	,    a = True	,    **a	,    )	->							Tuple:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     super().__init__()
     if use_fast_bert_tokenizer:
       _A           =    FastBertTokenizer(
           a	,    token_out_type=tf.intaa	,    lower_case_nfd_strip_accents=a	,    **a					)
     else:
       _A           =    tf.lookup.StaticVocabularyTable(
           tf.lookup.KeyValueTensorInitializer(
               keys=a	,    key_dtype=tf.string	,    values=tf.range(tf.size(a	,    out_type=tf.intaa					)	,    dtype=tf.intaa					)	,    value_dtype=tf.intaa	,    )	,    num_oov_buckets=1	,    )
       _A           =    BertTokenizerLayer(
           a	,    token_out_type=tf.intaa	,    lower_case=a	,    **a					)
  
     _A           =    vocab_list
     _A           =    do_lower_case
     _A           =    cls_token_id or vocab_list.index('''[CLS]'''					)
     _A           =    sep_token_id or vocab_list.index('''[SEP]'''					)
     _A           =    pad_token_id or vocab_list.index('''[PAD]'''					)
     _A           =    ShrinkLongestTrimmer(max_length - 3	,    axis=1					)  # Allow room for special tokens
     _A           =    max_length
     _A           =    padding
     _A           =    truncation
     _A           =    pad_to_multiple_of
     _A           =    return_token_type_ids
     _A           =    return_attention_mask
   @classmethod
   def lowercase_		(						cls	,    a	,    **a					)	->							Optional[int]:  # noqa: F821
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _A           =    kwargs.pop('''do_lower_case'''	,    a					)
     _A           =    tokenizer.do_lower_case if do_lower_case is None else do_lower_case
     _A           =    kwargs.pop('''cls_token_id'''	,    a					)
     _A           =    tokenizer.cls_token_id if cls_token_id is None else cls_token_id
     _A           =    kwargs.pop('''sep_token_id'''	,    a					)
     _A           =    tokenizer.sep_token_id if sep_token_id is None else sep_token_id
     _A           =    kwargs.pop('''pad_token_id'''	,    a					)
     _A           =    tokenizer.pad_token_id if pad_token_id is None else pad_token_id
  
     _A           =    tokenizer.get_vocab()
     _A           =    sorted([(wordpiece, idx) for wordpiece, idx in vocab.items()]	,    key=lambda a					: x[1]					)
     _A           =    [entry[0] for entry in vocab]
     return cls(
         vocab_list=a	,    do_lower_case=a	,    cls_token_id=a	,    sep_token_id=a	,    pad_token_id=a	,    **a	,    )
   @classmethod
   def lowercase_		(						cls	,    a	,    *a	,    **a					)	->							Tuple:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     try:
       _A           =    BertTokenizer.from_pretrained(a	,    *a	,    **a					)
     except:  # noqa: E722
       from .tokenization_bert_fast import BertTokenizerFast
  
       _A           =    BertTokenizerFast.from_pretrained(a	,    *a	,    **a					)
     return cls.from_tokenizer(a	,    **a					)
   def lowercase_		(						self	,    a					)	->							int:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     if self.do_lower_case:
       _A           =    case_fold_utfa(a					)
     _A           =    self.tf_tokenizer.tokenize(a					)
     return tokens.merge_dims(1	,    -1					)
   def lowercase_		(						self	,    a	,    a=None	,    a=None	,    a=None	,    a=None	,    a=None	,    a=None	,    a=None	,    )	->							List[Any]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     if padding is None:
       _A           =    self.padding
     if padding not in ("longest", "max_length"):
       raise ValueError('''Padding must be either \'longest\' or \'max_length\'!'''					)
     if max_length is not None and text_pair is not None:
       # Because we have to instantiate a Trimmer to do it properly
       raise ValueError('''max_length cannot be overridden at call time when truncating paired texts!'''					)
     if max_length is None:
       _A           =    self.max_length
     if truncation is None:
       _A           =    self.truncation
     if pad_to_multiple_of is None:
       _A           =    self.pad_to_multiple_of
     if return_token_type_ids is None:
       _A           =    self.return_token_type_ids
     if return_attention_mask is None:
       _A           =    self.return_attention_mask
     if not isinstance(a	,    tf.Tensor					):
       _A           =    tf.convert_to_tensor(a					)
     if text_pair is not None and not isinstance(a	,    tf.Tensor					):
       _A           =    tf.convert_to_tensor(a					)
     if text_pair is not None:
       if text.shape.rank > 1:
         raise ValueError('''text argument should not be multidimensional when a text pair is supplied!'''					)
       if text_pair.shape.rank > 1:
         raise ValueError('''text_pair should not be multidimensional!'''					)
     if text.shape.rank == 2:
       _A    ,   _A           =    text[:, 0], text[:, 1]
     _A           =    self.unpaired_tokenize(a					)
     if text_pair is None:  # Unpaired text
       if truncation:
         _A           =    text[:, : max_length - 2]  # Allow room for special tokens
       _A    ,   _A           =    combine_segments(
           (text,)	,    start_of_sequence_id=self.cls_token_id	,    end_of_segment_id=self.sep_token_id					)
     else:  # Paired text
       _A           =    self.unpaired_tokenize(a					)
       if truncation:
         _A    ,   _A           =    self.paired_trimmer.trim([text, text_pair]					)
       _A    ,   _A           =    combine_segments(
           (text, text_pair)	,    start_of_sequence_id=self.cls_token_id	,    end_of_segment_id=self.sep_token_id					)
     if padding == "longest":
       _A           =    input_ids.bounding_shape(axis=1					)
       if pad_to_multiple_of is not None:
         # No ceiling division in tensorflow, so we negate floordiv instead
         _A           =    pad_to_multiple_of * (-tf.math.floordiv(-pad_length	,    a					))
     else:
       _A           =    max_length
  
     _A    ,   _A           =    pad_model_inputs(a	,    max_seq_length=a	,    pad_value=self.pad_token_id					)
     _A           =    {'''input_ids''': input_ids}
     if return_attention_mask:
       _A           =    attention_mask
     if return_token_type_ids:
       _A    ,   _A           =    pad_model_inputs(
           a	,    max_seq_length=a	,    pad_value=self.pad_token_id					)
       _A           =    token_type_ids
     return output
  
  
  
   def lowercase_		(						self					)	->							List[str]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     return {
         "vocab_list": self.vocab_list,
         "do_lower_case": self.do_lower_case,
         "cls_token_id": self.cls_token_id,
         "sep_token_id": self.sep_token_id,
         "pad_token_id": self.pad_token_id,
     }
style_context: 
  
  
  
  import argparse
  
  import torch
  
  from transformers import ElectraConfig, ElectraForMaskedLM, ElectraForPreTraining, load_tf_weights_in_electra
  from transformers.utils import logging
  
  
  logging.set_verbosity_info()
  
  
  
  
  def     UpperCAmelCase__ (							__snake_case						,				__snake_case						,				__snake_case						,				__snake_case							)   -> Tuple:
    # Initialise PyTorch model
    _A           =    ElectraConfig.from_json_file(__snake_case							)
    print(F'''Building PyTorch model from configuration: {config}'''							)
  
    if discriminator_or_generator == "discriminator":
      _A           =    ElectraForPreTraining(__snake_case							)
    elif discriminator_or_generator == "generator":
      _A           =    ElectraForMaskedLM(__snake_case							)
    else:
      raise ValueError('''The discriminator_or_generator argument should be either \'discriminator\' or \'generator\''''							)
  
    # Load weights from tf checkpoint
    load_tf_weights_in_electra(
        __snake_case						,				__snake_case						,				__snake_case						,				discriminator_or_generator=__snake_case							)
  
    # Save pytorch-model
    print(F'''Save PyTorch model to {pytorch_dump_path}'''							)
    torch.save(model.state_dict()						,				__snake_case							)
  
  
  if __name__ == "__main__":
      __lowerCamelCase  				=					argparse.ArgumentParser()
      # Required parameters
      parser.add_argument(
          """--tf_checkpoint_path""", default=None, type=str, required=True, help="""Path to the TensorFlow checkpoint path."""
      )
      parser.add_argument(
          """--config_file""",
          default=None,
          type=str,
          required=True,
          help="""The config json file corresponding to the pre-trained model. \nThis specifies the model architecture.""",
      )
      parser.add_argument(
          """--pytorch_dump_path""", default=None, type=str, required=True, help="""Path to the output PyTorch model."""
      )
      parser.add_argument(
          """--discriminator_or_generator""",
          default=None,
          type=str,
          required=True,
          help=(
              """Whether to export the generator or the discriminator. Should be a string, either 'discriminator' or """
              """'generator'."""
          ),
      )
      __lowerCamelCase  				=					parser.parse_args()
      convert_tf_checkpoint_to_pytorch(
          args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path, args.discriminator_or_generator
      )