You are right that we aren’t calling backward on “test”.
However, during “test”, the model layers will create the computation graph for forward propagation, which can only be cleaned-up by a backward propagation. To avoid this, with torch.set_grad_enabled(False) informs all the layers to not to create any computational graph, because we do not wish to backpropagate for current computations.