|
47 | 47 | from .utils import print_ops_info |
48 | 48 |
|
49 | 49 |
|
| 50 | +default_quantizer = CadenceDefaultQuantizer() |
| 51 | + |
| 52 | + |
| 53 | +# Note: this is not meant as a primary API since it can create inconsistencies |
| 54 | +# if the quantizer here is different from the quantizer used to convert. It is |
| 55 | +# however useful for unit tests to separate the converted model from the fused |
| 56 | +# model, to be able to get reference numerics. |
| 57 | +# If this does not apply, please use quantize_and_fuse_pt2 instead. |
50 | 58 | def prepare_and_convert_pt2( |
51 | 59 | model: torch.nn.Module, |
52 | 60 | inputs: tuple[object, ...], |
@@ -245,6 +253,28 @@ def export_to_edge( |
245 | 253 | return edge_prog_manager |
246 | 254 |
|
247 | 255 |
|
| 256 | +def quantize_and_export_to_edge( |
| 257 | + model: torch.nn.Module, |
| 258 | + inputs: tuple[object, ...], |
| 259 | + quantizer: Optional[CadenceQuantizer] = None, |
| 260 | + dump_graphs: bool = False, |
| 261 | + constant_methods: Optional[dict[str, object]] = None, |
| 262 | +) -> EdgeProgramManager: |
| 263 | + quantized_model = quantize_pt2( |
| 264 | + model, |
| 265 | + inputs, |
| 266 | + quantizer=quantizer, |
| 267 | + dump_graphs=dump_graphs, |
| 268 | + ) |
| 269 | + |
| 270 | + return export_to_edge( |
| 271 | + quantized_model, |
| 272 | + inputs, |
| 273 | + dump_graphs=dump_graphs, |
| 274 | + constant_methods=constant_methods, |
| 275 | + ) |
| 276 | + |
| 277 | + |
248 | 278 | def export_to_cadence( |
249 | 279 | model: torch.nn.Module, |
250 | 280 | inputs: tuple[object, ...], |
|
0 commit comments