Skip to content

Commit 7c6ff80

Browse files
jerryzh168brianjo
andauthored
[quant] Fix fx quant ptq static tutorial (#1457)
Co-authored-by: Brian Johnson <brianjo@fb.com>
1 parent 30d0f3a commit 7c6ff80

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

prototype_source/fx_graph_mode_ptq_static.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ The purpose for calibration is to run through some sample examples that is repre
311311
the statistics of the Tensors and we can later use this information to calculate quantization parameters.
312312

313313
.. code:: python
314+
314315
def calibrate(model, data_loader):
315316
model.eval()
316317
with torch.no_grad():
@@ -320,17 +321,19 @@ the statistics of the Tensors and we can later use this information to calculate
320321
321322
7. Convert the Model to a Quantized Model
322323
-----------------------------------------
323-
``convert_fx`` takes a calibrated model and produces a quantized model.
324+
``convert_fx`` takes a calibrated model and produces a quantized model.
324325

325326
.. code:: python
326-
quantized_model = convert_fx(prepared_model)
327+
328+
quantized_model = convert_fx(prepared_model)
327329
print(quantized_model)
328-
330+
329331
8. Evaluation
330332
-------------
331333
We can now print the size and accuracy of the quantized model.
332334

333335
.. code:: python
336+
334337
print("Size of model before quantization")
335338
print_size_of_model(float_model)
336339
print("Size of model after quantization")
@@ -372,6 +375,7 @@ we'll first call fuse explicitly to fuse the conv and bn in the model:
372375
Note that ``fuse_fx`` only works in eval mode.
373376

374377
.. code:: python
378+
375379
fused = fuse_fx(float_model)
376380
377381
conv1_weight_after_fuse = fused.conv1[0].weight[0]
@@ -383,6 +387,7 @@ Note that ``fuse_fx`` only works in eval mode.
383387
--------------------------------------------------------------------
384388

385389
.. code:: python
390+
386391
scripted_float_model_file = "resnet18_scripted.pth"
387392
388393
print("Size of baseline model")
@@ -397,6 +402,7 @@ quantized in eager mode. FX graph mode and eager mode produce very similar quant
397402
so the expectation is that the accuracy and speedup are similar as well.
398403

399404
.. code:: python
405+
400406
print("Size of Fx graph mode quantized model")
401407
print_size_of_model(quantized_model)
402408
top1, top5 = evaluate(quantized_model, criterion, data_loader_test)

0 commit comments

Comments
 (0)