clika_runtime.graph
The graph as data.
A compiled or traced :class:ModelGraph answers nodes() with its
:class:Node views: each carries an :class:OpCode, a name, its attributes
as plain Python values, and the :class:Value views of the tensors it
consumes and produces; bound_tensors() names the weights a traced module
bound into the operator (constants() lists edge constants such as an ONNX
initializer). find_nodes(op_code), node(name), constants() and
is_finalized() complete the read surface, and a
:class:Pattern (a graph of operator constraints) finds its occurrences
through find_pattern as :class:Match entries::
graph = crt.io.OnnxModel.open("model.onnx").compile()
for node in graph.nodes():
print(node.name, node.op_code, node.attributes)
(relu,) = graph.find_nodes(crt.graph.OpCode.Relu)
for match in graph.find_pattern(crt.graph.Pattern([OpCode.MatMul, OpCode.Relu])):
matmul, relu = match
A view stays valid while its graph is alive and unchanged; holding one keeps the graph alive.
The graph also answers what shapes it admits and how fast it runs:
shape_domains() reports one :class:ShapeDomain per input (each
dimension :class:DimDomain Fixed, Range or Free), validate_shapes
checks shapes against them, and bench times synthesized or given inputs
into a :class:BenchReport::
domains = graph.shape_domains()
report = graph.bench([[8, 131]], crt.graph.BenchOptions(warmup=2, iterations=10))
print(report.p50_ms, report.throughput_items_per_s)
print(report.to_csv())
| Name | Kind |
|---|---|
BenchOptions | class |
BenchReport | class |
DimDomain | class |
FeedFill | class |
InputShape | class |
Match | class |
ModelGraph | class |
Node | class |
NodeKind | class |
OpCode | class |
Pattern | class |
ShapeDomain | class |
Value | class |