afnio.autodiff.graph#

Classes

GradientEdge(node, output_nr)

Object representing a given gradient edge within the autodiff graph.

Node([next_functions])

class afnio.autodiff.graph.GradientEdge(node: Node, output_nr: int)[source]#

Bases: NamedTuple

Object representing a given gradient edge within the autodiff graph.

To get the gradient edge where a given Variable gradient will be computed, you can do edge = autodiff.graph.get_gradient_edge(variable).

count(value, /)#

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)#

Return first index of value.

Raises ValueError if the value is not present.

node: Node#

Alias for field number 0

output_nr: int#

Alias for field number 1

class afnio.autodiff.graph.Node(next_functions=None)[source]#

Bases: object

apply(*args)[source]#
name()[source]#

Return the name.

Example:

>>> import afnio
>>> import afnio.cognitive.functional as F
>>> a = hf.Variable("Hello,", requires_grad=True)
>>> b = hf.Variable("world!", requires_grad=True)
>>> c = F.sum([a, b])
>>> assert isinstance(c.grad_fn, afnio.autodiff.graph.Node)
>>> print(c.grad_fn.name())
SumBackward0
property next_functions: Tuple[GradientEdge]#