So, Both the functions are quite the same except



 Ka_Hina:

    with torch.no_grad():


This will reduce memory usage and speed up computations but you won’t be able to backprop.
Except everything is the same, second function has much better implementation.
Also



 Ka_Hina:

    model.train()


I don’t see any use of this.