  
  
  def train_ch3(net, train_iter, test_iter, loss, num_epochs, batch_size,
                params=None, lr=None, trainer=None):
      """Train and evaluate a model on CPU."""
      for epoch in range(1, num_epochs + 1):
          train_l_sum = 0
          train_acc_sum = 0
          for X, y in train_iter:
              with autograd.record():
                  y_hat = net(X)
                  l = loss(y_hat, y)
              l.backward()
 
</s> remove     for epoch in range(1, num_epochs + 1):
        train_l_sum = 0
        train_acc_sum = 0
        start = time.time()
 </s> add     for epoch in range(num_epochs):
        train_l_sum, train_acc_sum, n, start = 0.0, 0.0, 0, time.time() </s> remove     """Train and evaluate a model on CPU or GPU."""
 </s> add     """Train and evaluate a model with CPU or GPU.""" </s> remove                     prefix, pred_len, model, vocab_size,
                    ctx, idx_to_char, char_to_idx))
 </s> add                     prefix, pred_len, model, vocab_size, ctx, idx_to_char,
                    char_to_idx)) </s> remove                 l = loss(y_hat, y)
 </s> add                 l = loss(y_hat, y).sum() </s> remove                 l = loss(y_hat, y)
 </s> add                 l = loss(y_hat, y).sum()
    """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
  
  
  def train_ch3(net, train_iter, test_iter, loss, num_epochs, batch_size,
                params=None, lr=None, trainer=None):
    """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
    """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
    """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
    """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
          for X, y in train_iter:
              with autograd.record():
                  y_hat = net(X)
                  l = loss(y_hat, y)
              l.backward()
keep keep keep keep replace replace replace replace keep keep keep keep keep
 gb 0.8.9, fix acc, loss computations 
gluonbook/utils.py