Transformation - Streamline

Transformation (Streamline)

class finn.transformation.streamline.Streamline

Bases: Transformation

Apply the streamlining transform, see arXiv:1709.04060.

apply(model)

finn.transformation.streamline.absorb

class finn.transformation.streamline.absorb.Absorb1BitMulIntoConv

Bases: Transformation

Absorb bipolar or binary multiplications into the preciding convolution.

apply(model)
class finn.transformation.streamline.absorb.Absorb1BitMulIntoMatMul

Bases: Transformation

Absorb bipolar or binary multiplications into the preciding matrix multiply.

apply(model)
class finn.transformation.streamline.absorb.AbsorbAddIntoMultiThreshold

Bases: Transformation

Absorb 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: Transformation

Remove (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: Transformation

Absorb 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: Transformation

Remove 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: Transformation

Absorb 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: Transformation

Absorb 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: Transformation

For (NCHWTranspose -> MultiThreshold) move Transpose past MultiThreshold and set its data_layout mode to NHWC.

apply(model)
class finn.transformation.streamline.absorb.AbsorbTransposeIntoResize

Bases: Transformation

For (NCHWTranspose -> Resize) move Transpose past Resize and change the Resize node’s attributes accordingly.

apply(model)
class finn.transformation.streamline.absorb.FactorOutMulSignMagnitude

Bases: Transformation

Split 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: CollapseRepeatedOp

Collapse repeated adder node into a single operation.

class finn.transformation.streamline.collapse_repeated.CollapseRepeatedMul

Bases: CollapseRepeatedOp

Collapse repeated multiplier node into a single operation.

class finn.transformation.streamline.collapse_repeated.CollapseRepeatedOp(op_name, make_collapsed_param_fxn)

Bases: Transformation

Collapse 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: Transformation

Convert (MaxPool, NHWCTranspose) into (NHWCTranspose, MaxPoolNHWC) and (NCHWTranspose, MaxPool) into (MaxPoolNHWC, NCHWTranspose).

apply(model)
class finn.transformation.streamline.reorder.MakeScaleResizeNHWC

Bases: Transformation

Converts the inputs and outputs for all scales Resize and Upsample nodes from NCHW to NHWC.

apply(model)
class finn.transformation.streamline.reorder.MoveAddPastConv

Bases: Transformation

Move 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.MoveAddPastMul

Bases: Transformation

Move 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.MoveFlattenPastAffine

Bases: Transformation

Moves a node that implements a (1, -1) reshape past a MatMul, Mul or Add node.

apply(model)
class finn.transformation.streamline.reorder.MoveFlattenPastTopK

Bases: Transformation

Move 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: Transformation

Move identical operations on different branches past the common join node. This transformation assumes that the identical operations only change the data layout. For linear operations, see the transformation MoveLinearPastEltwiseAdd. Specifically, this transformation matches and transforms the following patterns: f(x) + f(y) -> f(x + y) where f(.) is currently only supporting ‘Transpose’, and an ‘Add’ node is the join node.

apply(model)
move_node(model, n, prod0, prod1)
class finn.transformation.streamline.reorder.MoveLinearPastEltwiseAdd

Bases: Transformation

Move linear operations (mul, add) past elementwise add operations where possible. Specifically,matches and transforms the following patterns: (x*C) + (y*C) -> (x + y) * C (x+A) + (y+B) -> (x + y) + (A + B) where x and y are dynamic inputs, A, B, C are constant tensors (in general).

apply(model)
move_node(graph, n, prod0, prod1, node_ind)
class finn.transformation.streamline.reorder.MoveLinearPastFork

Bases: MoveOpPastFork

class finn.transformation.streamline.reorder.MoveMaxPoolPastMultiThreshold

Bases: Transformation

Move MaxPool nodes past MultiThreshold nodes on linear segments of the graph.

apply(model)
class finn.transformation.streamline.reorder.MoveMulPastDWConv

Bases: Transformation

Move 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.MoveMulPastMaxPool

Bases: Transformation

Move 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, get_attrs_fxn=<function MoveOpPastFork.<lambda>>)

Bases: Transformation

Move 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: Transformation

Move 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: Transformation

Move 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

apply(model)
class finn.transformation.streamline.reorder.MoveScalarMulPastConv

Bases: Transformation

Move 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: Transformation

Move 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: Transformation

Move 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

class finn.transformation.streamline.reorder.MoveTransposePastScalarMul

Bases: Transformation

Moves a Transpose node past a scalar Mul node

apply(model)

finn.transformation.streamline.round_thresholds

class finn.transformation.streamline.round_thresholds.RoundAndClipThresholds

Bases: Transformation

For MultiThreshold nodes operating on integer inputs, round up thresholds values to the nearest integer. Additionally, if the input is unsigned, sets negative thresholds to zero.

apply(model)

finn.transformation.streamline.sign_to_thres

class finn.transformation.streamline.sign_to_thres.ConvertSignToThres

Bases: Transformation

Convert Sign node instances to MultiThreshold with threshold at 0.

apply(model)