MCPcopy Create free account
hub / github.com/pytorch/pytorch / inputs

Method inputs

torch/_export/pass_base.py:267–302  ·  view source on GitHub ↗
(self, graph_module: torch.fx.GraphModule)

Source from the content-addressed store, hash-verified

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

Callers 15

callMethod · 0.95
visualizeFunction · 0.45
inline_graphFunction · 0.45
add_nodeFunction · 0.45
parseFunction · 0.45
load_graph_and_inputsFunction · 0.45
serialize_modelMethod · 0.45
add_list_constructMethod · 0.45
add_tuple_constructMethod · 0.45
add_pool2d_nodeMethod · 0.45
add_avg_pool2dMethod · 0.45

Calls 2

listFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected