eazygrad.grad.computation_graph.ComputationGraph

class eazygrad.grad.computation_graph.ComputationGraph[source]

Bases: object

Global dynamic computation graph used by EaZyGrad.

The graph stores every differentiable operation as a node together with:

  • the parent node ids,

  • the operation object that knows how to backpropagate locally,

  • the result tensor produced at that node.

Notes

EaZyGrad currently uses a single global graph instance (dag) rather than per-tensor graph ownership. This keeps the implementation small and easy to trace, but it also means graph lifetime management is more manual than in PyTorch.

backward(root_node_id: int, debug: bool = False, retain_graph: bool = False) None[source]

Backpropagate gradients through the computation graph.

Parameters:
  • root_node_id (int) – Identifier of the root node from which backpropagation starts.

  • debug (bool, default=False) – Reserved debug flag. Currently unused.

  • retain_graph (bool, default=False) – If True, keep traversed non-leaf nodes in the graph after the backward pass. If False, traversed non-leaf nodes are removed as they are processed.

Returns:

None

Notes

The method consumes the accumulated gradient stored in each visited node’s result.acc_grad field and distributes gradients to parent nodes using the local backward rule of each recorded operation. Broadcasted gradients are reduced to match parent tensor shapes before being accumulated.

clear() None[source]
clear_node(node_id: int) None[source]
create_node(parents_id: list[int | None], operation: Any, result: Any, is_leaf: bool = False) int | None[source]
plot(root_node_id: int, full_graph: bool) None[source]