afe.common_utils
This file contains functions that can be used in all AFE source code
Classes
Overload Enum's _missing_ method to print out more |
|
Host and port of TVM RPC server where ARM code will be run in tests |
Functions
|
Use the postfix after the last splitter of the given name. If the postfix |
|
Unroll a tuple of two integers to a range of integers where the lower bound |
|
Used to parse a list of indices. Each element in the list can be: |
|
Given patterns in List[Union[str, int, Tuple[int, int]]], generate node name patterns |
|
Given a list of node names and targeted patterns in List[Union[str, int, Tuple[int, int]]] format. |
|
Get the last AFE git commit ID if running out of a git repository. |
|
Looks through the files inside a directory and returns the file path with the matching filetype. |
|
Return true if this file appears to be running from an installed package (not a source directory). |
|
Return the ARM target information if ARM target support is found on the system, |
Module Contents
- class afe.common_utils.EnumHelper[source]
Overload Enum’s _missing_ method to print out more informative error message.
- afe.common_utils.get_index_from_node_name(name: str, splitter='_') int | None [source]
Use the postfix after the last splitter of the given name. If the postfix is an integer, return it as the index.
Parameters
- param name:
str. Name of the node.
- param splitter:
str. Used to locate the postfix.
Return
- return:
Optional[int]. Return None if there is no index in the given node name else return the index in int.
- afe.common_utils.unroll_tuple_range(tuple_range: Tuple[int, int]) List[int] [source]
Unroll a 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.
Parameters
- param tuple_range:
Tuple[int, int]. Tuple of two integers used to generate a list of continuous integers.
Return
- return:
List[int]. List of continuous integers
- afe.common_utils.parse_indices(indices_list: List[int | Tuple[int, int]]) List[int] [source]
- Used to parse a list of indices. Each element in the list can be:
A single integer
A tuple contains 2 integers where the left one represent the lower bound and the right one represents the upper bound. Both lower bound and upper bound are inclusive.
Example
indices_list = [2, (11, 14), 7] decoded_indices_list = parse_indices(indices_list) # decoded_indices_list = [2, 7, 11, 12, 13, 14]
Parameters
- param indices_list:
List[int, Tuple[int, int]]. List of indices contains element in either an integer or a Tuple of two integers.
Return
- return:
List[int]. List of indices. Each element is a integer
- afe.common_utils.generate_node_name_patterns(patterns: List[str | int | Tuple[int, int]]) List[str] [source]
Given patterns in List[Union[str, int, Tuple[int, int]]], generate node name patterns using the different types of pattern as below:
str: Append to the output list. Support wildcard.
int: Append the *_{number} to the output list.
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 append to the output list.
The output list contains a list of str. Please check the example below
Example
patterns = [2, (11, 14), "*_conv*", "3", "10"] str_patterns = generate_str_patterns(patterns) # str_patterns = ["*_2", "*_11", "*_12", "*_13", "*_14", "*_conv*", "*_3", "*_10"]
Parameters
- param patterns:
List[str, int, Tuple[int, int]]
Return
- return:
List[str]. List of str patterns.
- afe.common_utils.search_matched_node_names(node_names: List[str], patterns: List[str | int | Tuple[int, int]], excluded_patterns: List[str | int | Tuple[int, int]] | None = None) Set[str] [source]
Given a list of node names and targeted patterns in List[Union[str, int, Tuple[int, int]]] format. Generate a node name set using the different types of pattern as below:
str: Support wildcard.
int: Find node with name contains *_{number}.
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 that will be used as 2 above
Return a set of matched node names
Example
The example will search nodes with indices equal to [2, 3, 10, 11, 12, 13, 14] and all the node contains “conv” in the node name. Because the excluded_patterns is assigned so the nodes with “conv2d_transpose” in the node name will be excluded.
patterns = [2, (11, 14), "*conv*", "3", "10"] excluded_patterns = ["*conv2d_transpose*"] matched_node_name_set = search_matched_node_names(net, patterns, excluded_patterns)
Parameters
- param node_names:
List[str]. List of node names and will be applied by the pattern matching using the patterns input argument.
- 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.
Return
- return:
Set[str]. Set of node names that contain the given patterns but not the excluded patterns
- afe.common_utils.get_afe_git_commit_id() str | None [source]
Get the last AFE git commit ID if running out of a git repository. Return None if the ID can’t be found. If running an installed package, no attempt is made to get the commit ID.
- Returns:
commit ID as string, if it can’t get ID returns None.
- afe.common_utils.get_filetype_from_directory(dir_path: str, filetype: str) str [source]
Looks through the files inside a directory and returns the file path with the matching filetype. Raises an error if multiple files match the filetype EG: in ‘./example_dir’ find ‘.json’ file path
- afe.common_utils.is_installed() bool [source]
Return true if this file appears to be running from an installed package (not a source directory).
- class afe.common_utils.ARMRuntime[source]
Host and port of TVM RPC server where ARM code will be run in tests
- afe.common_utils.get_arm_runtime() ARMRuntime | None [source]
Return the ARM target information if ARM target support is found on the system, or None otherwise.