code: def conv2d_param_grads(
      module: Module,
      activation: Tensor,
      gradient_out: Tensor,
      reset: bool = False,
  ) -> None:
      r"""
      Computes parameter gradients per sample for nn.Conv2d module, given module
      input activations and output gradients.
  
      nn.Conv2d modules with padding set to a string option ('same' or 'valid') are
      currently unsupported.
  
      Gradients are accumulated in the sample_grad attribute of each parameter
      (weight and bias). If reset = True, any current sample_grad values are reset,
      otherwise computed gradients are accumulated and added to the existing
      stored gradients.
      """
      if reset:
          _reset_sample_grads(module)
  
      batch_size = cast(int, activation.shape[0])
      unfolded_act = torch.nn.functional.unfold(
          activation,
          cast(Union[int, Tuple[int, ...]], module.kernel_size),
          dilation=cast(Union[int, Tuple[int, ...]], module.dilation),
          padding=cast(Union[int, Tuple[int, ...]], module.padding),
          stride=cast(Union[int, Tuple[int, ...]], module.stride),
      )
      reshaped_grad = gradient_out.reshape(
          batch_size, -1, unfolded_act.shape[-1]
      )
      grad1 = torch.einsum("ijk,ilk->ijl", reshaped_grad, unfolded_act)
      shape = [batch_size] + list(
          cast(Iterable[int], module.weight.shape)
      )
      module.weight.sample_grad += grad1.reshape(shape)  # type: ignore
      if module.bias is not None:
          module.bias.sample_grad += torch.sum(reshaped_grad, dim=2)
  
imports: from collections import defaultdict
  from enum import Enum
  from typing import cast, DefaultDict, Iterable, List, Optional, Tuple, Union
  import torch
  from captum._utils.common import _format_tensor_into_tuples, _register_backward_hook
  from torch import Tensor
  from torch.nn import Module
label_desc: Use image node_id 3 for calling a global function with example usage: conv2d_param_grads(module, activation, gradient_out, reset) without return types