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

Function _annotate_input

backends/arm/quantizer/quantization_annotator.py:332–368  ·  view source on GitHub ↗

Annotate a node's input with the given qspec. Maps the specified input argument(s) to the provided quantization spec and optionally marks the input node(s) as annotated. Args: node (Node): Node whose input should be annotated. quant_property (_QuantProperty): Input inde

(node: Node, quant_property: _QuantProperty)

Source from the content-addressed store, hash-verified

330
331
332def _annotate_input(node: Node, quant_property: _QuantProperty):
333 """Annotate a node's input with the given qspec.
334
335 Maps the specified input argument(s) to the provided quantization spec and
336 optionally marks the input node(s) as annotated.
337
338 Args:
339 node (Node): Node whose input should be annotated.
340 quant_property (_QuantProperty): Input index and qspec(s).
341
342 Raises:
343 RuntimeError: If the node is already annotated.
344 TypeError: If an input argument is not a ``Node`` instance.
345
346 """
347 if is_annotated(node):
348 raise RuntimeError(
349 f"Cannot annotate input: node '{node.name}' is already annotated"
350 )
351 if quant_property.optional and (
352 quant_property.index >= len(node.args)
353 or node.args[quant_property.index] is None
354 ):
355 return
356
357 for n_arg, qspec in zip(
358 _as_list(node.args[quant_property.index]),
359 _as_list(quant_property.qspec),
360 strict=True,
361 ):
362 if not isinstance(n_arg, Node):
363 raise TypeError(
364 f"n_arg must be a Node instance, got {type(n_arg).__name__!r}"
365 )
366 annotate_input_qspec_map(node, n_arg, qspec)
367 if quant_property.mark_annotated:
368 mark_node_as_annotated(n_arg) # type: ignore[attr-defined]
369
370
371def _annotate_output(node: Node, quant_property: _QuantProperty):

Callers 1

annotate_graphFunction · 0.85

Calls 3

_as_listFunction · 0.85
is_annotatedFunction · 0.70
mark_node_as_annotatedFunction · 0.70

Tested by

no test coverage detected