This document presents the IR as of October 17th 2018. Future changes like mutability might render parts of this document outdated.
PyTorch uses an SSA-based IR, which is built of multiple entities:
Graph
is generally the outermost container for the program representation. At the moment all programs are mostly pure (modulo special operators likeprim::Print
orprim::PythonOp
), but this will change in the future.- Then, there are
Block
s, which you can treat as functions. They have a list of inputs and outputs, and a (topologically ordered) list ofNode
s. EveryGraph
has a top-levelBlock
which is (using C lingo) like amain
function. Node
s, in turn, represent calls to functions (with possibly multiple arguments and returns).- Finally, every single intermediate value that appears in the program is represented using a
Value
- the rootBlock
s have a list of input values, and everyNode
takes them as inputs, and returns some more as outputs. Every Value has aType
a