54
54
# if the quantizer here is different from the quantizer used to convert. It is
55
55
# however useful for unit tests to separate the converted model from the fused
56
56
# model, to be able to get reference numerics.
57
- # If this does not apply, please use quantize_and_fuse_pt2 instead.
57
+ # If this does not apply, please use quantize_pt2 instead.
58
58
def trace (
59
59
model : torch .nn .Module ,
60
60
inputs : tuple [object , ...],
@@ -85,6 +85,29 @@ def trace(
85
85
86
86
87
87
def prepare_pt2 (
88
+ model : torch .nn .Module ,
89
+ inputs : tuple [object , ...],
90
+ quantizer : CadenceQuantizer ,
91
+ dump_graphs : bool = False ,
92
+ ) -> torch .fx .GraphModule :
93
+ """
94
+ Trace and Prepare a model using the given quantizer.
95
+ The quantizer must be supplied and be the same as the one used to
96
+ fuse the model later, if applicable. If you do not expect that behavior,
97
+ please use quantize_pt2 instead, which will instantiate a
98
+ default quantizer for you if needed.
99
+ Returns a GraphModule with the prepared model.
100
+ """
101
+
102
+ traced_program = trace (model , inputs , dump_graphs = dump_graphs )
103
+ prepared_program = prepare_traced_pt2 (
104
+ traced_program , quantizer , dump_graphs = dump_graphs
105
+ )
106
+
107
+ return prepared_program
108
+
109
+
110
+ def prepare_traced_pt2 (
88
111
program : ExportedProgram ,
89
112
quantizer : CadenceQuantizer ,
90
113
dump_graphs : bool = False ,
@@ -93,7 +116,7 @@ def prepare_pt2(
93
116
Prepare a model using the given quantizer.
94
117
The quantizer must be supplied and be the same as the one used to
95
118
fuse the model later, if applicable. If you do not expect that behavior,
96
- please use quantize_and_fuse_pt2 instead, which will instantiate a
119
+ please use quantize_pt2 instead, which will instantiate a
97
120
default quantizer for you if needed.
98
121
Returns a GraphModule with the prepared model.
99
122
"""
@@ -137,7 +160,7 @@ def fuse_pt2(
137
160
"""
138
161
Fuse a converted graph module using the given quantizer.
139
162
The quantizer must be the same as the one used to convert the model.
140
- If you do not expect that behavior, please use quantize_and_fuse_pt2 instead,
163
+ If you do not expect that behavior, please use quantize_pt2 instead,
141
164
which will instantiate a default quantizer for you if needed.
142
165
Returns a GraphModule with the fused model.
143
166
"""
@@ -179,7 +202,7 @@ def quantize_pt2(
179
202
logging .info (program .graph .print_tabular ())
180
203
181
204
# Get prepared graph module
182
- prepared_gm = prepare_pt2 (program , quantizer , dump_graphs = dump_graphs )
205
+ prepared_gm = prepare_pt2 (model , inputs , quantizer , dump_graphs = dump_graphs )
183
206
184
207
# Calibrate
185
208
# If no calibration data is provided, use the inputs
0 commit comments