code: def create_or_accumulate_grad_sample(
      *,
      param: torch.Tensor,
      grad_sample: torch.Tensor,
      max_batch_len: int,
  ) -> None:
      """
      Creates a ``_current_grad_sample`` attribute in the given parameter, or adds to it
      if the ``_current_grad_sample`` attribute already exists.
  
  
      Args:
          param: Parameter to which ``grad_sample`` will be added
          grad_sample: Per-sample gradients tensor. Must be of the same
              shape as ``param`` with extra batch dimension
          layer: nn.Module parameter belongs to
      """
      if param.requires_grad:
          if hasattr(param, "_current_grad_sample"):
              param._current_grad_sample[
                  : grad_sample.shape[0]
              ] += grad_sample
          else:
              param._current_grad_sample = torch.zeros(
                  torch.Size([max_batch_len]) + grad_sample.shape[1:],
                  device=grad_sample.device,
                  dtype=grad_sample.dtype,
              )
              param._current_grad_sample[
                  : grad_sample.shape[0]
              ] = grad_sample
  
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 1 for calling a global function with example usage: create_or_accumulate_grad_sample() without return types