You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix quantization tutorials (imports, syntax, and style) (#1772)
* Fix quantization tutorials (imports, syntax, and style)
Summary: This commit fixes the quantization tutorials such that
they can be run smoothly by the user.
Test Plan: Ran the updated tutorials without problem.
Reviewers: jerryzh168
Subscribers: jerryzh168, supriyar
ghstack-source-id: 196719d
Pull Request resolved: #1763
* Fix quantization tutorials (imports, syntax, and style)
Summary: This commit fixes the quantization tutorials such that
they can be run smoothly by the user.
Test Plan: Ran the updated tutorials without problem.
Reviewers: jerryzh168
Subscribers: jerryzh168, supriyar
ghstack-source-id: 196719d
Pull Request resolved: #1763
* revert paths for wikitext version
* Fix broken url
Co-authored-by: Jesse Cai <[email protected]>
Co-authored-by: Jesse Cai <[email protected]>
Copy file name to clipboardExpand all lines: prototype_source/fx_graph_mode_ptq_static.rst
+35-38
Original file line number
Diff line number
Diff line change
@@ -13,9 +13,8 @@ tldr; The FX Graph Mode API looks like the following:
13
13
.. code:: python
14
14
15
15
import torch
16
-
from torch.quantization import get_default_qconfig
17
-
# Note that this is temporary, we'll expose these functions to torch.quantization after official releasee
18
-
from torch.quantization.quantize_fx import prepare_fx, convert_fx
16
+
from torch.ao.quantization import get_default_qconfig
17
+
from torch.ao.quantization.quantize_fx import prepare_fx, convert_fx
19
18
float_model.eval()
20
19
qconfig = get_default_qconfig("fbgemm")
21
20
qconfig_dict = {"": qconfig}
@@ -58,24 +57,28 @@ These steps are identitcal to `Static Quantization with Eager Mode in PyTorch <h
58
57
59
58
To run the code in this tutorial using the entire ImageNet dataset, first download imagenet by following the instructions at here `ImageNet Data <http://www.image-net.org/download>`_. Unzip the downloaded file into the 'data_path' folder.
60
59
61
-
Download the `torchvision resnet18 model <https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py#L12>`_ and rename it to
60
+
Download the `torchvision resnet18 model <https://download.pytorch.org/models/resnet18-f37072fd.pth>`_ and rename it to
62
61
``data/resnet18_pretrained_float.pth``.
63
62
64
63
.. code:: python
65
64
66
-
import numpy as np
67
-
import torch
68
-
import torch.nn as nn
69
-
import torchvision
70
-
from torch.utils.data import DataLoader
71
-
from torchvision import datasets
72
-
import torchvision.transforms as transforms
73
-
import os
74
-
import time
75
-
import sys
76
-
import torch.quantization
77
-
78
-
# Setup warnings
65
+
import os
66
+
import sys
67
+
import time
68
+
import numpy as np
69
+
70
+
import torch
71
+
from torch.ao.quantization import get_default_qconfig
72
+
from torch.ao.quantization.quantize_fx import prepare_fx, convert_fx, fuse_fx
73
+
import torch.nn as nn
74
+
from torch.utils.data import DataLoader
75
+
76
+
import torchvision
77
+
from torchvision import datasets
78
+
from torchvision.models.resnet import resnet18
79
+
import torchvision.transforms as transforms
80
+
81
+
# Set up warnings
79
82
import warnings
80
83
warnings.filterwarnings(
81
84
action='ignore',
@@ -84,16 +87,13 @@ Download the `torchvision resnet18 model <https://github.com/pytorch/vision/blob
84
87
)
85
88
warnings.filterwarnings(
86
89
action='default',
87
-
module=r'torch.quantization'
90
+
module=r'torch.ao.quantization'
88
91
)
89
92
90
93
# Specify random seed for repeatable results
91
94
_ = torch.manual_seed(191009)
92
95
93
96
94
-
from torchvision.models.resnet import resnet18
95
-
from torch.quantization import get_default_qconfig, quantize_jit
96
-
97
97
classAverageMeter(object):
98
98
"""Computes and stores the average and current value"""
99
99
def__init__(self, name, fmt=':f'):
@@ -168,25 +168,22 @@ Download the `torchvision resnet18 model <https://github.com/pytorch/vision/blob
@@ -239,7 +236,7 @@ of the observers for activation and weight. ``qconfig_dict`` is a dictionary wit
239
236
.. code:: python
240
237
241
238
qconfig = {
242
-
" : qconfig_global,
239
+
"" : qconfig_global,
243
240
"sub" : qconfig_sub,
244
241
"sub.fc" : qconfig_fc,
245
242
"sub.conv": None
@@ -282,7 +279,7 @@ of the observers for activation and weight. ``qconfig_dict`` is a dictionary wit
282
279
]
283
280
}
284
281
285
-
Utility functions related to ``qconfig`` can be found in the `qconfig <https://github.com/pytorch/pytorch/blob/master/torch/quantization/qconfig.py>`_ file.
282
+
Utility functions related to ``qconfig`` can be found in the `qconfig <https://github.com/pytorch/pytorch/blob/master/torch/ao/quantization/qconfig.py>`_ file.
0 commit comments