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ο
A renaming on requantizations. It maps (tensor, need) pairs |
Functionsο
|
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