afe.ir.debug
Functions
|
Given the set of nodes that need to be fixed to floating point, find all their |
|
Given patterns in List[Union[str, int, Tuple[int, int]]], generate a node name pattern set |
|
Determine the critical node with worse quantization results for given metric, for analysis done in |
Determine the critical node with worse quantization results for given metric, for analysis done in |
|
|
Determine the critical node with worse quantization results for given metric. |
Improves precision of calibrated AwesomeNet by running the graph quantization analysis, |
Module Contents
- afe.ir.debug.fix_constant_input_nodes_to_float(net: afe.ir.net.AwesomeNet, nodes_to_be_fixed: Set[str])[source]
Given the set of nodes that need to be fixed to floating point, find all their constant input nodes and fix them to floating point as well.
- Parameters:
net – AwesomeNet. Input AwesomeNet which nodes are subject to fixing in floating point.
nodes_to_be_fixed – Set[str]. Set of names of nodes that are to be fixed to floating point and expanded with constant input nodes.
- afe.ir.debug.fix_nodes_to_float(net: afe.ir.net.AwesomeNet, patterns: List[str | Tuple[int, int]], excluded_patterns: List[str | Tuple[int, int]] | None = None, verbose: bool = True, fix_constant_input_nodes: bool = False) None [source]
Given patterns in List[Union[str, int, Tuple[int, int]]], generate a node name pattern set using the different types of pattern as below:
str: Add to the set. Support wildcard.
int: Add the *_{number} to the set.
Tuple[int, int]: Unroll the tuple of two integers to a range of integers where the lower bound is the first integer of the tuple and the upper bound is the second integer of the tuple. Each integer will be converted to *_{number} string and add to the set.
Use the set to pattern match each node names in the given AwesomeNet. Add the matched node name to net.float_node_list. Each sub awesome-net has its own float_node_list which is updated. The node will still be calibrated so the downstream nodes can have its zero points and scales, but it won’t get quantized.
Example
The example add the nodes with indices equal to [2, 3, 10, 11, 12, 13, 14] and all the nodes containing “conv” in the node name to net.float_node_list. The node with “conv2d_transpose” in the node name will be excluded and will not be set to fixed float. Set the verbose to True to print out the node names that are added to float_node_list.
patterns = [2, (11, 14), "*conv*", "3", "10"] excluded_patterns = ["*conv2d_transpose*"] fix_nodes_to_float(net, patterns, excluded_patterns, verbose=True)
Parameters
- param net:
AwesomeNet. The AwesomeNet contains nodes that user want to fixed to float.
- param patterns:
List[Union[str, int, Tuple[int, int]]]. List of patterns.
- param excluded_patterns:
Optional[List[Union[str, int, Tuple[int, int]]]]. Default is None. List of patterns that will be excluded from the pattern matching. Node names that contains these patterns will be excluded from the matched patterns.
- param verbose:
bool. Default is True. Set to False if user want to hide the print message
- param fix_constant_input_nodes:
bool. Default is True. Set to True if user wants to also fix all constant input nodes of nodes matching patterns. This will avoid errors in cases where fixing one node to floating point would lead to its constant input missing quantization data. Otherwise, set to False.
Return
- return:
None
- afe.ir.debug.get_critical_node_local_feed(results: Dict[afe.core.graph_analyzer.utils.Metric, afe.core.graph_analyzer.analyzed_results.AnalyzedResultDict], float_nodes: List[str], metric: afe.core.graph_analyzer.utils.Metric, verbose: bool) str [source]
Determine the critical node with worse quantization results for given metric, for analysis done in QuantizedGraphAnalyzerMode.local_feed mode.
Parameters
- param results:
Dict[Metric, AnalyzedResultDict]. Results of the graph quantization analysis.
- param float_nodes:
List[str]. If given, the list of nodes already set to fp32.
- param metric:
Metric. Defines metric used for determining the critical node.
- param verbose:
bool. Default is False. If set to True the function will print out critical node name.
Return
- return:
str. Name of the critical node.
- afe.ir.debug.get_critical_node_global_feed(results: Dict[afe.core.graph_analyzer.utils.Metric, afe.core.graph_analyzer.analyzed_results.AnalyzedResultDict], float_nodes: List[str], metric: afe.core.graph_analyzer.utils.Metric, verbose: bool) str [source]
Determine the critical node with worse quantization results for given metric, for analysis done in QuantizedGraphAnalyzerMode.global_feed mode.
Parameters
- param results:
Dict[Metric, AnalyzedResultDict]. Results of the graph quantization analysis.
- param float_nodes:
List[str]. If given, the list of nodes already set to fp32.
- param metric:
Metric. Defines metric used for determining the critical node.
- param verbose:
bool. Default is False. If set to True the function will print out critical node name.
Return
- return:
str. Name of the critical node.
- afe.ir.debug.get_critical_node(results: Dict[afe.core.graph_analyzer.utils.Metric, afe.core.graph_analyzer.analyzed_results.AnalyzedResultDict], float_nodes: List[str], mode: str | afe.core.graph_analyzer.utils.QuantizedGraphAnalyzerMode, metric: afe.core.graph_analyzer.utils.Metric, verbose: bool = False) str [source]
Determine the critical node with worse quantization results for given metric.
Parameters
- param results:
Dict[Metric, AnalyzedResultDict]. Results of the graph quantization analysis.
- param float_nodes:
List[str]. If given, the list of nodes already set to fp32.
- param mode:
Union[str, QuantizedGraphAnalyzerMode]
- param metric:
Metric. Defines metric used for determining the critical node.
- param verbose:
bool. Default is False. If set to True the function will print out critical node name.
Return
- return:
str. Name of the critical node.
- afe.ir.debug.improve_quantized_net_performance(calibrated_net: afe.ir.net.AwesomeNet, quantized_net: afe.ir.net.AwesomeNet, reference_net: afe.ir.net.AwesomeNet, input_data_set: Iterable[Dict[str, numpy.ndarray]], mode: afe.core.graph_analyzer.utils.QuantizedGraphAnalyzerMode = QuantizedGraphAnalyzerMode.local_feed, metric: afe.core.graph_analyzer.utils.Metric = Metric.mse) str [source]
Improves precision of calibrated AwesomeNet by running the graph quantization analysis, finding the critical node and fixing the critical node to floating point.
Parameters
- param calibrated_net:
AwesomeNet. Calibrated AwesomeNet which precision needs to be improved.
- param quantized_net:
AwesomeNet. Quantized AwesomeNet which precision needs to be improved.
- param reference_net:
AwesomeNet. Reference FP32 AwesomeNet.
- param input_data_set:
Iterable of input data used for quantization analysis. It is recommended to use a smaller data set than calibration would use.
- param mode:
QuantizedGraphAnalyzerMode. Default is QuantizedGraphAnalyzerMode.local_feed. Mode in which the GraphAnalyzer shall be used.
- param metric:
Metric. Default is Metric.mse. Defines which metric is used in determining the critical node.
- return:
str. Name of the node that needs to be fixed to higher precision.