Skip to content
class

GraphBarrier

GraphBarrier

The create_graph half of the barrier protocol.

Eager backward hands a barrier each arriving gradient together with its slot (Node::accumulate_barrier_grad) and runs the barrier once, after every gradient has arrived. Graph-mode backward kept one pending tensor per node and summed every arrival into it whatever its slot — right for a node with a single slot, wrong for one with several, whose gradients it added together. A barrier that implements this interface receives its graph-mode gradients the way eager backward delivers them.

The engine finds it with graph_barrier_of; a barrier that does not implement it keeps the single-pending-tensor path.

Destructor

1

Virtual methods

2
= 0

accumulate_barrier_grad_for_graph

void accumulate_barrier_grad_for_graph(int input_nr, int grad)

Add grad to what slot input_nr holds. The sum is a graph op, so it stays differentiable.

virtconst

runs_without_grad

bool runs_without_grad()

Whether the barrier runs on its turn even when no gradient reached its slots — e.g. a hooked module's input barrier once its output barrier has run, which materializes zeros for the inputs as the reference's Function does.

Methods

1
fn

apply_barrier_for_graph

int apply_barrier_for_graph()

Run the barrier once every gradient has arrived: one tensor per outgoing edge, null where no gradient flows.