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 preciding convolution.
- apply(model)
- class finn.transformation.streamline.absorb.Absorb1BitMulIntoMatMul
Bases:
TransformationAbsorb bipolar or binary multiplications into the preciding 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.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.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 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:
TransformationMove 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:
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.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, get_attrs_fxn=<function MoveOpPastFork.<lambda>>)
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
- 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
- class finn.transformation.streamline.reorder.MoveTransposePastScalarMul
Bases:
TransformationMoves a Transpose node past a scalar Mul node
- apply(model)
finn.transformation.streamline.round_thresholds
- class finn.transformation.streamline.round_thresholds.RoundAndClipThresholds
Bases:
TransformationFor 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:
TransformationConvert Sign node instances to MultiThreshold with threshold at 0.
- apply(model)