Solved by mailcorahul in post #4 
              
              
                Can you use the following? 
with torch.no_grad():
        y_pred = model(x)

Gradients are generally computed by default during forward call.