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

Function get_const_node

backends/qualcomm/_passes/utils.py:302–321  ·  view source on GitHub ↗

Register a scalar constant as a named buffer on the graph module and return a get_attr node referencing it. Used in edge dialect op decomposition passes where raw scalar arguments are not accepted by QNN op builders which need the inputs to be graph nodes.

(
    graph: torch.fx.Graph,
    graph_module: torch.fx.GraphModule,
    attr_name: str,
    value,
    source_node: torch.fx.Node,
)

Source from the content-addressed store, hash-verified

300
301
302def get_const_node(
303 graph: torch.fx.Graph,
304 graph_module: torch.fx.GraphModule,
305 attr_name: str,
306 value,
307 source_node: torch.fx.Node,
308) -> torch.fx.Node:
309 """
310 Register a scalar constant as a named buffer on the graph module and return a get_attr node referencing it.
311 Used in edge dialect op decomposition passes where raw scalar arguments are not accepted by QNN op builders which need the inputs to be graph nodes.
312 """
313 dtype = source_node.meta["val"].dtype
314 tensor = torch.tensor(value, dtype=dtype)
315 graph_module.register_buffer(attr_name, tensor)
316
317 fake_mode = source_node.meta["val"].fake_mode
318 with graph.inserting_before(next(iter(graph.nodes))):
319 const_node = graph.get_attr(attr_name)
320 const_node.meta["val"] = fake_mode.from_tensor(tensor)
321 return const_node
322
323
324def create_node(graph, target, args, meta, callback=None):

Callers 5

callMethod · 0.85
_decompose_log_nMethod · 0.85
_decompose_log_pMethod · 0.85
make_constMethod · 0.85
callMethod · 0.85

Calls 4

register_bufferMethod · 0.80
inserting_beforeMethod · 0.80
get_attrMethod · 0.45
from_tensorMethod · 0.45

Tested by

no test coverage detected