Skip to content

Commit 86b26ec

Browse files
committed
Update on "[quant][graphmode] Support quantization for aten::apend"
Summary: `aten::append` modifies input inplace and the output is ignored, these ops are not supported right now, so we'll need to first make `aten::append` non-inplace by change ``` ignored = aten::append(list, x) ``` to ``` x_list = aten::ListConstruct(x) result = aten::add(list, x_list) ``` and then quantize the aten::add instead. Test Plan: TestQuantizeJitOps.test_general_shape_ops Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D22302151](https://our.internmc.facebook.com/intern/diff/D22302151) [ghstack-poisoned]
2 parents 9451edb + 2f47e95 commit 86b26ec

File tree

9 files changed

+200
-159
lines changed

9 files changed

+200
-159
lines changed

.circleci/scripts/python_doc_push_script.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ sudo apt-get -y install expect-dev
77
# This is where the local pytorch install in the docker image is located
88
pt_checkout="/var/lib/jenkins/workspace"
99

10+
source "$pt_checkout/.jenkins/pytorch/common_utils.sh"
11+
1012
echo "python_doc_push_script.sh: Invoked with $*"
1113

1214
set -ex
@@ -59,12 +61,7 @@ pip install -q https://s3.amazonaws.com/ossci-linux/wheels/tensorboard-1.14.0a0-
5961

6062
# Get all the documentation sources, put them in one place
6163
pushd "$pt_checkout"
62-
git clone https://github.com/pytorch/vision
63-
pushd vision
64-
git checkout c2e8a00885e68ae1200eb6440f540e181d9125de
65-
conda install -q pillow
66-
time python setup.py install
67-
popd
64+
checkout_install_torchvision
6865
pushd docs
6966
rm -rf source/torchvision
7067
cp -a ../vision/docs/source source/torchvision

.jenkins/pytorch/common.sh

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
#!/bin/bash
22

33
# Common setup for all Jenkins scripts
4-
5-
# NB: define this function before set -x, so that we don't
6-
# pollute the log with a premature EXITED_USER_LAND ;)
7-
function cleanup {
8-
# Note that if you've exited user land, then CI will conclude that
9-
# any failure is the CI's fault. So we MUST only output this
10-
# string
11-
retcode=$?
12-
set +x
13-
if [ $retcode -eq 0 ]; then
14-
echo "EXITED_USER_LAND"
15-
fi
16-
}
17-
4+
source "$(dirname "${BASH_SOURCE[0]}")/common_utils.sh"
185
set -ex
196

207
# Save the SCRIPT_DIR absolute path in case later we chdir (as occurs in the gpu perf test)
@@ -77,20 +64,6 @@ declare -f -t trap_add
7764
7865
trap_add cleanup EXIT
7966
80-
function assert_git_not_dirty() {
81-
# TODO: we should add an option to `build_amd.py` that reverts the repo to
82-
# an unmodified state.
83-
if ([[ "$BUILD_ENVIRONMENT" != *rocm* ]] && [[ "$BUILD_ENVIRONMENT" != *xla* ]]) ; then
84-
git_status=$(git status --porcelain)
85-
if [[ $git_status ]]; then
86-
echo "Build left local git repository checkout dirty"
87-
echo "git status --porcelain:"
88-
echo "${git_status}"
89-
exit 1
90-
fi
91-
fi
92-
}
93-
9467
if [[ "$BUILD_ENVIRONMENT" != *pytorch-win-* ]]; then
9568
if which sccache > /dev/null; then
9669
# Save sccache logs to file
@@ -158,43 +131,7 @@ if [[ "$BUILD_ENVIRONMENT" == *pytorch-xla-linux-bionic* ]] || \
158131
fi
159132
fi
160133
161-
function pip_install() {
162-
# retry 3 times
163-
# old versions of pip don't have the "--progress-bar" flag
164-
pip install --progress-bar off "$@" || pip install --progress-bar off "$@" || pip install --progress-bar off "$@" ||\
165-
pip install "$@" || pip install "$@" || pip install "$@"
166-
}
167-
168-
function pip_uninstall() {
169-
# uninstall 2 times
170-
pip uninstall -y "$@" || pip uninstall -y "$@"
171-
}
172-
173134
retry () {
174135
$* || (sleep 1 && $*) || (sleep 2 && $*)
175136
}
176137
177-
function get_exit_code() {
178-
set +e
179-
"$@"
180-
retcode=$?
181-
set -e
182-
return $retcode
183-
}
184-
185-
function file_diff_from_base() {
186-
# The fetch may fail on Docker hosts, but it's not always necessary.
187-
set +e
188-
git fetch origin master --quiet
189-
set -e
190-
git diff --name-only "$(git merge-base origin/master HEAD)" > "$1"
191-
}
192-
193-
function get_bazel() {
194-
# download bazel version
195-
wget https://github.com/bazelbuild/bazel/releases/download/3.1.0/bazel-3.1.0-linux-x86_64 -O tools/bazel
196-
# verify content
197-
echo '753434f4fa730266cf5ce21d1fdd425e1e167dd9347ad3e8adc19e8c0d54edca tools/bazel' | sha256sum --quiet -c
198-
199-
chmod +x tools/bazel
200-
}

.jenkins/pytorch/common_utils.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
# Common util **functions** that can be sourced in other scripts.
4+
5+
# NB: define this function before set -x, so that we don't
6+
# pollute the log with a premature EXITED_USER_LAND ;)
7+
function cleanup {
8+
# Note that if you've exited user land, then CI will conclude that
9+
# any failure is the CI's fault. So we MUST only output this
10+
# string
11+
retcode=$?
12+
set +x
13+
if [ $retcode -eq 0 ]; then
14+
echo "EXITED_USER_LAND"
15+
fi
16+
}
17+
18+
function assert_git_not_dirty() {
19+
# TODO: we should add an option to `build_amd.py` that reverts the repo to
20+
# an unmodified state.
21+
if ([[ "$BUILD_ENVIRONMENT" != *rocm* ]] && [[ "$BUILD_ENVIRONMENT" != *xla* ]]) ; then
22+
git_status=$(git status --porcelain)
23+
if [[ $git_status ]]; then
24+
echo "Build left local git repository checkout dirty"
25+
echo "git status --porcelain:"
26+
echo "${git_status}"
27+
exit 1
28+
fi
29+
fi
30+
}
31+
32+
function pip_install() {
33+
# retry 3 times
34+
# old versions of pip don't have the "--progress-bar" flag
35+
pip install --progress-bar off "$@" || pip install --progress-bar off "$@" || pip install --progress-bar off "$@" ||\
36+
pip install "$@" || pip install "$@" || pip install "$@"
37+
}
38+
39+
function pip_uninstall() {
40+
# uninstall 2 times
41+
pip uninstall -y "$@" || pip uninstall -y "$@"
42+
}
43+
44+
function get_exit_code() {
45+
set +e
46+
"$@"
47+
retcode=$?
48+
set -e
49+
return $retcode
50+
}
51+
52+
function file_diff_from_base() {
53+
# The fetch may fail on Docker hosts, but it's not always necessary.
54+
set +e
55+
git fetch origin master --quiet
56+
set -e
57+
git diff --name-only "$(git merge-base origin/master HEAD)" > "$1"
58+
}
59+
60+
function get_bazel() {
61+
# download bazel version
62+
wget https://github.com/bazelbuild/bazel/releases/download/3.1.0/bazel-3.1.0-linux-x86_64 -O tools/bazel
63+
# verify content
64+
echo '753434f4fa730266cf5ce21d1fdd425e1e167dd9347ad3e8adc19e8c0d54edca tools/bazel' | sha256sum --quiet -c
65+
66+
chmod +x tools/bazel
67+
}
68+
69+
TORCHVISION_COMMIT=c2e8a00885e68ae1200eb6440f540e181d9125de
70+
71+
function install_torchvision() {
72+
# Check out torch/vision at Jun 11 2020 commit
73+
# This hash must match one in .jenkins/caffe2/test.sh
74+
pip_install --user "git+https://github.com/pytorch/vision.git@$TORCHVISION_COMMIT"
75+
}
76+
77+
function checkout_install_torchvision() {
78+
git clone https://github.com/pytorch/vision
79+
pushd vision
80+
git checkout "$TORCHVISION_COMMIT"
81+
time python setup.py install
82+
popd
83+
}

.jenkins/pytorch/test.sh

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,6 @@ if [[ "${BUILD_ENVIRONMENT}" == *tbb* ]]; then
204204
sudo cp -r $PWD/third_party/tbb/include/tbb/* /usr/include/tbb
205205
fi
206206

207-
test_torchvision() {
208-
# Check out torch/vision at Jun 11 2020 commit
209-
# This hash must match one in .jenkins/caffe2/test.sh
210-
pip_install --user git+https://github.com/pytorch/vision.git@c2e8a00885e68ae1200eb6440f540e181d9125de
211-
}
212-
213207
test_libtorch() {
214208
if [[ "$BUILD_ENVIRONMENT" != *rocm* ]]; then
215209
echo "Testing libtorch"
@@ -319,7 +313,7 @@ if [[ "${BUILD_ENVIRONMENT}" == *backward* ]]; then
319313
test_backward_compatibility
320314
# Do NOT add tests after bc check tests, see its comment.
321315
elif [[ "${BUILD_ENVIRONMENT}" == *xla* || "${JOB_BASE_NAME}" == *xla* ]]; then
322-
test_torchvision
316+
install_torchvision
323317
test_xla
324318
elif [[ "${BUILD_ENVIRONMENT}" == *ge_config_legacy* || "${JOB_BASE_NAME}" == *ge_config_legacy* ]]; then
325319
test_python_ge_config_legacy
@@ -332,7 +326,7 @@ elif [[ "${BUILD_ENVIRONMENT}" == *-test1 || "${JOB_BASE_NAME}" == *-test1 ]]; t
332326
test_python_nn
333327
test_cpp_extensions
334328
elif [[ "${BUILD_ENVIRONMENT}" == *-test2 || "${JOB_BASE_NAME}" == *-test2 ]]; then
335-
test_torchvision
329+
install_torchvision
336330
test_python_all_except_nn_and_cpp_extensions
337331
test_aten
338332
test_libtorch
@@ -341,11 +335,11 @@ elif [[ "${BUILD_ENVIRONMENT}" == *-test2 || "${JOB_BASE_NAME}" == *-test2 ]]; t
341335
elif [[ "${BUILD_ENVIRONMENT}" == *-bazel-* ]]; then
342336
test_bazel
343337
elif [[ "${BUILD_ENVIRONMENT}" == pytorch-linux-xenial-cuda9.2-cudnn7-py3-gcc5.4* ]]; then
344-
# test cpp extension for xenial + cuda 9.2 + gcc 5.4 to make sure
345-
# cpp extension can be built correctly under this old env
338+
# test cpp extension for xenial + cuda 9.2 + gcc 5.4 to make sure
339+
# cpp extension can be built correctly under this old env
346340
test_cpp_extensions
347341
else
348-
test_torchvision
342+
install_torchvision
349343
test_python_nn
350344
test_python_all_except_nn_and_cpp_extensions
351345
test_cpp_extensions

test/quantization/test_quantize_jit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,15 +2340,15 @@ def forward(self, x):
23402340
FileCheck().check_count("aten::quantize_per_tensor", 1, exactly=True) \
23412341
.run(m.graph)
23422342

2343-
FileCheck().check_count("quantized::conv2d", 2, exactly=True) \
2343+
FileCheck().check_count("quantized::conv2d(", 2, exactly=True) \
23442344
.run(m.graph)
23452345

23462346
FileCheck().check_count("aten::dequantize", 1, exactly=True) \
23472347
.run(m.graph)
23482348

23492349
FileCheck().check("quantized::add_scalar") \
23502350
.check("quantized::mul_scalar") \
2351-
.check("aten::append") \
2351+
.check("aten::append(") \
23522352
.run(m.graph)
23532353

23542354
def test_general_value_ops(self):

tools/pyi/gen_pyi.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,11 @@ def gen_pyi(declarations_path, out):
460460
.format(FACTORY_PARAMS),
461461
'def arange(end: Number, *, out: Optional[Tensor]=None, {}) -> Tensor: ...'
462462
.format(FACTORY_PARAMS)],
463-
'randint': ['def randint(low: _int, high: _int, size: _size, *, {}) -> Tensor: ...'
463+
'randint': ['def randint(low: _int, high: _int, size: _size, *,'
464+
' generator: Optional[Generator]=None, {}) -> Tensor: ...'
464465
.format(FACTORY_PARAMS),
465-
'def randint(high: _int, size: _size, *, {}) -> Tensor: ...'
466+
'def randint(high: _int, size: _size, *,'
467+
' generator: Optional[Generator]=None, {}) -> Tensor: ...'
466468
.format(FACTORY_PARAMS)],
467469
'full': ['def full(size: _size, fill_value: Number, *,'
468470
' out: Optional[Tensor]=None, {}) -> Tensor: ...'

torch/autograd/grad_mode.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ class no_grad(_DecoratorContextManager):
4040
In this mode, the result of every computation will have
4141
`requires_grad=False`, even when the inputs have `requires_grad=True`.
4242
43-
This mode has no effect when using :class:`~enable_grad` context manager .
44-
4543
This context manager is thread local; it will not affect computation
4644
in other threads.
4745
@@ -115,9 +113,6 @@ class set_grad_enabled(object):
115113
``set_grad_enabled`` will enable or disable grads based on its argument :attr:`mode`.
116114
It can be used as a context-manager or as a function.
117115
118-
When using :class:`~enable_grad` context manager, :class:`~set_grad_enabled(False)`
119-
has no effect.
120-
121116
This context manager is thread local; it will not affect computation
122117
in other threads.
123118

0 commit comments

Comments
 (0)