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 shape
  • TensorOp an implementation of a specific graph operation which performs forward/backwad operation.

*

(* & inputs)

+

(+ & inputs)

-ensure-arity

(-ensure-arity expected-arity input-nodes)

-ensure-same-shapes

(-ensure-same-shapes nodes)

-forward

(-forward node factory cache)

-tensor

(-tensor node key factory cache)

-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

arg-max

(arg-max x)

concat

(concat dim & inputs)

cross-entropy-loss

(cross-entropy-loss activations label)

dropout

(dropout p input)

ensure-vector-tensor?!

(ensure-vector-tensor?! prefix shape)

exp

(exp input)

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

hadamard

(hadamard x y)

Output is element-wise product of two inputs

max

(max & inputs)

Inputs: Tensors of same shape Output: Tensor of input shape where each element is maximum

scalar-op

(scalar-op key)

graph operation of single argument where output is same shape

scale

(scale scale node)

sigmoid

(sigmoid input)

split

(split node dim & split-indices)

squeeze

(squeeze input dim-to-squeeze)

strech

(strech input dim-to-insert)

sum-elems

(sum-elems node)

summarize-computation

(summarize-computation target indent)(summarize-computation target)

Create informative s-expression for computation

tanh

(tanh input)

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.

vec-remove

(vec-remove coll pos)

remove elem in coll