Wrapper for processing and serializing all types of placeholders.
(
node: torch.fx.Node,
tosa_graph: Any,
edge_program: ExportedProgram,
containing_graph_module: torch.fx.GraphModule | None,
tosa_spec: TosaSpecification,
)
| 234 | |
| 235 | |
| 236 | def process_placeholder( |
| 237 | node: torch.fx.Node, |
| 238 | tosa_graph: Any, |
| 239 | edge_program: ExportedProgram, |
| 240 | containing_graph_module: torch.fx.GraphModule | None, |
| 241 | tosa_spec: TosaSpecification, |
| 242 | ): |
| 243 | """Wrapper for processing and serializing all types of placeholders.""" |
| 244 | if node.name != node.target: |
| 245 | raise ValueError( |
| 246 | f"Placeholder name '{node.name}' does not match target '{node.target}'" |
| 247 | ) |
| 248 | if len(node.args) != 0: |
| 249 | raise ValueError(f"Placeholder '{node.name}' must not have default values") |
| 250 | |
| 251 | if node.name in edge_program.graph_signature.user_inputs: |
| 252 | process_inputs(node, tosa_graph, tosa_spec) |
| 253 | elif containing_graph_module and _is_submodule_input(node, containing_graph_module): |
| 254 | process_inputs(node, tosa_graph, tosa_spec) |
| 255 | elif is_param(edge_program, node): |
| 256 | process_inputs_to_parameters(node, tosa_graph, edge_program, tosa_spec) |
| 257 | elif is_buffer(edge_program, node): |
| 258 | process_inputs_to_buffers(node, tosa_graph, edge_program, tosa_spec) |
| 259 | elif is_lifted_tensor_constant(edge_program, node): |
| 260 | process_inputs_to_lifted_tensor_constants( |
| 261 | node, tosa_graph, edge_program, tosa_spec |
| 262 | ) |
| 263 | elif node.name in edge_program.graph_signature.inputs_to_lifted_custom_objs: |
| 264 | raise NotImplementedError( |
| 265 | "Placeholder is of type 'lifted custom object' which is not supported." |
| 266 | ) |
| 267 | else: |
| 268 | raise RuntimeError(f"Placeholder '{node.name}' is of unknown type.") |
| 269 | |
| 270 | |
| 271 | def process_output(node: torch.fx.Node, tosa_graph: Any, tosa_spec: TosaSpecification): |