afe.ir.transform.requantization_hoisting.hoisting_transform

This module defines the requantization hoisting transformation. It moves Requantize nodes from their original locations (usually at the input of a node) to immediately after the node that produces its input data.

Classes

RqRenaming

A renaming on requantizations. It maps (tensor, need) pairs

Functions

move_requantization_in_model_graph(β†’Β afe.ir.net.AwesomeNet)

Place all Requantize nodes as early as possible in the model graph.

Module Contents

class afe.ir.transform.requantization_hoisting.hoisting_transform.RqRenaming[source]

A renaming on requantizations. It maps (tensor, need) pairs in the old net to tensors in the new net. Where a model uses tuples, it has mappings for the tensors in the tuples.

For a value named N in the old net, self.find(N) is a DataValue identifing the tensor values corresponding to N in the new net. As a tensor may have been requantized several ways, the corresponding tensor values are stored as a NeedMapping[NodeName].

find(n: afe.ir.defines.NodeName) afe.ir.defines.DataValue[afe.ir.transform.requantization_hoisting.defines.NeedMapping[afe.ir.defines.NodeName]][source]

Get all renaming information for the output of one node. It is an error if the node is not found.

find_tensor(n: afe.ir.defines.NodeName, need: afe.ir.transform.requantization_hoisting.defines.Need) afe.ir.defines.NodeName[source]

Find the new tensor representing the given node’s output and need.

get(n: afe.ir.defines.NodeName) afe.ir.defines.DataValue[afe.ir.transform.requantization_hoisting.defines.NeedMapping[afe.ir.defines.NodeName]] | None[source]

Get all renaming information for the output of one node, or None if there is no information.

get_tensor(n: afe.ir.defines.NodeName, need: afe.ir.transform.requantization_hoisting.defines.Need) afe.ir.defines.NodeName | None[source]

Get the new tensor representing the given node’s output and need, or None if there is no such tensor.

assign(n: afe.ir.defines.NodeName, v: afe.ir.defines.DataValue[afe.ir.transform.requantization_hoisting.defines.NeedMapping[afe.ir.defines.NodeName]]) None[source]

Assign the renaming information for the output of one node.

assign_tensor(n: afe.ir.defines.NodeName, transformed_n: afe.ir.defines.NodeName) None[source]

Assign the renaming information for the output of one node, where the output is a single tensor and it is not requantized.

update_tensor(n: afe.ir.defines.NodeName, need: afe.ir.transform.requantization_hoisting.defines.Need, transformed_n: afe.ir.defines.NodeName) None[source]

Record that transformed_n represents the single tensor output of n requantized by need. Node n must output a single tensor. Other renamings for node n are not affected.

Parameters:
  • n – Node in old model that will be associated to a node in the new model

  • need – Requantization that is performed on the output of n

  • transformed_n – Node in new model that will be associated to n

afe.ir.transform.requantization_hoisting.hoisting_transform.move_requantization_in_model_graph(net: afe.ir.net.AwesomeNet, node_needs: Dict[afe.ir.defines.NodeName, afe.ir.transform.requantization_hoisting.defines.DataNeeds], subgraph_inputs: Dict[afe.ir.defines.NodeName, List[afe.ir.transform.requantization_hoisting.defines.DataNeeds]]) afe.ir.net.AwesomeNet[source]

Place all Requantize nodes as early as possible in the model graph. All requantize nodes are removed, and the requantize nodes which are needed are reconstructed in the same location as the node that produced their input.

Parameters:
  • net – Model to transform

  • node_needs – Uses of the outputs of all nodes, as computed by analyze_needs

  • subgraph_inputs – Uses of the inputs of all subgraphs, as computed by analyze_needs

Returns:

Transformed model