| ag_grad | R Documentation |
After backward(), x$grad holds the gradient – as an R matrix
on the closure path, but as a device handle when the graph backward kept it
on the GPU (the default there). ag_grad() returns the value as a
matrix either way, so code that reads gradients does not depend on where
they live. In graph mode it is a synchronisation point.
ag_grad(x)
x |
An ag_tensor (usually a parameter). |
A numeric matrix, or NULL when x has no gradient.
w <- ag_param(matrix(1:4 + 0, 2, 2))
with_grad_tape({ loss <- ag_sum(ag_mul(w, w)) })
backward(loss)
ag_grad(w) # 2 * w
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.