Thank you. I did what you suggested but it still does not have grad_fun in the output tensor. Could you please try the below c++ code on your side?
class SpikeFunction : public torch::autograd::Function<SpikeFunction> {
 public:
  static torch::Tensor forward(
      torch::autograd::AutogradContext* ctx,
      torch::autograd::Variable v_scaled,
      torch::Tensor dampening_factor) {
    // forward calculation
    ctx->save_for_backward({v_scaled,dampening_factor});
    return (v_scaled > 0).type_as(v_scaled);
  }

  static torch::autograd::variable_list backward(
      torch::autograd::AutogradContext* ctx,
      torch::autograd::variable_list grad_output) {
    // backward calculation
    auto saved = ctx->get_saved_variables();
    auto v_scaled = saved[0];
    auto dampening_factor = saved[1];
    auto dE_dz = grad_output[0];
    auto dz_dv_scaled = torch::maximum(1 - torch::abs(v_scaled), torch::zeros_like(v_scaled)) * dampening_factor;
    auto dE_dv_scaled = dE_dz * dz_dv_scaled;
    return {dE_dv_scaled, torch::Tensor()};
  }
};

torch::Tensor SpikeFunction(torch::Tensor& v_scaled, torch::Tensor& dampening_factor) {
  return SpikeFunction::apply(v_scaled,dampening_factor);
}

// TORCH_LIBRARY(my_ops, m) {
//   m.def("SpikeFunction", &SpikeFunction);
// }

static auto registry = torch::RegisterOperators().op("myops::SpikeFunction", &SpikeFunction);