Skip to content

Commit 5b04add

Browse files
committed
fix link check and failed to get source partition
1 parent eaf8aa6 commit 5b04add

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

examples/qualcomm/custom_op/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This folder contains examples demonstrating how to register custom operators int
88

99
- Please finish tutorial [Setting up executorch](https://pytorch.org/executorch/stable/getting-started-setup).
1010

11-
- Please finish [setup QNN backend](../../docs/source/build-run-qualcomm-ai-engine-direct-backend.md).
11+
- Please finish [setup QNN backend](../../../docs/source/backends-qualcomm.md).
1212

1313
- Please follow [the instructions to install proper version of Hexagon SDK and Hexagon Tools.](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/linux_setup.html#htp-and-dsp)
1414
- This example is verified with SM8650 (Snapdragon 8 Gen 3).

examples/qualcomm/custom_op/custom_ops_1.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ def annotate_custom(gm: torch.fx.GraphModule) -> None:
6868
This function is specific for custom op.
6969
The source_fn of the rewritten nn module turns out to be "my_ops.mul3.default"
7070
"""
71-
import itertools
72-
7371
from executorch.backends.qualcomm.quantizer.annotators import (
7472
_is_annotated,
7573
QUANT_ANNOTATION_KEY,
@@ -80,31 +78,23 @@ def annotate_custom(gm: torch.fx.GraphModule) -> None:
8078
)
8179
from torch.ao.quantization.quantize_pt2e import QuantizationAnnotation
8280
from torch.fx import Node
83-
from torch.fx.passes.utils.source_matcher_utils import get_source_partitions
8481

85-
custom_partitions = get_source_partitions(gm.graph, [torch.ops.my_ops.mul3.default])
86-
custom_partitions = list(itertools.chain(*custom_partitions.values()))
8782
quantization_config = get_ptq_per_channel_quant_config()
88-
for custom_partition in custom_partitions:
89-
if len(custom_partition.output_nodes) > 1:
90-
raise ValueError("custom partition has more than one output node")
91-
custom_node = custom_partition.output_nodes[0]
92-
if (
93-
custom_node.op != "call_function"
94-
or custom_node.target != torch.ops.my_ops.mul3.default
95-
):
96-
raise ValueError(f"{custom_node} is not a custom operator")
83+
for node in gm.graph.nodes:
84+
if node.target != torch.ops.my_ops.mul3.default:
85+
continue
86+
9787
# skip annotation if it is already annotated
98-
if _is_annotated([custom_node]):
88+
if _is_annotated([node]):
9989
continue
10090

10191
input_qspec_map = {}
102-
input_act = custom_node.args[0]
92+
input_act = node.args[0]
10393
assert isinstance(input_act, Node)
10494
input_spec = quantization_config.input_activation
10595
input_qspec_map[input_act] = input_spec
10696

107-
custom_node.meta[QUANT_ANNOTATION_KEY] = QuantizationAnnotation(
97+
node.meta[QUANT_ANNOTATION_KEY] = QuantizationAnnotation(
10898
input_qspec_map=input_qspec_map,
10999
output_qspec=quantization_config.output_activation,
110100
_annotated=True,

0 commit comments

Comments
 (0)