chainer.variable.VariableNode

class chainer.variable.VariableNode(variable, name, grad=None)[source]

Node in the backward computational graph representing a variable.

This object represents a variable node in a computational graph. The node is used in error backpropagation (a.k.a. backprop) to determine which gradient to be passed to each function.

A variable node is held by the corresponding Variable object, which is managed by users. Function objects that take the variable as an input also hold references to the variable node.

Note that the node does not hold a reference to the corresponding data array in general. The data array is actually accessible by the node in the following cases.

  1. If there exists a Variable object that holds a reference to the variable node, the variable node holds a weak reference to the variable object, and thus the data array is accessible via the weak reference.
  2. If retain_data() is called, the node holds a reference to the data array. It is mainly called by a function that needs the input or output data array in its backprop procedure. See Function.retain_inputs() and Function.retain_outputs() for more details.

Users usually do not need to touch this variable node object. The computational graph is automatically managed by Chainer, and any interface that is beneficial for users is also provided by Variable.

Parameters:
  • variable (Variable) – The corresponding variable object.
  • name (str) – Name of the variable node.
Variables:
  • dtype – Data type of the data array.
  • shape – Shape of the data array.
  • name (str) – Name of the variable node.

Methods

retain_data()[source]

Lets the node hold a reference to the underlying data array.

This method gets the data array of the corresponding variable and keeps it. If the weak reference to the corresponding variable is dead, it raises an error.

set_creator(creator)[source]

Sets a Function object that created this node.

This method is equivalent to self.creator = creator.

Parameters:creator (Function) – Function object that created this node.
unchain()[source]

Deletes the reference to the creator of this variable node.

This method is equivalent to self.creator = None.

Attributes

creator

Function node that created this variable node.

data

Data array of the corresponding variable.

If the data is not available, it returns None.

grad

Gradient array of the corresponding variable.

label

Short text that represents the variable node.

rank
requires_grad

It indicates that grad will be set in backward calculation.