  
  def grad_clipping(params, theta, ctx):
      """Clip the gradient."""
      if theta is not None:
          norm = nd.array([0.0], ctx)
          for param in params:
              norm += (param.grad ** 2).sum()
          norm = norm.sqrt().asscalar()
          if norm > theta:
              for param in params:
 
</s> remove         data_iter_fn = data_iter_consecutive
 </s> add         data_iter_fn = gb.data_iter_consecutive </s> remove                 l = loss(y_hat, y)
 </s> add                 l = loss(y_hat, y).sum() </s> remove         for t, (X, Y) in enumerate(data_iter):
 </s> add         for X, Y in data_iter: </s> remove         l_sum, start = 0.0, time.time()
 </s> add         l_sum, n, start = 0.0, 0, time.time() </s> remove     acc = nd.array([0])
    n = 0
 </s> add     acc_sum, n = nd.array([0]), 0
        norm = nd.array([0], ctx)
  
  def grad_clipping(params, theta, ctx):
      """Clip the gradient."""
      if theta is not None:
        norm = nd.array([0], ctx)
          for param in params:
              norm += (param.grad ** 2).sum()
          norm = norm.sqrt().asscalar()
          if norm > theta:
              for param in params:
keep keep keep keep replace keep keep keep keep keep
 gb 0.8.9, fix acc, loss computations 
gluonbook/utils.py