class_docstr: An implementation of residual addition of an adapter module with its input.
  Supports stochastic depth regularization.
class_docstr_tok: ["An","implementation","of","residual","addition","of","an","adapter","module","with","its","input",".","Supports","stochastic","depth","regularization","."]
docstr: Compute any auxiliary losses and preserve it in the tensor registry.
  
  Args:
      output: The result tensor, after one of the active adapters has finished its forward passes.
      input: Original output tensor of the module, or the output of the previous adapter (if more than
          one adapters are enabled).
      adapter: The adapter module that is currently required to perform the forward pass.
      module: The calling module, in its entirety. It is a module that implements `AdapterModuleMixin`,
          therefore the strategy can access all other adapters in this module via `module.adapter_layer`.
docstr_tok: ["Compute","any","auxiliary","losses","and","preserve","it","in","the","tensor","registry",".","Args",":","output",":","The","result","tensor",",","after","one","of","the","active","adapters","has","finished","its","forward","passes",".","input",":","Original","output","tensor","of","the","module",",","or","the","output","of","the","previous","adapter","(","if","more","than","one","adapters","are","enabled",")",".","adapter",":","The","adapter","module","that","is","currently","required","to","perform","the","forward","pass",".","module",":","The","calling","module",",","in","its","entirety",".","It","is","a","module","that","implements","`","AdapterModuleMixin","`",",","therefore","the","strategy","can","access","all","other","adapters","in","this","module","via","`","module.adapter_layer","`","."]
code: def compute_auxiliary_losses(
      self,
      output: torch.Tensor,
      input: torch.Tensor,
      adapter: torch.nn.Module,
      *,
      module: "AdapterModuleMixin",
  ):
      """
      Compute any auxiliary losses and preserve it in the tensor registry.
  
      Args:
          output: The result tensor, after one of the active adapters has finished its forward passes.
          input: Original output tensor of the module, or the output of the previous adapter (if more than
              one adapters are enabled).
          adapter: The adapter module that is currently required to perform the forward pass.
          module: The calling module, in its entirety. It is a module that implements `AdapterModuleMixin`,
              therefore the strategy can access all other adapters in this module via `module.adapter_layer`.
      """
      if module.training and self.l2_lambda > 0.0:
          if not isinstance(adapter, AccessMixin):
              raise ValueError(
                  f"Module {adapter.__class__.__name__} does not implement AccessMixin !"
              )
  
          # Only add auxiliary loss if adapter has trainable parameters that require gradients
          if next(adapter.parameters()).requires_grad is True:
              # Check if globally allowed to compute aux loss
              compute_aux_loss = adapter.access_cfg.get(
                  "compute_adapter_loss", True
              )
  
              if compute_aux_loss:
                  # if l2 lambda is enabled, also enable AccessMixin
                  adapter.set_access_enabled(access_enabled=True)
  
                  l2_loss = (
                      self.l2_lambda
                      * (input - output)
                      .square()
                      .reshape(input.size(0), -1)
                      .sum(dim=-1)
                      .mean()
                  )
                  adapter.register_accessible_tensor(
                      name="adapter_loss", tensor=l2_loss
                  )
  
imports: from abc import ABC
  from dataclasses import dataclass
  from typing import Any, Dict, List, Tuple, Union
  import torch
  from nemo.core.classes.mixins import AccessMixin
label_desc: Use image node_id 5 for calling the ResidualAddAdapterStrategy obj's underlying member method code with example usage: obj.compute_auxiliary_losses(output, input, adapter) without return types