avg = (total_L / ntotal).asscalar()
if nbatch % args.log_interval == 0:
print("Evaluation batch %d: test loss %.2f, test ppl %.2f"
%(nbatch, avg, math.exp(avg)))
if max_nbatch_eval and nbatch > max_nbatch_eval:
print("Quit evaluation early at batch %d"%nbatch)
break
After Change
nbatch += 1
avg = total_L / ntotal
if nbatch % args.log_interval == 0:
avg_scalar = float(avg.asscalar())
ppl = math.exp(avg_scalar)
throughput = batch_size*args.log_interval/(time.time()-start_time)
print("Evaluation batch %d: test loss %.2f, test ppl %.2f, "
"throughput = %.2f samples/s"%(nbatch, avg_scalar, ppl, throughput))