class_docstr: Hooks-based implementation of AbstractGradSampleModule
  
  Computes per-sample gradients using custom-written methods for each layer.
  See README.md for more details
docstr: Check if per sample gradients can be fully computed for a given model
  
  Args:
      module: nn.Module to be checked
      raise_if_error: Behaviour in case of a negative check result. Will
      return the list of exceptions if set to ``False``, and throw otherwise
  
  Returns:
      Empty list of validation is successful.
      List of validation errors  if ``raise_if_error=False`` and
      unsupported modules are found
  
  Raises:
      NotImplementedError
          If ``raise_if_error=True`` and unsupported modules are found
docstr_tok: ["Check","if","per","sample","gradients","can","be","fully","computed","for","a","given","model","Args",":","module",":","nn.Module","to","be","checked","raise_if_error",":","Behaviour","in","case","of","a","negative","check","result",".","Will","return","the","list","of","exceptions","if","set","to","``","False","``",",","and","throw","otherwise","Returns",":","Empty","list","of","validation","is","successful",".","List","of","validation","errors","if","``","raise_if_error=False","``","and","unsupported","modules","are","found","Raises",":","NotImplementedError","If","``","raise_if_error=True","``","and","unsupported","modules","are","found"]
code: def validate(
      cls, module: nn.Module, *, strict: bool = False
  ) -> List[NotImplementedError]:
      """
      Check if per sample gradients can be fully computed for a given model
  
      Args:
          module: nn.Module to be checked
          raise_if_error: Behaviour in case of a negative check result. Will
          return the list of exceptions if set to ``False``, and throw otherwise
  
      Returns:
          Empty list of validation is successful.
          List of validation errors  if ``raise_if_error=False`` and
          unsupported modules are found
  
      Raises:
          NotImplementedError
              If ``raise_if_error=True`` and unsupported modules are found
      """
      errors = []
      errors.extend(
          [
              NotImplementedError(
                  f"Model contains a trainable layer "
                  f"that Opacus doesn't currently support({m_name}:{m}). "
                  f"Please implement and register grad sampler for this layer. "
                  f"(See opacus.grad_sample.utils.register_grad_sampler)"
              )
              for m_name, m in trainable_modules(module)
              # With functorch, all modules are trainable
              # We still want to avoid module that have buffers (e.g. BatchNorm)
              # as the buffers are not private
              if len(list(m.buffers())) > 0
          ]
      )
      # raise or return errors as needed
      if strict and len(errors) > 0:
          raise NotImplementedError(errors)
      else:
          return errors
  
imports: from __future__ import annotations
  import logging
  import warnings
  from functools import partial
  from typing import Iterable, List, Tuple
  import torch
  import torch.nn
  from opacus.grad_sample.functorch import ft_compute_per_sample_gradient, prepare_layer
  from opacus.grad_sample.gsm_base import AbstractGradSampleModule
  from opacus.layers.dp_rnn import DPGRU, DPLSTM, DPRNN, RNNLinear
  from opacus.utils.module_utils import has_trainable_params, requires_grad, trainable_modules, trainable_parameters
label_desc: Use image node_id 13 for calling the GradSampleModule obj's underlying member method code with example usage: obj.validate(cls, module) and returns: errors