Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tensors & the Computational Graph

teeny-core::graph (API docs) defines the types every other crate builds on:

  • ShapeVec<Option<usize>>; None entries are symbolic/dynamic dimensions (e.g. a batch dimension left unbound until trace time).
  • DtypeRepr — the element dtype of a tensor (F32, etc. — see The Dtype System).
  • Op — the set of graph operations (elementwise, reductions, layout, etc.).
  • GraphNode / Graph — the traced computational graph: nodes are Op applications, edges are data dependencies.
  • SymTensor — a symbolic tensor handle used while tracing a model: calling layers with a SymTensor input records Ops into a Graph rather than executing eagerly.

Tracing

Building a Graph from a model is “tracing”: construct a SymTensor::input(dtype, shape), call your model with it (via the nn::Layer trait), and read back the Graph that was recorded as a side effect. See teeny-cli’s aot_compile for a concrete example of this pattern.

What happens to the Graph next is covered in Compilation Flow.