Skip to content

Commit

Permalink
No quantization annotation copy
Browse files Browse the repository at this point in the history
  • Loading branch information
daniil-lyakhov committed Jan 23, 2025
1 parent 9187faa commit a2abc2a
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions nncf/experimental/quantization/quantizers/openvino_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ def annotate(self, model: torch.fx.GraphModule) -> torch.fx.GraphModule:

graph = model.graph
node_vs_torch_annotation = defaultdict(TorchAOQuantizationAnnotation)

for qp in non_unified_quantization_points.values():
edge_or_node, annotation = self._get_edge_or_node_and_annotation(graph, qp, node_vs_torch_annotation)
qspec = self._get_torch_ao_qspec_from_qp(qp)
self._fill_torch_ao_annotation(edge_or_node, qspec, annotation)

for quantizer_ids in quantization_setup.unified_scale_groups.values():

root_quantizer_id = self._get_unified_scales_root_quantizer_id(
Expand All @@ -128,30 +134,20 @@ def annotate(self, model: torch.fx.GraphModule) -> torch.fx.GraphModule:
f"{[(qp.insertion_point.__dict__, str(qp.qconfig)) for qp in qps]}"
)

root_edge_or_node, annotation = self._get_edge_or_node_and_annotation(
graph, root_qp, node_vs_torch_annotation
)
qspec = self._get_torch_ao_qspec_from_qp(root_qp)
self._fill_torch_ao_annotation(root_edge_or_node, qspec, annotation)
root_target_node = get_graph_node_by_name(graph, root_qp.insertion_point.target_node_name)
root_edge_or_node = self._get_edge_or_node(root_target_node, root_qp)

while quantizer_ids:
quantizer_id = quantizer_ids.pop()
del non_unified_quantization_points[quantizer_id]

if quantizer_id == root_quantizer_id:
continue

qspec = TorchAOSharedQuantizationSpec(root_edge_or_node)
qp = quantization_setup.quantization_points[quantizer_id]
edge_or_node, annotation = self._get_edge_or_node_and_annotation(graph, qp, node_vs_torch_annotation)

self._fill_torch_ao_annotation(edge_or_node, qspec, annotation)

for qp in non_unified_quantization_points.values():
edge_or_node, annotation = self._get_edge_or_node_and_annotation(graph, qp, node_vs_torch_annotation)
qspec = self._get_torch_ao_qspec_from_qp(qp)
self._fill_torch_ao_annotation(edge_or_node, qspec, annotation)

for node, annotation in node_vs_torch_annotation.items():
assert QUANT_ANNOTATION_KEY not in node.meta
node.meta[QUANT_ANNOTATION_KEY] = annotation
Expand Down

0 comments on commit a2abc2a

Please sign in to comment.