@@ -95,7 +95,10 @@ def _is_ok_for_quantization(
95
95
continue
96
96
97
97
for n_arg in _as_list (node .args [quant_property .index ]):
98
- assert isinstance (n_arg , Node )
98
+ if not isinstance (n_arg , Node ):
99
+ raise TypeError (
100
+ f"n_arg must be a Node instance, got { type (n_arg ).__name__ !r} "
101
+ )
99
102
if not is_ok_for_quantization (n_arg , gm ): # type: ignore[attr-defined]
100
103
logger .debug (
101
104
f'could not quantize node due to input "{ node } ": '
@@ -108,7 +111,10 @@ def _is_ok_for_quantization(
108
111
109
112
110
113
def _annotate_input (node : Node , quant_property : _QuantProperty ):
111
- assert not is_annotated (node )
114
+ if is_annotated (node ):
115
+ raise RuntimeError (
116
+ f"Cannot annotate input: node '{ node .name } ' is already annotated"
117
+ )
112
118
if quant_property .optional and (
113
119
quant_property .index >= len (node .args )
114
120
or node .args [quant_property .index ] is None
@@ -120,17 +126,28 @@ def _annotate_input(node: Node, quant_property: _QuantProperty):
120
126
_as_list (quant_property .qspec ),
121
127
strict = True ,
122
128
):
123
- assert isinstance (n_arg , Node )
129
+ if not isinstance (n_arg , Node ):
130
+ raise TypeError (
131
+ f"n_arg must be a Node instance, got { type (n_arg ).__name__ !r} "
132
+ )
124
133
annotate_input_qspec_map (node , n_arg , qspec )
125
134
if quant_property .mark_annotated :
126
135
mark_node_as_annotated (n_arg ) # type: ignore[attr-defined]
127
136
128
137
129
138
def _annotate_output (node : Node , quant_property : _QuantProperty ):
130
- assert not is_annotated (node )
131
- assert not quant_property .mark_annotated
132
- assert not quant_property .optional
133
- assert quant_property .index == 0 , "Only one output annotation supported currently"
139
+ if is_annotated (node ):
140
+ raise RuntimeError (
141
+ f"Cannot annotate output: node '{ node .name } ' is already annotated"
142
+ )
143
+ if quant_property .mark_annotated :
144
+ raise ValueError (
145
+ "quant_property.mark_annotated must be False for output annotation"
146
+ )
147
+ if quant_property .optional :
148
+ raise ValueError ("quant_property.optional must be False for output annotation" )
149
+ if quant_property .index != 0 :
150
+ raise ValueError ("Only one output annotation supported currently" )
134
151
135
152
annotate_output_qspec (node , quant_property .qspec )
136
153
@@ -145,7 +162,9 @@ def _match_pattern(
145
162
146
163
Each 'pattern' element is composed of a list of disjunctive nodes types.
147
164
"""
148
- assert len (pattern ) > 0 , "No pattern provided"
165
+ if len (pattern ) < 1 :
166
+ raise ValueError ("No pattern provided" )
167
+
149
168
if filter_fn is not None :
150
169
if not filter_fn (node ):
151
170
return False
@@ -417,8 +436,14 @@ def any_or_hardtanh_min_zero(n: Node):
417
436
torch .ops .aten .concatenate .default ,
418
437
torch .ops .aten .stack .default ,
419
438
):
420
- assert isinstance (node .args [0 ], list )
421
- assert len (node .args [0 ]) != 0
439
+ # first argument should be a non-empty list of nodes
440
+ if not isinstance (node .args [0 ], list ):
441
+ raise TypeError (
442
+ "Expected node.args[0] to be a list, got "
443
+ f"{ type (node .args [0 ]).__name__ !r} "
444
+ )
445
+ if len (node .args [0 ]) == 0 :
446
+ raise ValueError ("Expected non-empty list for node.args[0]" )
422
447
423
448
shared_qspec = SharedQuantizationSpec ((node .args [0 ][0 ], node ))
424
449
quant_properties .quant_inputs = [
0 commit comments