Skip to main content

ClikaRT::graph::transforms

namespace

One factory per built-in transform, named as the transform is: transforms::remove_double_permute() returns the handle whose name() is "remove_double_permute".

Functions​

defaults()​

std::vector<Transform> defaults(const DefaultsOptions& options = DefaultsOptions())

The default transform list for options, taking the choices as stated: the shape-fixation transforms join under specialize or shape_fixation, and drop_boundary_permutes under either channels-last choice. A graph's own defaults can differ, since they follow how the graph was built (a graph compiled from ONNX without pinned shapes keeps the shape-fixation transforms without specialize): ModelGraph::default_transforms returns the list optimize() runs on that graph.

Declared in ClikaRT/graph/optimize.h, line 117

rewrite()​

Transform rewrite(
    std::string name,
    Pattern pattern,
    RewriteFunction replace_fn,
    RewriteCondition condition_fn = {},
    std::vector<Transform> runs_after = {}
)

A transform named name that rewrites the occurrences of pattern, for OptimizeOptions::transforms.

Each iteration of optimize searches the graph for pattern once (ModelGraph::find_pattern), then takes the occurrences in the order the search returns them. An occurrence is skipped, and condition_fn never sees it, when an earlier replacement in the same iteration removed one of its nodes, when it is not convex (ModelGraph::is_convex: a path leaves it and comes back, and no replacement keeps that path), or when nothing outside it reads a value it makes. Every other occurrence goes to condition_fn (an empty one accepts every occurrence), and one it accepts is replaced: replace(match.outputs, replace_fn over the match, match.inputs). The next iteration searches again, so an occurrence a replacement creates is rewritten then.

A failure ends the run: condition_fn's or replace_fn's own failure or throw, and a refusal from replace (a new value of another type or count, a KV cache layer's attention among the operators it removes, a cyclic graph). optimize returns it with its status and code, the message naming the occurrence's first matched node, and leaves the graph as it found it. The report's row reads as any transform you write: applications counts the iterations in which the rule replaced at least one occurrence.

The rule keeps pattern, and copies of the handle share it and the two functions. Both run on optimize's thread; a handle two runs use at once runs them on two threads.

Refuses as Status::InvalidArgument: an empty name, the name of one of the runtime's transforms, a runs_after entry of the same name, an empty replace_fn, a pattern with no node, and a pattern find_pattern refuses (an edge naming a node never added, more than kMaxOptionalPatternNodes optional nodes, a node added with an empty predicate).

Declared in ClikaRT/graph/rewrite.h, line 156

ClikaRT/graph/optimize.h​

#include <ClikaRT/graph/optimize.h>

Options and report for ModelGraph::optimize: the graph optimizer's defaults, its iteration cap, the transforms it runs, and what one run did.