qonnx.transformation.base (module)

Guide to writing QONNX transformations

  • Your transformation must inherit the Transformation abstract base class.

  • Your transformation’s apply function should take in a ModelWrapper, and return a tuple with (transformed_model: ModelWrapper, model_was_changed: Bool)

  • The transformations are meant to be applied using the .transform function in ModelWrapper. This makes a deep copy of the input model by default, so you don’t have to.

  • model_was_changed indicates whether your transformation made any changes to the model. If you know your transformation needs to be called only once and repeated calls have no further effect, you can return False even if the model was changed.

  • You MUST return model_was_changed=False at some point when your transformation is called multiple times, otherwise apply_repeated() will loop infinitely.

  • If you cannot guarantee that the transformation will reach a fixed point, you must declare this, return model_was_changed = False and let the user manually re-apply the transform.

class qonnx.transformation.base.NodeLocalTransformation(num_workers=None)

Bases: qonnx.transformation.base.Transformation

Parent class for transformations, which can be executed locally to one node by accessing and modifying the attributes of only that node. This class can then automatically parallelize the transformation. Transformations sublcassing NodeLocalTransformation must implement the abstract method applyNodeLocal(). A read-only copy of the model is available as a member variable ref_input_model, but any modifications there will be disregarded.

To control the degree of parallelization, specify the num_workers argument in the constructor, using one of the following values: * None: use NUM_DEFAULT_WORKERS environment variable * 0: use all available CPU cores * (any other int>0): set number of parallel workers

apply(model)
abstract applyNodeLocal(node)
class qonnx.transformation.base.Transformation

Bases: abc.ABC

Transformation class all transformations are based on. Contains only abstract method apply() every transformation has to fill.

abstract apply(model)