Hi Pap!



 pap:

model.fc[i].weight.grad, it returns None.


Just to ask the obvious, are you calling model.fc[i].weight.grad
before or after training?  weight.grad will be None until the first time
you call loss.backward().
Other than that, I don’t see anything obviously wrong with the code you
posted.  If you still have this issue after considering my above comment,
please post a short, self-contained, runnable script that illustrates your
issue.  Include your MLP class, but (if it suffices to reproduce your issue)
just make one loss.backward() (and maybe optimizer.step())
call after passing hard-coded or randomly-generated data to MLP.
Also include the code where you show that model.fc[i].weight.grad
is None and post the output of your script when you run it.
Best.
K. Frank