( # noqa: C901
node: torch.fx.Node,
nodes: Dict[str, Node],
const_count: int,
module_mapping: Dict[Tuple[str, str], List[Node]],
enable_module_hierarchy: bool,
)
| 110 | |
| 111 | @staticmethod |
| 112 | def _parse_args( # noqa: C901 |
| 113 | node: torch.fx.Node, |
| 114 | nodes: Dict[str, Node], |
| 115 | const_count: int, |
| 116 | module_mapping: Dict[Tuple[str, str], List[Node]], |
| 117 | enable_module_hierarchy: bool, |
| 118 | ) -> Tuple[List[Node], int]: |
| 119 | inputs = [] |
| 120 | op = node.op |
| 121 | name = node.name |
| 122 | args = node.args |
| 123 | kwargs = node.kwargs |
| 124 | named_args = None |
| 125 | if node.op == "call_function" and hasattr(node.target, "_schema"): |
| 126 | # pyre-ignore |
| 127 | named_args = node.target._schema.arguments |
| 128 | |
| 129 | if node.op == "call_function" and ( |
| 130 | node.target == auto_functionalized or node.target == auto_functionalized_v2 |
| 131 | ): |
| 132 | # for functioanlized HOPs, args for the corresponding functional op are stored in kwargs |
| 133 | args = tuple(kwargs.values()) |
| 134 | |
| 135 | for index, arg in enumerate(args): |
| 136 | if isinstance(arg, torch.fx.node.Node): |
| 137 | if arg.target == exir.memory.alloc: |
| 138 | continue |
| 139 | arg_name = FXOperatorGraph._get_node_name(arg) |
| 140 | elif isinstance(arg, (int, float, torch.dtype, str)): |
| 141 | # e.g. The "0" from node.args of squeeze_copy (mm_default, 0) |
| 142 | if named_args and len(named_args) > index: |
| 143 | arg_name = named_args[index].name + "_" + str(const_count) |
| 144 | else: |
| 145 | arg_name = "CONST_" + str(const_count) |
| 146 | const_count += 1 |
| 147 | const_node = ValueNode(arg_name, val=str(arg)) |
| 148 | nodes[arg_name] = const_node |
| 149 | if enable_module_hierarchy: |
| 150 | FXOperatorGraph._update_module_mapping( |
| 151 | const_node, module_mapping, node.meta |
| 152 | ) |
| 153 | elif isinstance(arg, list): |
| 154 | arg_name: List[str] = [] |
| 155 | for list_arg in arg: |
| 156 | if isinstance(list_arg, (int, float)): |
| 157 | # Consider the whole list of ints/floats as a single constant and |
| 158 | # stringify that. |
| 159 | if named_args and len(named_args) > index: |
| 160 | arg_name = [named_args[index].name + "_" + str(const_count)] |
| 161 | else: |
| 162 | arg_name = ["CONST_" + str(const_count)] |
| 163 | const_count += 1 |
| 164 | const_node = ValueNode(arg_name[0], val=arg) |
| 165 | nodes[arg_name[0]] = const_node |
| 166 | if enable_module_hierarchy: |
| 167 | FXOperatorGraph._update_module_mapping( |
| 168 | const_node, module_mapping, node.meta |
| 169 | ) |
no test coverage detected