(
exp_prog: ExportedProgram, node: torch.fx.Node
)
| 76 | |
| 77 | |
| 78 | def get_param_tensor( |
| 79 | exp_prog: ExportedProgram, node: torch.fx.Node |
| 80 | ) -> Optional[torch.Tensor]: |
| 81 | if node is None: |
| 82 | return None |
| 83 | elif is_param(exp_prog, node): |
| 84 | return get_param(exp_prog, node) |
| 85 | elif is_buffer(exp_prog, node): |
| 86 | return get_buffer(exp_prog, node) |
| 87 | elif is_lifted_tensor_constant(exp_prog, node): |
| 88 | return get_lifted_tensor_constant(exp_prog, node) |
| 89 | elif is_get_attr_node(node): |
| 90 | # This is a hack to support both lifted and unlifted graph |
| 91 | try: |
| 92 | return getattr(node.graph.owning_module, node.target) |
| 93 | except AttributeError: |
| 94 | return getattr(exp_prog.graph_module, node.target) |
| 95 | raise RuntimeError(f"unsupported param type, {node.op}.") |
| 96 | |
| 97 | |
| 98 | def create_constant_placeholder( |
no test coverage detected