gradient clipping #2724
Answered
by
laggui
wangjiawen2013
asked this question in
Q&A
gradient clipping
#2724
-
Hi, let loss = MseLoss::new().forward(output.clone(), batch.targets, Mean);
let grads = loss.backward();
let grads = GradientClippingConfig::Norm(1.0).init().clip_gradient(grads); So could you give an example on how to clip the gradients ? |
Beta Was this translation helpful? Give feedback.
Answered by
laggui
Jan 22, 2025
Replies: 2 comments 2 replies
-
Besides, how to display and get the values of the grads ? |
Beta Was this translation helpful? Give feedback.
1 reply
-
You can set this via the optimizer config You can see how it's applied in the optimizer: burn/crates/burn-core/src/optim/simple/adaptor.rs Lines 120 to 131 in b33bd24 |
Beta Was this translation helpful? Give feedback.
1 reply
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
With the
GradientsParams
, you can retrieve the gradients for a givenParamId
(associated to a parameter tensor) withgrads.get(id)
.And then you can display / check the values of the grad tensor. If you want to check all values of a module, you could use a
ModuleVisitor
and do something similar to the optimizer adaptor I linked in my other response.