(self, graph_module: torch.fx.GraphModule)
| 265 | return ProxyValue(res_data, res_proxy) |
| 266 | |
| 267 | def inputs(self, graph_module: torch.fx.GraphModule) -> List[Argument]: |
| 268 | # TODO(angelayi): Update this with what we decide to do for metadata in |
| 269 | # the exported graph module |
| 270 | if (args := graph_module.meta.get("args", None)) is not None: |
| 271 | return list(args) |
| 272 | |
| 273 | def extract_input(node: torch.fx.Node) -> Optional[FakeTensor]: |
| 274 | if "val" in node.meta: |
| 275 | fake = node.meta["val"] |
| 276 | if hasattr(fake, "constant") and fake.constant is not None: |
| 277 | return fake.constant |
| 278 | return fake |
| 279 | elif tensor_meta := node.meta.get("tensor_meta"): |
| 280 | assert self.fake_tensor_mode is not None |
| 281 | return FakeTensor( |
| 282 | self.fake_tensor_mode, |
| 283 | torch.empty( |
| 284 | tensor_meta.shape, |
| 285 | dtype=tensor_meta.dtype, |
| 286 | device="meta", |
| 287 | requires_grad=tensor_meta.requires_grad, |
| 288 | memory_format=tensor_meta.memory_format, |
| 289 | ), |
| 290 | torch.device("cpu"), |
| 291 | ) |
| 292 | elif len(node.users) == 0: |
| 293 | return None |
| 294 | raise ExportPassBaseError( |
| 295 | f"Cannot construct an input for graph module: {graph_module}.", |
| 296 | ) |
| 297 | |
| 298 | return [ |
| 299 | extract_input(node) |
| 300 | for node in graph_module.graph.nodes |
| 301 | if node.op == "placeholder" |
| 302 | ] |
| 303 | |
| 304 | def on_attr(self, attr: ProxyValue) -> None: |
| 305 | pass |
no test coverage detected