Transformation - Streamline
Transformation (Streamline)
- class finn.transformation.streamline.Streamline
Bases:
TransformationApply the streamlining transform, see arXiv:1709.04060.
- apply(model)
finn.transformation.streamline.absorb
- class finn.transformation.streamline.absorb.Absorb1BitMulIntoConv
Bases:
TransformationAbsorb bipolar or binary multiplications into the preceding convolution.
- apply(model)
- class finn.transformation.streamline.absorb.Absorb1BitMulIntoMatMul
Bases:
TransformationAbsorb bipolar or binary multiplications into the preceding matrix multiply.
- apply(model)
- class finn.transformation.streamline.absorb.AbsorbAddIntoMultiThreshold
Bases:
TransformationAbsorb preceding Add ops into MultiThreshold by updating the threshold values. Only scalar/1D add vectors can be absorbed.
- apply(model)
- class finn.transformation.streamline.absorb.AbsorbConsecutiveTransposes
Bases:
TransformationRemove (Transpose -> Transpose) patterns when the input and output of the pattern have the same layout.
- apply(model)
- are_opposite_permutations(perms1, perms2)
- class finn.transformation.streamline.absorb.AbsorbMulIntoMultiThreshold
Bases:
TransformationAbsorb preceding Mul ops into MultiThreshold by updating the threshold values. Only positive scalar/1D mul vectors can be absorbed.
- apply(model)
- class finn.transformation.streamline.absorb.AbsorbScalarMulAddIntoTopK
Bases:
TransformationRemove mul/add node prior to topk node if the op is scalar. Note that the TopK output probabilities will change, but the indices won’t.
- apply(model)
- class finn.transformation.streamline.absorb.AbsorbSignBiasIntoMultiThreshold
Bases:
TransformationAbsorb scalar bias originating from signed int export back into MultiThreshold and re-evaluate the output datatype.
- apply(model)
- class finn.transformation.streamline.absorb.AbsorbTransposeIntoFlatten
Bases:
TransformationAbsorb transpose node into succeeding flatten node, if H=W=1 and the first dimension stays the same. Can also be applied if flatten is implemented implicitly by a reshape node with shape [1, -1] and the first input dimension is 1
- apply(model)
- class finn.transformation.streamline.absorb.AbsorbTransposeIntoMultiThreshold
Bases:
TransformationFor (NCHWTranspose -> MultiThreshold) move Transpose past MultiThreshold and set its data_layout mode to NHWC.
- apply(model)
- class finn.transformation.streamline.absorb.AbsorbTransposeIntoResize
Bases:
TransformationFor (NCHWTranspose -> Resize) move Transpose past Resize and change the Resize node’s attributes accordingly.
- apply(model)
- class finn.transformation.streamline.absorb.FactorOutMulSignMagnitude
Bases:
TransformationSplit multiply-by-constant nodes into two multiply-by-constant nodes, where the first node is a bipolar vector (of signs) and the second is a vector of magnitudes.
- apply(model)
finn.transformation.streamline.collapse_repeated
- class finn.transformation.streamline.collapse_repeated.CollapseRepeatedAdd
Bases:
CollapseRepeatedOpCollapse repeated adder node into a single operation.
- class finn.transformation.streamline.collapse_repeated.CollapseRepeatedMul
Bases:
CollapseRepeatedOpCollapse repeated multiplier node into a single operation.
- class finn.transformation.streamline.collapse_repeated.CollapseRepeatedOp(op_name, make_collapsed_param_fxn)
Bases:
TransformationCollapse repeated consecutive operations with constant parameters into a single operation. make_collapsed_param_fxn must take two tensors and return a tensor which gives the equivalent result using a single op.
- apply(model)
finn.transformation.streamline.reorder
- class finn.transformation.streamline.reorder.MakeMaxPoolNHWC
Bases:
TransformationConvert (MaxPool, NHWCTranspose) into (NHWCTranspose, MaxPoolNHWC) and (NCHWTranspose, MaxPool) into (MaxPoolNHWC, NCHWTranspose).
- apply(model)
- class finn.transformation.streamline.reorder.MakeScaleResizeNHWC
Bases:
TransformationConverts the inputs and outputs for all scales Resize and Upsample nodes from NCHW to NHWC.
- apply(model)
- class finn.transformation.streamline.reorder.MoveAddPastConv
Bases:
TransformationMove scalar and channelwise add operations past conv operations. We want to have adds next to each other such that they can be collapsed into a single add.
- apply(model)
- class finn.transformation.streamline.reorder.MoveAddPastFork
Bases:
MoveOpPastFork
- class finn.transformation.streamline.reorder.MoveAddPastJoinAdd
Bases:
MoveIdenticalOpPastJoinOp- are_producers_identical(model, producers)
Checks only op_types Should be overwritten for additional checks
- move_node(model, n, producers)
We use the base move_node method to move the first producer past the join node (and delete the rest)
- class finn.transformation.streamline.reorder.MoveAddPastJoinConcat
Bases:
MoveAffinePastJoinConcat
- class finn.transformation.streamline.reorder.MoveAddPastMul
Bases:
TransformationMove add operations past multiply operations on linear segments of the graph. The aim is to have them next to each other such that they can be collapsed into a single add.
- apply(model)
- class finn.transformation.streamline.reorder.MoveAffinePastJoinConcat(linear_ops=['Mul', 'Add'])
Bases:
MoveIdenticalOpPastJoinOpApplies to scalar linear or channelwise affine ops with the same parameter value
- are_producers_channelwise_ops(channel_dim, model, producers)
- are_producers_identical_scalar_ops(model, producers)
- move_node(model, n, producers)
Should be overwritten for some operations
- Returns:
bool: whether moving the node was successful
- class finn.transformation.streamline.reorder.MoveFlattenPastAffine
Bases:
TransformationMoves a node that implements a (1, -1) reshape past a MatMul, Mul or Add node.
- apply(model)
- class finn.transformation.streamline.reorder.MoveFlattenPastTopK
Bases:
TransformationMove flatten node past a succeeding topk node, if the “axis” attribute in topk is set to -1 and the data layout before the flatten is NHWC with H=W=1
- apply(model)
- class finn.transformation.streamline.reorder.MoveIdenticalOpPastJoinOp(identical_op_list, join_node_list)
Bases:
TransformationMove multiple identical operations on different branches past the common join node. It assumes the shape to be preserved by the join op in the default move_node() method
- apply(model)
- are_producers_identical(model, producers)
Checks only op_types Should be overwritten for additional checks
- move_node(model, n, producers)
Should be overwritten for some operations
- Returns:
bool: whether moving the node was successful
- class finn.transformation.streamline.reorder.MoveLinearPastFork
Bases:
MoveOpPastFork
- class finn.transformation.streamline.reorder.MoveMaxPoolPastMultiThreshold
Bases:
TransformationMove MaxPool nodes past MultiThreshold nodes on linear segments of the graph.
- apply(model)
- class finn.transformation.streamline.reorder.MoveMulPastDWConv
Bases:
TransformationMove channelwise mul operations past depthwise conv operations. We want to have muls next to each other such that they can be collapsed into a single mul.
- apply(model)
- class finn.transformation.streamline.reorder.MoveMulPastFork
Bases:
MoveOpPastFork
- class finn.transformation.streamline.reorder.MoveMulPastJoinAdd
Bases:
MoveIdenticalOpPastJoinOp- are_producers_identical(model, producers)
Checks only op_types Should be overwritten for additional checks
- class finn.transformation.streamline.reorder.MoveMulPastJoinConcat
Bases:
MoveAffinePastJoinConcat
- class finn.transformation.streamline.reorder.MoveMulPastMaxPool
Bases:
TransformationMove non-negative scalar or channelwise mul operations past max pool operations. We want to have muls next to each other such that they can be collapsed into a single mul.
- apply(model)
- class finn.transformation.streamline.reorder.MoveOpPastFork(op_name_list)
Bases:
TransformationMove node operations past graph forks. Used when a node before a fork can be merged with nodes in the branches
- apply(model)
- class finn.transformation.streamline.reorder.MoveScalarAddPastMatMul
Bases:
TransformationMove scalar add operations past matmul operations. We want to have adds next to each other such that they can be collapsed into a single add.
- apply(model)
- class finn.transformation.streamline.reorder.MoveScalarLinearPastInvariants
Bases:
TransformationMove scalar linear operations (mul, add) past functions which are invariant to them. Specifically, matches and transforms the following patterns: f(x*C) -> f(x) * C f(x+C) -> f(x) + C where x is a dynamic input, C is a constant tensor. Known f which obey this property are: Reshape, Flatten, Transpose, GlobalAveragePool
- SUPPORTED_INVARIANTS = {'Flatten', 'GlobalAveragePool', 'Reshape', 'Slice', 'Squeeze', 'Transpose', 'Unsqueeze'}
- apply(model)
- class finn.transformation.streamline.reorder.MoveScalarLinearPastSplit
Bases:
TransformationMove scalar Mul and Add nodes past channel split operation.
- apply(model)
- class finn.transformation.streamline.reorder.MoveScalarMulPastConv
Bases:
TransformationMove scalar mul operations past conv operations. We want to have muls next to each other such that they can be collapsed into a single mul.
- apply(model)
- class finn.transformation.streamline.reorder.MoveScalarMulPastConvTranspose
Bases:
TransformationMove scalar mul operations past ConvTranspose operations. We want to have muls next to each other such that they can be collapsed into a single mul.
- apply(model)
- class finn.transformation.streamline.reorder.MoveScalarMulPastMatMul
Bases:
TransformationMove scalar mul operations past matmul operations. We want to have muls next to each other such that they can be collapsed into a single mul.
- apply(model)
- class finn.transformation.streamline.reorder.MoveTransposePastFork
Bases:
MoveOpPastFork
- class finn.transformation.streamline.reorder.MoveTransposePastJoinAdd
Bases:
MoveIdenticalOpPastJoinOp- are_producers_identical(model, producers)
Checks only op_types Should be overwritten for additional checks
- class finn.transformation.streamline.reorder.MoveTransposePastJoinConcat
Bases:
MoveIdenticalOpPastJoinOp- are_producers_identical(model, producers)
Checks only op_types Should be overwritten for additional checks
- move_node(model, n, producers)
Should be overwritten for some operations
- Returns:
bool: whether moving the node was successful
- class finn.transformation.streamline.reorder.MoveTransposePastScalarMul
Bases:
TransformationMoves a Transpose node past a scalar Mul node
- apply(model)
- class finn.transformation.streamline.reorder.MoveTransposePastSplit
Bases:
Transformation- apply(model)
- finn.transformation.streamline.reorder.permute_shape(shape, perm)
finn.transformation.streamline.round_thresholds
- class finn.transformation.streamline.round_thresholds.RoundAndClipThresholds
Bases:
TransformationFor MultiThreshold, Thresholding, MVAU, and VVAU nodes operating on integer inp/accumulators, round up (ceil) threshold values to the nearest integer and clip to valid range. Type-casts thresholds (back) to the float32 container type (this is separate from the quantization annotation). Runs InferDataTypes() afterward to propagate any changes to the quantization data types.
- apply(model: ModelWrapper)
finn.transformation.streamline.sign_to_thres
- class finn.transformation.streamline.sign_to_thres.ConvertSignToThres
Bases:
TransformationConvert Sign node instances to MultiThreshold with threshold at 0.
- apply(model)