Skip to content

Commit 98cb4dc

Browse files
committed
comment changes
remove unnecesary print remove unnecesary FX metatype Registry pre commit fix
1 parent 7ed1617 commit 98cb4dc

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

nncf/common/graph/operator_metatypes.py

+11
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ def wrap(obj: Type[OperatorMetatype]) -> Type[OperatorMetatype]:
111111
)
112112
raise nncf.InternalError(msg)
113113
self._op_name_to_op_meta_dict[name] = obj
114+
if hasattr(obj, "module_to_function_names"):
115+
for namespace, function_names in obj.module_to_function_names.items():
116+
for function_name in function_names:
117+
target_function_name = f"{namespace.value}.{function_name}"
118+
if target_function_name in self._func_name_to_op_meta_dict:
119+
msg = (
120+
"Inconsistent operator metatype registry - single patched "
121+
f"op name `{target_function_name}` maps to multiple metatypes!"
122+
)
123+
raise nncf.InternalError(msg)
124+
self._func_name_to_op_meta_dict[target_function_name] = obj
114125
return obj
115126

116127
return wrap

nncf/experimental/torch/fx/nncf_graph_builder.py

+2-18
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,6 @@ def _get_layer_attributes(
6565
)
6666
return None
6767

68-
def _map_fx_unique_metatypes(node: torch.fx.Node, metatype: om.OperatorMetatype) -> om.OperatorMetatype:
69-
"""
70-
Attempts to retrieve correct subtype for the given node.
71-
72-
:param node: Given node.
73-
:param metatype: Given node metatype.
74-
:param model: Target GraphModule instance.
75-
:return: Correct FX metatype of the given node if it is exist or the original node metatype otherwise.
76-
"""
77-
if metatype in [om.PTEmbeddingMetatype]:
78-
weight_node = node.args[0]
79-
if weight_node.op == "get_attr":
80-
return om.PTAtenEmbeddingMetatype
81-
82-
return metatype
83-
8468
@staticmethod
8569
def get_node_type_and_metatype(node: torch.fx.Node, model: torch.fx.GraphModule) -> Tuple[str, om.OperatorMetatype]:
8670
"""
@@ -118,7 +102,8 @@ def get_node_type_and_metatype(node: torch.fx.Node, model: torch.fx.GraphModule)
118102
layer_attrs = GraphConverter._get_layer_attributes(node, node_metatype, model)
119103
node_subtype = node_metatype.determine_subtype(layer_attrs)
120104
node_metatype = node_subtype or node_metatype
121-
return node_type, node_metatype
105+
node_type_name = node_type_name or node_type
106+
return node_type_name, node_metatype
122107

123108
@staticmethod
124109
def create_nncf_graph(model: torch.fx.GraphModule) -> PTNNCFGraph:
@@ -135,7 +120,6 @@ def create_nncf_graph(model: torch.fx.GraphModule) -> PTNNCFGraph:
135120
const_targets_counter = Counter([node.target for node in model.graph.nodes if node.op == "get_attr"])
136121
for source_node in model.graph.nodes:
137122
node_type, node_metatype = GraphConverter.get_node_type_and_metatype(source_node, model)
138-
node_metatype = GraphConverter._map_fx_unique_metatypes(source_node, node_metatype)
139123
is_shared_node = source_node.op in ("get_attr",) and (
140124
const_targets_counter[source_node.target] > 1 or len(source_node.users) > 1
141125
)

nncf/torch/graph/operator_metatypes.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
ModuleAttributes = TypeVar("ModuleAttributes", bound=BaseLayerAttributes)
2929

3030
PT_OPERATOR_METATYPES = OperatorMetatypeRegistry("operator_metatypes")
31-
FX_OPERATOR_METATYPES = OperatorMetatypeRegistry("operator_metatypes")
3231

3332

3433
class PTOperatorMetatype(OperatorMetatype):
@@ -926,9 +925,9 @@ class PTEmbeddingMetatype(PTOperatorMetatype):
926925
weight_port_ids = [1]
927926

928927

929-
@FX_OPERATOR_METATYPES.register()
928+
@PT_OPERATOR_METATYPES.register()
930929
class PTAtenEmbeddingMetatype(OperatorMetatype):
931-
name = "EmbeddingOp"
930+
name = "AtenEmbeddingOp"
932931
module_to_function_names = {NamespaceTarget.ATEN: ["embedding"]}
933932
hw_config_names = [HWConfigOpName.EMBEDDING]
934933
weight_port_ids = [0]

0 commit comments

Comments
 (0)