Autograd

namespace gtn

Functions

void backward(Graph g, const Graph &grad, bool retainGraph = false)

Compute the gradients of any inputs w.r.t g using the chain rule to incorporate grad, a gradient of another function with respect to graph.

If retainGraph = false (default) then the autograd graph will not be saved and un-referenced nodes in the autograd graph may be destroyed.

Parameters
  • g – The graph to compute gradients with respect to.

  • grad – A seed gradient, typically set to be a gradient of another function with respect to graph.

  • retainGraph – Whether or not to save the autograd graph. Setting this to False is more memory efficient as temporary Graphs created during the forward computation may be destroyed.

void backward(Graph g, bool retainGraph = false)

Compute the gradients of any inputs w.r.t g.

If retainGraph = false (default) then the autograd graph will not be saved and un-referenced nodes in the autograd graph may be destroyed.

See the overload gtn::backward().