with ag.record():
outputs = [net(X) for X in data]
loss = [L(yhat, y) for yhat, y in zip(outputs, label_smooth)]
for l in loss:
l.backward()
trainer.step(batch_size)
acc_top1.update(label, outputs)
acc_top5.update(label, outputs)
train_loss += sum([l.sum().asscalar() for l in loss])
After Change
with ag.record():
outputs = [net(X) for X in data]
loss = [L(yhat, y) for yhat, y in zip(outputs, label_smooth)]
ag.backward(loss)
trainer.step(batch_size)
acc_top1.update(label, outputs)
acc_top5.update(label, outputs)
train_loss += sum([l.sum().asscalar() for l in loss])