code: def apply_gradient_requirements(
      inputs: Tuple[Tensor, ...], warn: bool = True
  ) -> List[bool]:
      """
      Iterates through tuple on input tensors and sets requires_grad to be true on
      each Tensor, and ensures all grads are set to zero. To ensure that the input
      is returned to its initial state, a list of flags representing whether or not
       a tensor originally required grad is returned.
      """
      assert isinstance(
          inputs, tuple
      ), "Inputs should be wrapped in a tuple prior to preparing for gradients"
      grad_required = []
      for index, input in enumerate(inputs):
          assert isinstance(
              input, torch.Tensor
          ), "Given input is not a torch.Tensor"
          grad_required.append(input.requires_grad)
          inputs_dtype = input.dtype
          # Note: torch 1.2 doesn't support is_complex for dtype that's why we check
          # on the existance of is_complex method.
          if not inputs_dtype.is_floating_point and not (
              hasattr(inputs_dtype, "is_complex")
              and inputs_dtype.is_complex
          ):
              if warn:
                  warnings.warn(
                      """Input Tensor %d has a dtype of %s.
                      Gradients cannot be activated
                      for these data types."""
                      % (index, str(inputs_dtype))
                  )
          elif not input.requires_grad:
              if warn:
                  warnings.warn(
                      "Input Tensor %d did not already require gradients, "
                      "required_grads has been set automatically."
                      % index
                  )
              input.requires_grad_()
      return grad_required
  
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 1 for calling a global function with example usage: apply_gradient_requirements(inputs, warn) and returns: grad_required