code: def _get_grads(self, samples_input, model, sparse_labels=None):
      samples_input.requires_grad = True
  
      grad_tensor = torch.zeros(samples_input.shape).float()
  
      for i in range(self.k):
          particular_slice = samples_input[:, i]
          batch_output = model(particular_slice)
          # should check that users pass in sparse labels
          # Only look at the user-specified label
          if batch_output.size(1) > 1:
              sample_indices = torch.arange(0, batch_output.size(0))
              indices_tensor = torch.cat(
                  [
                      sample_indices.unsqueeze(1),
                      sparse_labels.unsqueeze(1),
                  ],
                  dim=1,
              )
              batch_output = gather_nd(batch_output, indices_tensor)
  
          model_grads = grad(
              outputs=batch_output,
              inputs=particular_slice,
              grad_outputs=torch.ones_like(batch_output),
              create_graph=True,
          )
          grad_tensor[:, i, :] = model_grads[0]
      return grad_tensor
  
file_path: attributionpriors/attributionpriors/pytorch_ops_cpu.py
imports: import functools
  import operator
  import torch
  from torch.autograd import grad
  from torch.utils.data import DataLoader
label_desc: Use image node_id 4 for calling the AttributionPriorExplainer obj's underlying member method code with example usage: obj._get_grads(samples_input, model, sparse_labels) and returns: grad_tensor