After doing the loss.backward() (which will calculate the grads), but before optimizer.step() each parameter has a .grad attribute (which should be not None for updated parameters) and you could manipulate the gradients there.