text: import math
  import torch
  
  # This file is used when gradients become small enough. Read Appendix A of the paper. 
  def preprocess_gradients(x):
      p = 10
      eps = 1e-6
      indicator = (x.abs() > math.exp(-p)).float()
      x1 = (x.abs() + eps).log() / p * indicator - (1 - indicator)
      x2 = x.sign() * indicator + math.exp(p) * x * (1 - indicator)
  
      return torch.cat((x1, x2), 1)
  