Skip to content

Commit 8c28aa2

Browse files
Comments
1 parent 98c2cbd commit 8c28aa2

File tree

10 files changed

+6171
-6069
lines changed

10 files changed

+6171
-6069
lines changed

nncf/experimental/torch/fx/quantization/quantizer/torch_ao_adapter.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ def _get_node_args(node: torch.fx.Node) -> tuple[Any, ...]:
117117

118118
@staticmethod
119119
def get_quantizer_config_from_annotated_model(annotated: torch.fx.GraphModule) -> SingleConfigQuantizerSetup:
120+
"""
121+
Process a torch.fx.GraphModule annotated with quantization specifications
122+
(e.g., via torch.ao observers) and generates a corresponding NNCF quantization setup object,
123+
which maps quantization configurations to graph edges.
124+
125+
:param annotated: A torch.fx.GraphModule that has been annotated with Torch quantization observers.
126+
:return: A SingleConfigQuantizerSetup containing quantization points derived from the annotated model.
127+
"""
120128
edge_or_node_to_qspec = _get_edge_or_node_to_qspec(annotated)
121129
# Node means all output edges should be quantized.
122130
# Edge means only one edge should be quantized.
@@ -127,9 +135,7 @@ def get_quantizer_config_from_annotated_model(annotated: torch.fx.GraphModule) -
127135
for edge_or_node, group_id in edge_or_node_to_group_id.items():
128136
target_edges = [edge_or_node]
129137
if isinstance(edge_or_node, torch.fx.Node):
130-
target_edges = []
131-
for user in edge_or_node.users:
132-
target_edges.append((edge_or_node, user))
138+
target_edges = [(edge_or_node, user) for user in edge_or_node.users]
133139
group_id_vs_edges[group_id].update(target_edges)
134140
# All qspecs should be aligned after the _get_edge_or_node_to_group_id call
135141
group_id_vs_qspec[group_id] = _unwrap_shared_qspec_safe(

tests/torch/data/reference_graphs/fx/experimental/XNNPACKQuantizer/swin_v2_t.dot

Lines changed: 0 additions & 3806 deletions
This file was deleted.

tests/torch/data/reference_graphs/fx/experimental/XNNPACKQuantizer/vit_b_16.dot

Lines changed: 0 additions & 2071 deletions
This file was deleted.

tests/torch2/data/fx/XNNPACKQuantizer/swin_v2_t.dot

Lines changed: 3866 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 221 additions & 189 deletions
Large diffs are not rendered by default.

tests/torch2/data/fx/XNNPACKQuantizer/vit_b_16.dot

Lines changed: 2075 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)