first, thanks for reply. This code is work, but i don’t know whether the obtained values of model.layer3.register_backward_hook(hook) are partial derivative of Etotal and neto. Second, I want to use nn.MSELoss() replace nn.CrossEntropyLoss(), so,  the criterion=  nn.CrossEntropyLoss() change to criterion= nn.MSELoss(size_average = False).

this  code proceed with error below:

longerror.png1467×35 3.35 KB

then, i add line code:

but, there also has error:

320.png1488×28 2.39 KB

for this error, i really don’t know how to solve this problem or how to use MSELoss in my program
I know the ‘’target‘’ of MSELoss is ：