code: def ref_grad_min_max_quantize(
      x,
      qr_min,
      qr_max,
      ql_min,
      ql_max,
      dy,
      decay,
      x_min_max,
      ema,
      ste_fine_grained,
      eps,
      quantize,
      **kw,
  ):
      if not quantize:
          return dy.flatten()
  
      # min-max
      raxes = tuple([i for i, s in enumerate(ql_min.shape) if s == 1])
      x_min = np.min(x, raxes, keepdims=True)
      x_max = np.max(x, raxes, keepdims=True)
      if x_min_max and ema:
          qr_min = decay * qr_min + (1.0 - decay) * x_min
          qr_max = decay * qr_max + (1.0 - decay) * x_max
      elif x_min_max and not ema:
          qr_min = x_min
          qr_max = x_max
      elif not x_min_max and ema:
          pass
      # scale
      scale = (qr_max - qr_min) / (ql_max - ql_min)
      # nudge scale
      if np.any(qr_max - qr_min < eps):
          qr_max[qr_max - qr_min < eps] = qr_min + eps
      # nudge min-max
      zero_point_from_min = ql_min - qr_min / scale
      zero_point_nudged = std_round(zero_point_from_min)
      if np.any(zero_point_from_min <= ql_min):
          zero_point_nudged[zero_point_from_min <= ql_min] = q_min[
              zero_point_from_min <= ql_min
          ]
      if np.any(zero_point_from_min >= ql_max):
          zero_point_nudged[zero_point_from_min >= ql_max] = q_max[
              zero_point_from_min >= ql_max
          ]
      qr_min_nudged = (ql_min - zero_point_nudged) * scale
      qr_max_nudged = (ql_max - zero_point_nudged) * scale
  
      # STE
      dy0 = dy.copy()
      if ste_fine_grained:
          dy = dy0 * (x >= qr_min_nudged) * (x <= qr_max_nudged)
      if x_min_max or ema:
          return dy.flatten()
      else:  # train qr_min and qr_max
          d_qr_min = np.sum(
              dy0 * (x < qr_min_nudged), raxes, keepdims=True
          )
          d_qr_max = np.sum(
              dy0 * (x > qr_max_nudged), raxes, keepdims=True
          )
          return np.concatenate(
              [dy.flatten(), d_qr_min.flatten(), d_qr_max.flatten()]
          )
  
file_path: nnabla/python/test/function/test_min_max_quantize.py
imports: import pytest
  import numpy
  import nnabla
  import nnabla.functions
  from nbla_test_utils import list_context
label_desc: Use image node_id 3 for calling a global function with example usage: ref_grad_min_max_quantize(x, qr_min, qr_max, ql_min, ql_max, dy, decay, x_min_max, ema, ste_fine_grained, eps, quantize) and returns: dy, dy, np