class_docstr: Adapter Mixin that can augment a ModelPT subclass with Adapter support.
  
  This mixin class should be used only with a top level ModelPT subclass.
  This mixin class adds several utility methods which should be subclassed and overriden to
  propagated to the submodules as necessary.
  
  An Adapter module is any Pytorch nn.Module that possess a few properties :
  
  - It's input and output dimension are the same, while the hidden dimension need not be the same.
  - The final layer of the Adapter module is zero-initialized, so that the residual connection to the adapter
      yields the original output.
  
  This mixin adds the following instance variables to the class this inherits it:
  
      -   `adapter_layer`: A torch.nn.ModuleDict(), whose keys are the names of the adapter (globally unique),
              and values are the Adapter nn.Module().
      -   `adapter_cfg`: A OmegaConf DictConfig object that holds the config of the adapters that are initialized.
      -   `adapter_global_cfg_key`: A str representing a key in the model config that can be provided by the user.
          The value resolves to `global_cfg`, and can be overridden via `model.cfg.adapters.global_cfg.*`.
  
  .. note::
  
      This module **is** responsible for maintaining its config. At the ModelPT level, it will access and
      write Adapter config information to `self.cfg.adapters`.
class_docstr_tok: ["Adapter","Mixin","that","can","augment","a","ModelPT","subclass","with","Adapter","support",".","This","mixin","class","should","be","used","only","with","a","top","level","ModelPT","subclass",".","This","mixin","class","adds","several","utility","methods","which","should","be","subclassed","and","overriden","to","propagated","to","the","submodules","as","necessary",".","An","Adapter","module","is","any","Pytorch","nn.Module","that","possess","a","few","properties",":","-","It","'s","input","and","output","dimension","are","the","same",",","while","the","hidden","dimension","need","not","be","the","same",".","-","The","final","layer","of","the","Adapter","module","is","zero-initialized",",","so","that","the","residual","connection","to","the","adapter","yields","the","original","output",".","This","mixin","adds","the","following","instance","variables","to","the","class","this","inherits","it",":","-","`","adapter_layer","`",":","A","torch.nn.ModuleDict","(",")",",","whose","keys","are","the","names","of","the","adapter","(","globally","unique",")",",","and","values","are","the","Adapter","nn.Module","(",")",".","-","`","adapter_cfg","`",":","A","OmegaConf","DictConfig","object","that","holds","the","config","of","the","adapters","that","are","initialized",".","-","`","adapter_global_cfg_key","`",":","A","str","representing","a","key","in","the","model","config","that","can","be","provided","by","the","user",".","The","value","resolves","to","`","global_cfg","`",",","and","can","be","overridden","via","`","model.cfg.adapters.global_cfg.","*","`",".","..","note",":",":","This","module","*","*","is","*","*","responsible","for","maintaining","its","config",".","At","the","ModelPT","level",",","it","will","access","and","write","Adapter","config","information","to","`","self.cfg.adapters","`","."]
docstr: Utility method that is called in the ASR ModelPT-implementation constructor, so as to restore any
  adapters that were previously added.
  
  Should be overriden by the subclass for additional setup steps as required.
  
  This method should be called just once at constructor time.
docstr_tok: ["Utility","method","that","is","called","in","the","ASR","ModelPT-implementation","constructor",",","so","as","to","restore","any","adapters","that","were","previously","added",".","Should","be","overriden","by","the","subclass","for","additional","setup","steps","as","required",".","This","method","should","be","called","just","once","at","constructor","time","."]
code: def setup_adapters(self):
      """
      Utility method that is called in the ASR ModelPT-implementation constructor, so as to restore any
      adapters that were previously added.
  
      Should be overriden by the subclass for additional setup steps as required.
  
      This method should be called just once at constructor time.
      """
      # Test if `adapters` is part of the config (injected from previous Adapter additions)
      if "adapters" in self.cfg:
          # Set the global config of adapters
          self.update_adapter_cfg(self.cfg.adapters)
  
          # Dispatch the call to the encoder, for every adapter contained in the config.
          for adapter_name, adapter_cfg in self.cfg.adapters.items():
              # reserve special key `model.adapters.cfg`
              if adapter_name == self.adapter_global_cfg_key:
                  continue
  
              # Add the adapters back to the model during setup
              # Add a guard so that during restoration, unique name check is disabled
              self._restoring_adapters = True
  
              # Restore the unique adapter
              self.add_adapter(name=adapter_name, cfg=adapter_cfg)
  
              # Remove restoration guard
              del self._restoring_adapters
  
              # Log the setup adapter name
              (
                  module_name,
                  adapter_name,
              ) = self.resolve_adapter_module_name_(adapter_name)
  
              if module_name != "":
                  full_adapter_name = f"{module_name}:{adapter_name}"
              else:
                  full_adapter_name = adapter_name
  
              logging.info(
                  f"Finished setup of adapter : '{full_adapter_name}'. Enabled: {adapter_cfg.get('enabled', True)}."
              )
  
imports: import inspect
  from abc import ABC
  from dataclasses import dataclass, is_dataclass
  from typing import List, Optional, Set, Tuple, Union
  import torch
  import torch.nn
  from hydra.utils import instantiate
  from omegaconf import DictConfig, OmegaConf, open_dict
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 1 for calling the AdapterModelPTMixin obj's underlying member method code with example usage: obj.setup_adapters() without return types