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

Function _annotate_linear

backends/vulkan/quantizer/vulkan_quantizer_utils.py:92–136  ·  view source on GitHub ↗
(
    gm: torch.fx.GraphModule,
    quantization_config: Optional[QuantizationConfig],
    filter_fn: Optional[Callable[[Node], bool]] = None,
)

Source from the content-addressed store, hash-verified

90
91@register_annotator("linear")
92def _annotate_linear(
93 gm: torch.fx.GraphModule,
94 quantization_config: Optional[QuantizationConfig],
95 filter_fn: Optional[Callable[[Node], bool]] = None,
96) -> Optional[list[list[Node]]]:
97 annotated_partitions = []
98 input_act_qspec = get_input_act_qspec(quantization_config)
99 output_act_qspec = get_output_act_qspec(quantization_config)
100 weight_qspec = get_weight_qspec(quantization_config)
101 bias_qspec = get_bias_qspec(quantization_config)
102 for node in gm.graph.nodes:
103 if node.op != "call_function" or node.target != torch.ops.aten.linear.default:
104 continue
105 if filter_fn and not filter_fn(node):
106 continue
107 act_node = node.args[0]
108 weight_node = node.args[1]
109 bias_node = None
110 if len(node.args) > 2:
111 bias_node = node.args[2]
112
113 if _is_annotated([node]) is False: # type: ignore[list-item]
114 annotate_input_qspec_map(
115 node,
116 act_node,
117 input_act_qspec,
118 )
119 annotate_input_qspec_map(
120 node,
121 weight_node,
122 weight_qspec,
123 )
124 nodes_to_mark_annotated = [node, weight_node]
125 if bias_node:
126 annotate_input_qspec_map(
127 node,
128 bias_node,
129 bias_qspec,
130 )
131 nodes_to_mark_annotated.append(bias_node)
132 annotate_output_qspec(node, output_act_qspec)
133 _mark_nodes_as_annotated(nodes_to_mark_annotated)
134 annotated_partitions.append(nodes_to_mark_annotated)
135
136 return annotated_partitions
137
138
139def _is_share_obs_or_fq_op(op: Callable[..., torch.Tensor]) -> bool:

Callers

nothing calls this directly

Calls 5

annotate_output_qspecFunction · 0.90
_is_annotatedFunction · 0.70
_mark_nodes_as_annotatedFunction · 0.70
filter_fnFunction · 0.50
appendMethod · 0.45

Tested by

no test coverage detected