Skip to content

Commit b76433a

Browse files
committed
[quant] Fix fx quant ptq static tutorial
1 parent 25ece55 commit b76433a

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
@@ -320,6 +320,7 @@ The purpose for calibration is to run through some sample examples that is repre
320320
the statistics of the Tensors and we can later use this information to calculate quantization parameters.
321321

322322
.. code:: python
323+
323324
def calibrate(model, data_loader):
324325
model.eval()
325326
with torch.no_grad():
@@ -329,17 +330,19 @@ the statistics of the Tensors and we can later use this information to calculate
329330
330331
7. Convert the Model to a Quantized Model
331332
-----------------------------------------
332-
``convert_fx`` takes a calibrated model and produces a quantized model.
333+
``convert_fx`` takes a calibrated model and produces a quantized model.
333334

334335
.. code:: python
335-
quantized_model = convert_fx(prepared_model)
336+
337+
quantized_model = convert_fx(prepared_model)
336338
print(quantized_model)
337-
339+
338340
8. Evaluation
339341
-------------
340342
We can now print the size and accuracy of the quantized model.
341343

342344
.. code:: python
345+
343346
print("Size of model before quantization")
344347
print_size_of_model(float_model)
345348
print("Size of model after quantization")
@@ -381,6 +384,7 @@ we'll first call fuse explicitly to fuse the conv and bn in the model:
381384
Note that ``fuse_fx`` only works in eval mode.
382385

383386
.. code:: python
387+
384388
fused = fuse_fx(float_model)
385389
386390
conv1_weight_after_fuse = fused.conv1[0].weight[0]
@@ -392,6 +396,7 @@ Note that ``fuse_fx`` only works in eval mode.
392396
--------------------------------------------------------------------
393397

394398
.. code:: python
399+
395400
scripted_float_model_file = "resnet18_scripted.pth"
396401
397402
print("Size of baseline model")
@@ -406,6 +411,7 @@ quantized in eager mode. FX graph mode and eager mode produce very similar quant
406411
so the expectation is that the accuracy and speedup are similar as well.
407412

408413
.. code:: python
414+
409415
print("Size of Fx graph mode quantized model")
410416
print_size_of_model(quantized_model)
411417
top1, top5 = evaluate(quantized_model, criterion, data_loader_test)

0 commit comments

Comments
 (0)