MCPcopy Create free account
hub / github.com/pytorch/executorch / get_shape

Function get_shape

backends/transforms/permute_pass_utils.py:41–56  ·  view source on GitHub ↗

Return the shape of the tensor corresponding to node.

(
    graph_module: torch.fx.GraphModule, node: torch.fx.Node
)

Source from the content-addressed store, hash-verified

39
40
41def get_shape(
42 graph_module: torch.fx.GraphModule, node: torch.fx.Node
43) -> Union[torch.Size, None]:
44 """Return the shape of the tensor corresponding to node."""
45 try:
46 if isinstance(node, (float, int, bool)):
47 return torch.Size([1])
48 fake_tensor = node.meta.get("val")
49 if fake_tensor is not None:
50 return fake_tensor.shape
51 if node.op == "get_attr":
52 attr_node = getattr(graph_module, node.target)
53 return attr_node.shape
54 return None
55 except RuntimeError:
56 return None
57
58
59def get_transposed_dims(

Callers 15

define_nodeMethod · 0.90
define_nodeMethod · 0.90
define_nodeMethod · 0.90
define_nodeMethod · 0.90
define_nodeMethod · 0.90
define_nodeMethod · 0.90
define_nodeMethod · 0.90
define_nodeMethod · 0.90
define_nodeMethod · 0.90
define_nodeMethod · 0.90
define_nodeMethod · 0.90

Calls 2

SizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected