flare.computation-graph
Abstractions for constructing computation graphs using graph operations. The public methods for operations are at bottom of this ns. The key protocols are as follows:
GraphOp
a computational graph operation that knows nothing about tensor implementation, but can validate if inputs nodes are valid and predict output shapeTensorOp
an implementation of a specific graph operation which performs forward/backwad operation.
-tensor-op
(-tensor-op node factory)
valdiates that tensor op valid for a computation, and returns TensorOp
add-graph-op
(add-graph-op op nodes)
create a new node using a GraphOp
and a sequence of nodes. If in eager?
mode, will execute the tensor operation as well and result will be in :tensor
field on returned node
The nodes
inputs will be on the :children
field of returned Node
generate-equations
(generate-equations target)
generate semi-readable equations for computations in DAG represented by target
GraphOp
protocol
Graph operation only needs to be aware of shape of output, independent of any tensor implementation.
members
forward-shape
(forward-shape this input-shapes)
returns the shape of the operation
op-descriptor
(op-descriptor this)
returns a text description of the operation, useful for generating equations of the graph computations, can include the shape or other arguments
op-key
(op-key this)
A keyword that uniquely identifies the graph operation, useful for connecting to a tensor implementation.
op-validate!
(op-validate! this nodes)
throws exception if the operation isn’t valid for the argument nodes
max
(max & inputs)
Inputs: Tensors of same shape Output: Tensor of input shape where each element is maximum
summarize-computation
(summarize-computation target indent)
(summarize-computation target)
Create informative s-expression for computation
TensorOp
protocol
A tensor op executes a given GraphOp
in a tensor implementation
members
backward-node-pass!
(backward-node-pass! this node)
compute the :grad
gradient tensor on each child of passed in node reaching down to the leaves (which include the parameter nodes). Returns the node so that downstream backward-node-pass! calls can use added data.
ensure-valid?!
(ensure-valid?! this input-nodes)
Ensure the operation can be perfed with the tensor operation. Some impls may support limited dimension or sizes
forward-node-pass!
(forward-node-pass! this node)
compute the forward pass of the algorithm, for each node, compute :value
tensor for passed in node, using the :children
nodes and their :value
tensors. Returns the node in case any other computations are added to the node for use in the backward pass.