@mailcorahul  Variable did not necessarily mean requires_grad=True.
@shazhongcheng But as you are working with v1.0.0, I suggest you get rid of it in the cpu code.
I realize I didn’t answer at all your main question which was about you gpu code … sorry.
In your gpu code, you have :



 shazhongcheng:

net=net.to(device)


Does this mean you defined net before ?
You could try to define optimizer on net.parameters() after calling net=net.to(device).
If this still doesn’t work, show us your whole code ! So that we can see what’s what.