  def evaluate_accuracy(data_iter, net, ctx=[mx.cpu()]):
      """Evaluate accuracy of a model on the given data set."""
      if isinstance(ctx, mx.Context):
          ctx = [ctx]
      acc = nd.array([0])
      n = 0
      for batch in data_iter:
          features, labels, _ = _get_batch(batch, ctx)
          for X, y in zip(features, labels):
              y = y.astype('float32')
              acc += (net(X).argmax(axis=1) == y).sum().copyto(mx.cpu())
 
</s> remove             acc += (net(X).argmax(axis=1) == y).sum().copyto(mx.cpu())
 </s> add             acc_sum += (net(X).argmax(axis=1) == y).sum().copyto(mx.cpu()) </s> remove         acc.wait_to_read()
    return acc.asscalar() / n
 </s> add         acc_sum.wait_to_read()
    return acc_sum.asscalar() / n </s> remove     for epoch in range(1, num_epochs + 1):
        train_l_sum, train_acc_sum, n, m = 0.0, 0.0, 0.0, 0.0
        start = time.time()
 </s> add     for epoch in range(num_epochs):
        train_l_sum, train_acc_sum, n, m, start = 0.0, 0.0, 0, 0, time.time() </s> remove     """Train and evaluate a model on CPU."""
    for epoch in range(1, num_epochs + 1):
        train_l_sum = 0
        train_acc_sum = 0
 </s> add     """Train and evaluate a model with CPU."""
    for epoch in range(num_epochs):
        train_l_sum, train_acc_sum, n = 0.0, 0.0, 0 </s> remove             gutils.split_and_load(labels, ctx),
            features.shape[0])
 </s> add             gutils.split_and_load(labels, ctx), features.shape[0])
    acc_sum, n = nd.array([0]), 0
  def evaluate_accuracy(data_iter, net, ctx=[mx.cpu()]):
      """Evaluate accuracy of a model on the given data set."""
      if isinstance(ctx, mx.Context):
          ctx = [ctx]
    acc_sum, n = nd.array([0]), 0
    acc_sum, n = nd.array([0]), 0
      for batch in data_iter:
          features, labels, _ = _get_batch(batch, ctx)
          for X, y in zip(features, labels):
              y = y.astype('float32')
              acc += (net(X).argmax(axis=1) == y).sum().copyto(mx.cpu())
keep keep keep keep replace replace keep keep keep keep keep
 gb 0.8.9, fix acc, loss computations 
gluonbook/utils.py