code: def _apply_adam(  # type: ignore
      r,
      t,
      x,
      g,
      v,
      h,
      norm_coefficient,
      norm_coefficient_post,
      alpha,
      beta,
      epsilon,
  ):  # type: ignore
      # Add gradient of regularization term.
      g_regularized = norm_coefficient * x + g
      # Update momentum.
      v_new = alpha * v + (1 - alpha) * g_regularized
      # Update second-order momentum.
      h_new = beta * h + (1 - beta) * (g_regularized * g_regularized)
      # Compute element-wise square root.
      h_sqrt = np.sqrt(h_new) + epsilon
      # Adjust learning rate.
      r_adjusted = None
      if t > 0:
          # Consider bias correction on momentums.
          r_adjusted = r * np.sqrt(1 - beta**t) / (1 - alpha**t)
      else:
          # No bias correction on momentums.
          r_adjusted = r
      # Apply Adam update rule.
      x_new = x - r_adjusted * (v_new / h_sqrt)
      # It's possible to apply regularization in the end.
      x_final = (1 - norm_coefficient_post) * x_new
      return x_final, v_new, h_new
  
imports: import numpy
  from onnx.reference.ops.aionnx_preview_training._op_run_training import OpRunTraining
label_desc: Use image node_id 1 for calling a global function with example usage: _apply_adam(r, t, x, g, v, h, norm_coefficient, norm_coefficient_post, alpha, beta, epsilon) and returns: x_final,  v_new,  h_new