class_docstr: Flatten/unflatten the incremental state for use with TorchScripting.
  
  Typically, the incremental state will be stored as a Dict[int, Dict[str, Dict[str,
  torch.Tensor]]], where the 3 dictionary levels map decoder layer, attention type,
  and previous key/value/mask, respectively. However, TorchScript expects dicts to be
  of type Dict[str, torch.Tensor], and thus all input incremental states when
  TorchScripting will have to be of that type. We thus unflatten the input incremental
  state, already of type Dict[str, torch.Tensor], to pass it into whatever method
  needs it, and we flatten it again after the updated incremental state is passed back
  out.
  
  This is a base class that provides methods for flattening/unflattening: subclasses
  will call these methods as the incremental state is passed into and out of their own
  methods.
code: def __init__(self, module: nn.Module):
      super().__init__()
      self.module = module
  
imports: from collections import defaultdict
  from typing import Dict, List, Optional, Tuple
  import torch.jit
  from parlai.agents.bart.bart import BartAgent
  from parlai.core.dict import DictionaryAgent
  from parlai.core.torch_agent import TorchAgent
  from parlai.utils.bpe import Gpt2BpeHelper, SubwordBPEHelper
  from parlai.torchscript.tokenizer import ScriptableDictionaryAgent
  from torch import nn
label_desc: Use image node_id 1 to create a new BaseIncrStateFlattener object from inherited base classes: nn with example: obj = BaseIncrStateFlattener(module)