code: def compute_layer_norm_grad_sample(
      layer: nn.LayerNorm,
      activations: List[torch.Tensor],
      backprops: torch.Tensor,
  ) -> Dict[nn.Parameter, torch.Tensor]:
      """
      Computes per sample gradients for LayerNorm
  
      Args:
          layer: Layer
          activations: Activations
          backprops: Backpropagations
      """
      activations = activations[0]
      ret = {}
      if layer.weight.requires_grad:
          ret[layer.weight] = sum_over_all_but_batch_and_last_n(
              F.layer_norm(
                  activations, layer.normalized_shape, eps=layer.eps
              )
              * backprops,
              layer.weight.dim(),
          )
      if layer.bias.requires_grad:
          ret[layer.bias] = sum_over_all_but_batch_and_last_n(
              backprops, layer.bias.dim()
          )
      return ret
  
imports: from typing import Dict, List
  import torch
  import torch.nn
  import torch.nn.functional
  from opacus.utils.tensor_utils import sum_over_all_but_batch_and_last_n
  from .utils import register_grad_sampler
label_desc: Use image node_id 1 for calling a global function with example usage: compute_layer_norm_grad_sample(layer, activations, backprops) and returns: ret