class_docstr: Pre-trained GPT2 Tokenizer.
  
  Args:
      pretrained_model_name (optional): a `str`, the name of
          pre-trained model (e.g., `117M`). Please refer to
          :class:`~texar.torch.modules.PretrainedGPT2Mixin` for
          all supported models.
          If None, the model name in :attr:`hparams` is used.
      cache_dir (optional): the path to a folder in which the
          pre-trained models will be cached. If `None` (default),
          a default directory (``texar_data`` folder under user's home
          directory) will be used.
      hparams (dict or HParams, optional): Hyperparameters. Missing
          hyperparameter will be set to default values. See
          :meth:`default_hparams` for the hyperparameter structure
          and default values.
class_docstr_tok: ["Pre-trained","GPT2","Tokenizer",".","Args",":","pretrained_model_name","(","optional",")",":","a","`","str","`",",","the","name","of","pre-trained","model","(","e.g.",",","`","117M","`",")",".","Please","refer","to",":","class",":","`","~texar.torch.modules.PretrainedGPT2Mixin","`","for","all","supported","models",".","If","None",",","the","model","name","in",":","attr",":","`","hparams","`","is","used",".","cache_dir","(","optional",")",":","the","path","to","a","folder","in","which","the","pre-trained","models","will","be","cached",".","If","`","None","`","(","default",")",",","a","default","directory","(","``","texar_data","``","folder","under","user","'s","home","directory",")","will","be","used",".","hparams","(","dict","or","HParams",",","optional",")",":","Hyperparameters",".","Missing","hyperparameter","will","be","set","to","default","values",".","See",":","meth",":","`","default_hparams","`","for","the","hyperparameter","structure","and","default","values","."]
docstr: Save the tokenizer vocabulary and merge files to a directory.
docstr_tok: ["Save","the","tokenizer","vocabulary","and","merge","files","to","a","directory","."]
code: def save_vocab(self, save_dir: str) -> Tuple[str, str]:
      r"""Save the tokenizer vocabulary and merge files to a directory."""
      if not os.path.isdir(save_dir):
          raise ValueError(
              "Vocabulary path ({}) should be a "
              "directory".format(save_dir)
          )
  
      vocab_file = os.path.join(
          save_dir, self._VOCAB_FILE_NAMES["vocab_file"]
      )
      merge_file = os.path.join(
          save_dir, self._VOCAB_FILE_NAMES["merges_file"]
      )
  
      with open(vocab_file, "w", encoding="utf-8") as f:
          f.write(json.dumps(self.encoder, ensure_ascii=False))
  
      index = 0
      with open(merge_file, "w", encoding="utf-8") as writer:
          writer.write("#version: 0.2\n")
          for bpe_tokens, token_index in sorted(
              self.bpe_ranks.items(), key=lambda kv: kv[1]
          ):
              if index != token_index:
                  print(
                      "Saving vocabulary to {}: BPE merge indices are "
                      "not consecutive. Please check that the tokenizer "
                      "is not corrupted!".format(merge_file)
                  )
                  index = token_index
              writer.write(" ".join(bpe_tokens) + "\n")
              index += 1
  
      return (vocab_file, merge_file)
  
imports: from typing import Any, Dict, List, Optional, Tuple
  import os
  import json
  import regex
  from texar.tf.modules.pretrained.gpt2 import PretrainedGPT2Mixin
  from texar.tf.data.tokenizers.tokenizer_base import TokenizerBase
  from texar.tf.data.tokenizers.gpt2_tokenizer_utils import bytes_to_unicode, get_pairs
label_desc: Use image node_id 3 for calling the GPT2Tokenizer obj's underlying member method code with example usage: obj.save_vocab(save_dir) and returns: vocab_file,  merge_file