Skip to content

Commit d861b33

Browse files
authored
Merge branch 'main' into references/optimizations
2 parents e699eca + f4b6687 commit d861b33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1760
-874
lines changed

.circleci/config.yml

Lines changed: 23 additions & 300 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.circleci/config.yml.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,27 @@ jobs:
254254
pip install --user pytest
255255
python test/test_onnx.py
256256

257+
prototype_test:
258+
docker:
259+
- image: circleci/python:3.7
260+
steps:
261+
- run:
262+
name: Install torch
263+
command: pip install --user --progress-bar=off --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
264+
- run:
265+
name: Install prototype dependencies
266+
command: pip install --user --progress-bar=off git+https://github.com/pytorch/data.git
267+
- checkout
268+
- run:
269+
name: Install torchvision
270+
command: pip install --user --progress-bar off --no-build-isolation .
271+
- run:
272+
name: Install test utilities
273+
command: pip install --user --progress-bar=off pytest
274+
- run:
275+
name: Run tests
276+
command: pytest test/test_prototype_*.py
277+
257278
binary_linux_wheel:
258279
<<: *binary_common
259280
docker:
@@ -977,6 +998,7 @@ workflows:
977998
- clang_format
978999
- torchhub_test
9791000
- torch_onnx_test
1001+
- prototype_test
9801002
{{ ios_workflows() }}
9811003
{{ android_workflows() }}
9821004

@@ -998,6 +1020,7 @@ workflows:
9981020
- clang_format
9991021
- torchhub_test
10001022
- torch_onnx_test
1023+
- prototype_test
10011024
{{ ios_workflows(nightly=True) }}
10021025
{{ android_workflows(nightly=True) }}
10031026
{{ build_workflows(prefix="nightly_", filter_branch="nightly", upload=True) }}

.circleci/regenerate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def build_workflows(prefix="", filter_branch=None, upload=False, indentation=6,
3333
python_versions = PYTHON_VERSIONS
3434
cu_versions_dict = {
3535
"linux": ["cpu", "cu102", "cu111", "cu113", "rocm4.2", "rocm4.3.1"],
36-
"win": ["cpu", "cu102", "cu111", "cu113"],
36+
"win": ["cpu", "cu111", "cu113"],
3737
"macos": ["cpu"],
3838
}
3939
cu_versions = cu_versions_dict[os_type]

.circleci/unittest/linux/scripts/install.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ fi
2626
printf "Installing PyTorch with %s\n" "${cudatoolkit}"
2727
conda install -y -c "pytorch-${UPLOAD_CHANNEL}" "pytorch-${UPLOAD_CHANNEL}"::pytorch "${cudatoolkit}" pytest
2828

29-
printf "Installing torchdata from source"
30-
pip install git+https://github.com/pytorch/data.git
31-
32-
3329
if [ $PYTHON_VERSION == "3.6" ]; then
3430
printf "Installing minimal PILLOW version\n"
3531
# Install the minimal PILLOW version. Otherwise, let setup.py install the latest

.circleci/unittest/linux/scripts/run_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ conda activate ./env
77

88
export PYTORCH_TEST_WITH_SLOW='1'
99
python -m torch.utils.collect_env
10-
pytest --cov=torchvision --junitxml=test-results/junit.xml -v --durations 20 test --ignore=test/test_datasets_download.py
10+
pytest --cov=torchvision --junitxml=test-results/junit.xml -v --durations 20

.circleci/unittest/windows/scripts/install.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ printf "Installing PyTorch with %s\n" "${cudatoolkit}"
2929
# conda-forge channel is required for cudatoolkit 11.1 on Windows, see https://github.com/pytorch/vision/issues/4458
3030
conda install -y -c "pytorch-${UPLOAD_CHANNEL}" -c conda-forge "pytorch-${UPLOAD_CHANNEL}"::pytorch "${cudatoolkit}" pytest
3131

32-
printf "Installing torchdata from source"
33-
pip install git+https://github.com/pytorch/data.git
34-
35-
3632
if [ $PYTHON_VERSION == "3.6" ]; then
3733
printf "Installing minimal PILLOW version\n"
3834
# Install the minimal PILLOW version. Otherwise, let setup.py install the latest

.circleci/unittest/windows/scripts/run_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ source "$this_dir/set_cuda_envs.sh"
1010

1111
export PYTORCH_TEST_WITH_SLOW='1'
1212
python -m torch.utils.collect_env
13-
pytest --cov=torchvision --junitxml=test-results/junit.xml -v --durations 20 test --ignore=test/test_datasets_download.py
13+
pytest --cov=torchvision --junitxml=test-results/junit.xml -v --durations 20

.github/process_commit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"bc-breaking",
2222
"deprecation",
2323
"other",
24+
"prototype",
2425
}
2526

2627
SECONDARY_LABELS = {

README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ supported Python versions.
2525
+--------------------------+--------------------------+---------------------------------+
2626
| ``1.9.0`` | ``0.10.0`` | ``>=3.6``, ``<=3.9`` |
2727
+--------------------------+--------------------------+---------------------------------+
28+
| ``1.8.2`` | ``0.9.2`` | ``>=3.6``, ``<=3.9`` |
29+
+--------------------------+--------------------------+---------------------------------+
2830
| ``1.8.1`` | ``0.9.1`` | ``>=3.6``, ``<=3.9`` |
2931
+--------------------------+--------------------------+---------------------------------+
3032
| ``1.8.0`` | ``0.9.0`` | ``>=3.6``, ``<=3.9`` |
@@ -110,7 +112,9 @@ Video Backend
110112
=============
111113
Torchvision currently supports the following video backends:
112114

113-
* [pyav](https://github.com/PyAV-Org/PyAV) (default) - Pythonic binding for ffmpeg libraries.
115+
* `pyav`_ (default) - Pythonic binding for ffmpeg libraries.
116+
117+
.. _pyav : https://github.com/PyAV-Org/PyAV
114118

115119
* video_reader - This needs ffmpeg to be installed and torchvision to be built from source. There shouldn't be any conflicting version of ffmpeg installed. Currently, this is only supported on Linux.
116120

mypy.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ ignore_errors=True
2121

2222
ignore_errors = True
2323

24-
[mypy-torchvision.models.detection.backbone_utils]
25-
26-
ignore_errors = True
27-
2824
[mypy-torchvision.models.detection.transform]
2925

3026
ignore_errors = True

packaging/build_cmake.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ else
3636
MKL_CONSTRAINT=''
3737
fi
3838

39-
conda install -yq \pytorch=$PYTORCH_VERSION $CONDA_CUDATOOLKIT_CONSTRAINT $CONDA_CPUONLY_FEATURE $MKL_CONSTRAINT -c "pytorch-${UPLOAD_CHANNEL}"
39+
if [[ $CONDA_BUILD_VARIANT == "cpu" ]]; then
40+
PYTORCH_MUTEX_CONSTRAINT='pytorch-mutex=1.0=cpu'
41+
else
42+
PYTORCH_MUTEX_CONSTRAINT=''
43+
fi
44+
45+
conda install -yq \pytorch=$PYTORCH_VERSION $CONDA_CUDATOOLKIT_CONSTRAINT $PYTORCH_MUTEX_CONSTRAINT $MKL_CONSTRAINT -c "pytorch-${UPLOAD_CHANNEL}"
4046
TORCH_PATH=$(dirname $(python -c "import torch; print(torch.__file__)"))
4147

4248
if [[ "$(uname)" == Darwin || "$OSTYPE" == "msys" ]]; then

packaging/pkg_helpers.bash

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ setup_conda_pytorch_constraint() {
287287

288288
# Translate CUDA_VERSION into CUDA_CUDATOOLKIT_CONSTRAINT
289289
setup_conda_cudatoolkit_constraint() {
290-
export CONDA_CPUONLY_FEATURE=""
290+
export CONDA_BUILD_VARIANT="cuda"
291291
if [[ "$(uname)" == Darwin ]]; then
292-
export CONDA_CUDATOOLKIT_CONSTRAINT=""
292+
export CONDA_BUILD_VARIANT="cpu"
293293
else
294294
case "$CU_VERSION" in
295295
cu113)
@@ -318,7 +318,7 @@ setup_conda_cudatoolkit_constraint() {
318318
;;
319319
cpu)
320320
export CONDA_CUDATOOLKIT_CONSTRAINT=""
321-
export CONDA_CPUONLY_FEATURE="- cpuonly"
321+
export CONDA_BUILD_VARIANT="cpu"
322322
;;
323323
*)
324324
echo "Unrecognized CU_VERSION=$CU_VERSION"
@@ -329,10 +329,10 @@ setup_conda_cudatoolkit_constraint() {
329329
}
330330

331331
setup_conda_cudatoolkit_plain_constraint() {
332-
export CONDA_CPUONLY_FEATURE=""
332+
export CONDA_BUILD_VARIANT="cuda"
333333
export CMAKE_USE_CUDA=1
334334
if [[ "$(uname)" == Darwin ]]; then
335-
export CONDA_CUDATOOLKIT_CONSTRAINT=""
335+
export CONDA_BUILD_VARIANT="cpu"
336336
export CMAKE_USE_CUDA=0
337337
else
338338
case "$CU_VERSION" in
@@ -359,7 +359,7 @@ setup_conda_cudatoolkit_plain_constraint() {
359359
;;
360360
cpu)
361361
export CONDA_CUDATOOLKIT_CONSTRAINT=""
362-
export CONDA_CPUONLY_FEATURE="cpuonly"
362+
export CONDA_BUILD_VARIANT="cpu"
363363
export CMAKE_USE_CUDA=0
364364
;;
365365
*)

packaging/torchvision/meta.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{% set build_variant = environ.get('CONDA_BUILD_VARIANT', 'cpu') %}
12
package:
23
name: torchvision
34
version: "{{ environ.get('BUILD_VERSION') }}"
@@ -16,9 +17,9 @@ requirements:
1617
host:
1718
- python
1819
- setuptools
20+
- pytorch-mutex 1.0 {{ build_variant }} # [not osx ]
1921
{{ environ.get('CONDA_PYTORCH_BUILD_CONSTRAINT') }}
20-
{{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT') }}
21-
{{ environ.get('CONDA_CPUONLY_FEATURE') }}
22+
{{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT', '') }}
2223

2324
run:
2425
- python
@@ -27,8 +28,17 @@ requirements:
2728
- ffmpeg >=4.2 # [not win]
2829
- jpeg
2930
- pillow >=5.3.0
31+
- pytorch-mutex 1.0 {{ build_variant }} # [not osx ]
3032
{{ environ.get('CONDA_PYTORCH_CONSTRAINT') }}
31-
{{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT') }}
33+
{{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT', '') }}
34+
35+
{% if build_variant == 'cpu' %}
36+
run_constrained:
37+
- cpuonly
38+
{% elif not osx %}
39+
run_constrained:
40+
- cpuonly <0
41+
{% endif %}
3242

3343
build:
3444
string: py{{py}}_{{ environ['CU_VERSION'] }}
@@ -38,8 +48,6 @@ build:
3848
- FORCE_CUDA
3949
- BUILD_VERSION
4050
- TORCH_CUDA_ARCH_LIST
41-
features:
42-
{{ environ.get('CONDA_CPUONLY_FEATURE') }}
4351

4452
test:
4553
imports:

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ addopts =
66
--tb=native
77
# enable all warnings
88
-Wd
9+
--ignore=test/test_datasets_download.py
10+
--ignore-glob=test/test_prototype_*.py
911
testpaths =
1012
test

references/classification/train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def evaluate(model, criterion, data_loader, device, print_freq=100, log_suffix="
5858
header = f"Test: {log_suffix}"
5959

6060
num_processed_samples = 0
61-
with torch.no_grad():
61+
with torch.inference_mode():
6262
for image, target in metric_logger.log_every(data_loader, print_freq, header):
6363
image = image.to(device, non_blocking=True)
6464
target = target.to(device, non_blocking=True)

references/classification/train_quantization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def main(args):
112112
print("Starting training for epoch", epoch)
113113
train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, args.print_freq)
114114
lr_scheduler.step()
115-
with torch.no_grad():
115+
with torch.inference_mode():
116116
if epoch >= args.num_observer_update_epochs:
117117
print("Disabling observer for subseq epochs, epoch = ", epoch)
118118
model.apply(torch.quantization.disable_observer)

references/classification/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def update_parameters(self, model):
181181

182182
def accuracy(output, target, topk=(1,)):
183183
"""Computes the accuracy over the k top predictions for the specified values of k"""
184-
with torch.no_grad():
184+
with torch.inference_mode():
185185
maxk = max(topk)
186186
batch_size = target.size(0)
187187
if target.ndim == 2:

references/detection/engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _get_iou_types(model):
6868
return iou_types
6969

7070

71-
@torch.no_grad()
71+
@torch.inference_mode()
7272
def evaluate(model, data_loader, device):
7373
n_threads = torch.get_num_threads()
7474
# FIXME remove this and make paste_masks_in_image run on the GPU

references/detection/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def reduce_dict(input_dict, average=True):
9595
world_size = get_world_size()
9696
if world_size < 2:
9797
return input_dict
98-
with torch.no_grad():
98+
with torch.inference_mode():
9999
names = []
100100
values = []
101101
# sort the keys so that they are consistent across processes

references/segmentation/train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def evaluate(model, data_loader, device, num_classes):
4949
confmat = utils.ConfusionMatrix(num_classes)
5050
metric_logger = utils.MetricLogger(delimiter=" ")
5151
header = "Test:"
52-
with torch.no_grad():
52+
with torch.inference_mode():
5353
for image, target in metric_logger.log_every(data_loader, 100, header):
5454
image, target = image.to(device), target.to(device)
5555
output = model(image)

references/segmentation/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def update(self, a, b):
7676
n = self.num_classes
7777
if self.mat is None:
7878
self.mat = torch.zeros((n, n), dtype=torch.int64, device=a.device)
79-
with torch.no_grad():
79+
with torch.inference_mode():
8080
k = (a >= 0) & (a < n)
8181
inds = n * a[k].to(torch.int64) + b[k]
8282
self.mat += torch.bincount(inds, minlength=n ** 2).reshape(n, n)

references/similarity/train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def find_best_threshold(dists, targets, device):
5151
return best_thresh, accuracy
5252

5353

54-
@torch.no_grad()
54+
@torch.inference_mode()
5555
def evaluate(model, loader, device):
5656
model.eval()
5757
embeds, labels = [], []

references/video_classification/train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def evaluate(model, criterion, data_loader, device):
5252
model.eval()
5353
metric_logger = utils.MetricLogger(delimiter=" ")
5454
header = "Test:"
55-
with torch.no_grad():
55+
with torch.inference_mode():
5656
for video, target in metric_logger.log_every(data_loader, 100, header):
5757
video = video.to(device, non_blocking=True)
5858
target = target.to(device, non_blocking=True)

references/video_classification/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def log_every(self, iterable, print_freq, header=None):
159159

160160
def accuracy(output, target, topk=(1,)):
161161
"""Computes the accuracy over the k top predictions for the specified values of k"""
162-
with torch.no_grad():
162+
with torch.inference_mode():
163163
maxk = max(topk)
164164
batch_size = target.size(0)
165165

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def run(self):
466466
license="BSD",
467467
# Package info
468468
packages=find_packages(exclude=("test",)),
469-
package_data={package_name: ["*.dll", "*.dylib", "*.so", "*.categories"]},
469+
package_data={package_name: ["*.dll", "*.dylib", "*.so", "prototype/datasets/_builtin/*.categories"]},
470470
zip_safe=False,
471471
install_requires=requirements,
472472
extras_require={
Binary file not shown.

test/test_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
def _create_video_frames(num_frames, height, width):
26-
y, x = torch.meshgrid(torch.linspace(-2, 2, height), torch.linspace(-2, 2, width))
26+
y, x = torch.meshgrid(torch.linspace(-2, 2, height), torch.linspace(-2, 2, width), indexing="ij")
2727
data = []
2828
for i in range(num_frames):
2929
xc = float(i) / num_frames

0 commit comments

Comments
 (0)