code: def construct_neuron_grad_fn(
      layer: Module,
      neuron_selector: Union[
          int, Tuple[Union[int, slice], ...], Callable
      ],
      device_ids: Union[None, List[int]] = None,
      attribute_to_neuron_input: bool = False,
  ) -> Callable:
      def grad_fn(
          forward_fn: Callable,
          inputs: TensorOrTupleOfTensorsGeneric,
          target_ind: TargetType = None,
          additional_forward_args: Any = None,
      ) -> Tuple[Tensor, ...]:
          _, grads = _forward_layer_eval_with_neuron_grads(
              forward_fn,
              inputs,
              layer,
              additional_forward_args,
              gradient_neuron_selector=neuron_selector,
              device_ids=device_ids,
              attribute_to_layer_input=attribute_to_neuron_input,
          )
          return grads
  
      return grad_fn
  
imports: import threading
  import typing
  import warnings
  from collections import defaultdict
  from typing import Any, Callable, cast, Dict, List, Optional, Sequence, Tuple, Union
  import torch
  from captum._utils.common import _reduce_list, _run_forward, _sort_key_list, _verify_select_neuron
  from captum._utils.sample_gradient import SampleGradientWrapper
  from captum._utils.typing import Literal, ModuleOrModuleList, TargetType, TensorOrTupleOfTensorsGeneric
  from torch import device, Tensor
  from torch.nn import Module
label_desc: Use image node_id 21 for calling a global function with example usage: construct_neuron_grad_fn(layer, neuron_selector, device_ids, attribute_to_neuron_input) and returns: grad_fn, grads