Changing the computed gradients before backprop #8866
-
I want to add noise to the gradients in pytorch lightning . Specifically, something similar to this paper: https://arxiv.org/pdf/1511.06807.pdf . Basically, I would compute the gradients and before the call to backward, i want to add noise. What is the best way to achieve this in pytorch lightning? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Does the You can override this in your LightningModule If you need absolute control over the optimization process (forward, backward, optimizer steps), you can use manual optimization: https://pytorch-lightning.readthedocs.io/en/latest/common/optimizers.html#manual-optimization |
Beta Was this translation helpful? Give feedback.
-
Dear @sebastiangonsal, From your paper, it seems you might want to call backward which computes the gradients and then add some noise right ? Therefore, you could override the
If you want this re-usable, you could just move this to a callback instead. |
Beta Was this translation helpful? Give feedback.
Dear @sebastiangonsal,
From your paper, it seems you might want to call backward which computes the gradients and then add some noise right ?
Therefore, you could override the
before_optimizer_step
and add noise to all the params.grad.If you want this re-usable, you could just move this to a callback instead.