Handbook for Cirkit's Torch Compiler¤
Basic Terminology¤
- Symbolic Layers / Circuit are the abstract layers used in the normal circuit, they do not specify the concrete operations.
- Compiled Layers / Circuit are the layers that specify the exact computation in the chosen computation framework (here PyTorch)
- The Topological Order of nodes in a circuit is an ordering of the nodes from input to output.
- The Layer Topological Order is an ordering that groups layers depending on their depth with respect to its inputs. A layer is included in the current list if all its inputs have been included in previous lists.
Representing a Circuit¤
If you are new to cirkit, you need to understand how PCs are represented. A graph is described by:
- the list of its nodes:
[n1,n2,n3,n4]. - the input dictionary, which represents the edges of the graph as an adjacency list:
{
n1:[],
n2:[n1],
n3:[n1],
n4:[n2, n3]
}
This adjacency list represents this graph:
flowchart TD
n1((n1)) --> n2((n2))
n1 --> n3((n3))
n2--> n4((n4))
n3--> n4
- The outputs list which contains the nodes that are returned by the graph. Of course, these nodes need to be defined in the input dictionary.
Torch Compiler Components¤
Here you will find a short explanation of some important components used for the compilation:
TorchParameterare computational graphs, they are made ofTorchParameterNodeobjects of two types:- Input node, which can be a randomly initialized constant or a number provided by an external process (such as learned parameters).
- Operation node: computations applied to parameters, e.g., Softmax.
- The compiler registries (
CompilerRegistry) are mappings between types and Rules (Functions). They specify how to transform a symbolic layer / parameter / initializer into concrete PyTorch Graph element. There are three types of compiler registries: CompilerLayerRegistryCompilerParameterRegistryCompilerInitializerRegistry- The
Semiringobject stores the concrete operations to use for addition and multiplication as well as the domain. - The
CompiledCircuitsMapwhich stores bidirectional mappings between symbolic and compiled circuits.
The Compilation Process¤
Compiling a symbolic circuit involves three main steps:
- Transforming all symbolic layers / parameters / initializers to their compiled versions.
- Optimizing the Torch graph by fusing or splitting certain layers according to optimization parameters.
- Folding the circuit
You can dive deeper into the different processes on these pages: