class_docstr: k2 Mixin class that simplifies the construction of various models with k2-based losses.
  
  It does the following:
      -   Sets up the graph loss and decoder (methods _init_k2 and update_k2_modules).
      -   Registers external graphs, if needed.
      -   Augments forward(...) with optional graph decoding to get accurate predictions.
class_docstr_tok: ["k2","Mixin","class","that","simplifies","the","construction","of","various","models","with","k2-based","losses",".","It","does","the","following",":","-","Sets","up","the","graph","loss","and","decoder","(","methods","_init_k2","and","update_k2_modules",")",".","-","Registers","external","graphs",",","if","needed",".","-","Augments","forward","(","...",")","with","optional","graph","decoding","to","get","accurate","predictions","."]
docstr: k2-related initialization implementation.
  
  This method is expected to run after the __init__ which sets self._cfg
  self._cfg is expected to have the attribute graph_module_cfg
docstr_tok: ["k2-related","initialization","implementation",".","This","method","is","expected","to","run","after","the","__init__","which","sets","self._cfg","self._cfg","is","expected","to","have","the","attribute","graph_module_cfg"]
code: def _init_k2(self):
      """
      k2-related initialization implementation.
  
      This method is expected to run after the __init__ which sets self._cfg
      self._cfg is expected to have the attribute graph_module_cfg
      """
      if not hasattr(self, "_cfg"):
          raise ValueError(
              "self._cfg must be set before calling _init_k2()."
          )
      if (
          not hasattr(self._cfg, "graph_module_cfg")
          or self._cfg.graph_module_cfg is None
      ):
          raise ValueError(
              "self._cfg.graph_module_cfg must be set and cannot be None."
          )
      self.graph_module_cfg = self._cfg.graph_module_cfg
  
      # register token_lm for MAPLoss
      criterion_type = self.graph_module_cfg.get("criterion_type", "ml")
      self.use_graph_lm = criterion_type == "map"
      if self.use_graph_lm:
          token_lm_path = self.graph_module_cfg.backend_cfg.get(
              "token_lm", None
          )
          if token_lm_path is None:
              raise ValueError(
                  f"graph_module_cfg.backend_cfg.token_lm is empty. It must be set for criterion_type == `{criterion_type}`"
              )
          token_lm_path = self.register_artifact(
              "graph_module_cfg.backend_cfg.token_lm", token_lm_path
          )
          self.graph_module_cfg.backend_cfg["token_lm"] = token_lm_path
  
      self.update_k2_modules(self.graph_module_cfg)
  
file_path: NeMo/nemo/collections/asr/parts/k2/classes.py
imports: from abc import ABC
  from dataclasses import dataclass, field
  from typing import Any, Optional, Tuple
  import torch
  from omegaconf import DictConfig
  from nemo.utils import logging
label_desc: Use image node_id 1 for calling the ASRK2Mixin obj's underlying member method code with example usage: obj._init_k2() without return types