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

Function create_node

backends/arm/_passes/arm_pass_utils.py:141–185  ·  view source on GitHub ↗

Adds a node to 'graph'. graph.inserting_before/after() should be used before the call to decide where to insert the node. If quantize is true and q_params is not None, a q dq pair is inserted after the newly created node.

(
    graph: torch.fx.Graph,
    op_target: OpOverload | EdgeOpOverload,
    args: tuple = (),
    kwargs: Optional[dict] = None,
    quantize: bool = False,
    q_params: Optional[tuple] = None,
    from_node: Optional[torch.fx.Node] = None,
    inherit_qparams: bool = False,
)

Source from the content-addressed store, hash-verified

139
140
141def create_node(
142 graph: torch.fx.Graph,
143 op_target: OpOverload | EdgeOpOverload,
144 args: tuple = (),
145 kwargs: Optional[dict] = None,
146 quantize: bool = False,
147 q_params: Optional[tuple] = None,
148 from_node: Optional[torch.fx.Node] = None,
149 inherit_qparams: bool = False,
150):
151 """Adds a node to 'graph'.
152
153 graph.inserting_before/after() should be used before the call to decide
154 where to insert the node. If quantize is true and q_params is not None, a q
155 dq pair is inserted after the newly created node.
156
157 """
158
159 node = graph.create_node(
160 "call_function",
161 op_target,
162 args=args,
163 kwargs=kwargs or {},
164 )
165
166 new_meta = {}
167 if from_node:
168 keys = from_node.meta.keys()
169 for key in keys:
170 new_meta[key] = from_node.meta[key]
171 if not inherit_qparams:
172 if "input_qparams" in new_meta:
173 new_meta["input_qparams"] = {}
174 if "output_qparams" in new_meta:
175 new_meta["output_qparams"] = {}
176 elif inherit_qparams:
177 raise ValueError("inherit_qparams is only valid when from_node is given")
178
179 old_stack_trace = new_meta.get("stack_trace", "")
180 new_meta["stack_trace"] = f"{old_stack_trace}\n{traceback.format_stack()[-2]}"
181 node.meta = new_meta
182
183 if quantize and q_params:
184 return insert_q_dq_pair(graph, node, q_params, from_node)
185 return node
186
187
188def create_shape_node(

Callers 15

callMethod · 0.90
callMethod · 0.90
callMethod · 0.90
callMethod · 0.90
_match_op_rankMethod · 0.90
callMethod · 0.90
callMethod · 0.90
fold_dq_q_to_rescaleMethod · 0.90
_rescale_inputsMethod · 0.90
_rescale_outputsMethod · 0.90
_insert_rescaleMethod · 0.90
callMethod · 0.90

Calls 4

insert_q_dq_pairFunction · 0.85
create_nodeMethod · 0.80
keysMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected