class_docstr: To test the gradients of a module, we need to have a loss.
  This module makes it easy to get a loss from any nn.Module, and automatically generates
  a target y vector for it in the forward (of all zeros of the correct size).
  This reduces boilerplate while testing.
docstr: Instantiates this module.
  
  Args:
      module: The nn.Module you want to test.
      loss_reduction: What reduction to apply to the loss. Defaults to "mean".
  
  Raises:
      ValueError: If ``loss_reduction`` is not among those supported.
docstr_tok: ["Instantiates","this","module",".","Args",":","module",":","The","nn.Module","you","want","to","test",".","loss_reduction",":","What","reduction","to","apply","to","the","loss",".","Defaults","to","``","mean","''",".","Raises",":","ValueError",":","If","``","loss_reduction","``","is","not","among","those","supported","."]
code: def __init__(self, module: nn.Module, loss_reduction: str = "mean"):
      """
      Instantiates this module.
  
      Args:
          module: The nn.Module you want to test.
          loss_reduction: What reduction to apply to the loss. Defaults to "mean".
  
      Raises:
          ValueError: If ``loss_reduction`` is not among those supported.
      """
      super().__init__()
      self.wrapped_module = module
  
      if loss_reduction not in self.supported_reductions:
          raise ValueError(
              f"Passed loss_reduction={loss_reduction}. Only {self.supported_reductions} supported."
          )
      self.criterion = nn.L1Loss(reduction=loss_reduction)
  
imports: import io
  from typing import Callable, Dict, Iterable, List, Union
  import numpy
  import torch
  import torch.nn
  from opacus.grad_sample import wrap_model
  from opacus.utils.module_utils import trainable_parameters
  from opacus.utils.packed_sequences import compute_seq_lengths
  from torch.nn.utils.rnn import PackedSequence, pad_packed_sequence
label_desc: Use image node_id 1 to create a new ModelWithLoss object from inherited base classes: nn with example: obj = ModelWithLoss(module, loss_reduction)