class_docstr: CTC-based grapheme-to-phoneme model.
class_docstr_tok: ["CTC-based","grapheme-to-phoneme","model","."]
docstr: Initialized grapheme tokenizer 
docstr_tok: ["Initialized","grapheme","tokenizer"]
code: def setup_grapheme_tokenizer(self, cfg):
      """Initialized grapheme tokenizer"""
  
      if self.mode == "byt5":
          # Load appropriate tokenizer from HuggingFace
          grapheme_tokenizer = AutoTokenizer.from_pretrained(
              cfg.tokenizer_grapheme.pretrained
          )
          self.max_source_len = cfg.get(
              "max_source_len", grapheme_tokenizer.model_max_length
          )
          self.max_target_len = cfg.get(
              "max_target_len", grapheme_tokenizer.model_max_length
          )
  
          # TODO store byt5 vocab file
      elif self.mode == "conformer_bpe":
          grapheme_unk_token = (
              cfg.tokenizer_grapheme.unk_token
              if cfg.tokenizer_grapheme.unk_token is not None
              else ""
          )
          chars = (
              string.ascii_lowercase + grapheme_unk_token + " " + "'"
          )
  
          if not cfg.tokenizer_grapheme.do_lower:
              chars += string.ascii_uppercase
  
          if cfg.tokenizer_grapheme.add_punctuation:
              punctuation_marks = (
                  string.punctuation.replace('"', "")
                  .replace("\\", "")
                  .replace("'", "")
              )
              chars += punctuation_marks
  
          vocab_file = "/tmp/char_vocab.txt"
          with open(vocab_file, "w") as f:
              [f.write(f'"{ch}"\n') for ch in chars]
              f.write('"\\""\n')  # add " to the vocab
  
          self.register_artifact(
              "tokenizer_grapheme.vocab_file", vocab_file
          )
          grapheme_tokenizer = instantiate(
              cfg.tokenizer_grapheme.dataset, vocab_file=vocab_file
          )
          self.max_source_len = cfg.get("max_source_len", 512)
          self.max_target_len = cfg.get("max_target_len", 512)
      else:
          raise ValueError(
              f"{self.mode} is not supported. Choose from {self.supported_modes}"
          )
      return grapheme_tokenizer
  
imports: import os
  import string
  from dataclasses import dataclass
  from typing import Any, Dict, List, Optional, Union
  import torch
  from hydra.utils import instantiate
  from omegaconf import DictConfig, ListConfig, OmegaConf, open_dict
  from pytorch_lightning import Trainer
  from transformers import AutoConfig, AutoModel, AutoTokenizer
  from nemo.collections.tts.g2p.data.ctc import CTCG2PBPEDataset
  from nemo.collections.tts.models.base import G2PModel
  from nemo.core.classes.common import PretrainedModelInfo
  from nemo.utils import logging
label_desc: Use image node_id 2 for calling the CTCG2PModel obj's underlying member method code with example usage: obj.setup_grapheme_tokenizer(cfg) and returns: grapheme_tokenizer