the correct way is to make the model’s parameters not require gradients:
model = torch.load('mymodel.pth')
for p in model.parameters()
p.requires_grad = False
Alternatively, if you are purely using the model for inference with no gradients needed, the input to the model can be volatile (this is better, it saves more memory as well):
myinput = torch.randn(10, 20) # example input
model = torch.load('mymodel.pth')
input = Variable(myinput, volatile=True)
output = model(input)