File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ def apply_quantization_config(
154
154
):
155
155
# mark modules to be quantized by adding
156
156
# quant scheme to the matching layers
157
- matched_targets = list ( match_targets (name , submodule , target_to_scheme ) )
157
+ matched_targets = match_targets (name , submodule , target_to_scheme )
158
158
scheme = _scheme_from_targets (target_to_scheme , matched_targets , name )
159
159
if run_compressed :
160
160
format = config .format
Original file line number Diff line number Diff line change @@ -117,19 +117,25 @@ def match_named_parameters(
117
117
118
118
def match_targets (
119
119
name : str , module : torch .nn .Module , targets : Iterable [str ]
120
- ) -> Generator [str ]:
120
+ ) -> List [str ]:
121
121
"""
122
- Yields the targets that match the given name and module.
122
+ Returns the targets that match the given name and module.
123
123
Outputs are ordered by type: exact name match, regex name match, class name match
124
124
"""
125
+ if isinstance (module , InternalModule ):
126
+ return []
127
+
125
128
targets = sorted (targets , key = lambda x : ("re:" in x , x ))
129
+ matched_targets = []
126
130
for target in targets :
127
131
if _match_name (name , target ):
128
- yield target
132
+ matched_targets . append ( target )
129
133
130
134
for target in targets :
131
- if _match_class (module , target ):
132
- yield target
135
+ if _match_class (module , target ) and target not in matched_targets :
136
+ matched_targets .append (target )
137
+
138
+ return matched_targets
133
139
134
140
135
141
def match_modules_set (
You can’t perform that action at this time.
0 commit comments