code: def clip_grad(optimizer):
      with torch.no_grad():
          for group in optimizer.param_groups:
              for p in group["params"]:
                  state = optimizer.state[p]
  
                  if "step" not in state or state["step"] < 1:
                      continue
  
                  step = state["step"]
                  exp_avg_sq = state["exp_avg_sq"]
                  _, beta2 = group["betas"]
  
                  bound = (
                      3 * torch.sqrt(exp_avg_sq / (1 - beta2**step))
                      + 0.1
                  )
                  p.grad.data.copy_(
                      torch.max(torch.min(p.grad.data, bound), -bound)
                  )
  
label_desc: Use image node_id 3 for calling a global function with example usage: clip_grad(optimizer) without return types