I mean, for example, whatever you used the loss function like nn.CrossEntropyLoss, it can be NllLossBackward …
what you want is just call the backward function manually, check this documentation. (https://pytorch.org/tutorials/beginner/blitz/autograd_tutorial.html 92).