Skip to content

Commit

Permalink
Speed up CI runtime (#3189)
Browse files Browse the repository at this point in the history
* Speedup test_ucf101 (#2623 

* Speedup Cmake builds (#3186)

* Speedup test_autoaugment (#3190)

* Speedup DeformConvTester (#3191)

* Speedup InceptionV3 and GoogleNet on Windows (#3196)
  • Loading branch information
datumbox authored Jan 4, 2021
1 parent e85a113 commit 4d2d8bb
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .circleci/unittest/windows/scripts/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ dependencies:
- pip:
- future
- pillow>=4.1.1
- scipy==1.4.1
- scipy
- av
- dataclasses
17 changes: 11 additions & 6 deletions packaging/build_cmake.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/bash
set -ex

PARALLELISM=8
if [ -n "$MAX_JOBS" ]; then
PARALLELISM=$MAX_JOBS
fi

if [[ "$(uname)" != Darwin && "$OSTYPE" != "msys" ]]; then
eval "$(./conda/bin/conda shell.bash hook)"
conda activate ./env
Expand Down Expand Up @@ -40,11 +45,11 @@ cmake .. -DTorch_DIR=$TORCH_PATH/share/cmake/Torch -DWITH_CUDA=$CMAKE_USE_CUDA

# Compile and install libtorchvision
if [[ "$OSTYPE" == "msys" ]]; then
"$script_dir/windows/internal/vc_env_helper.bat" "$script_dir/windows/internal/build_cmake.bat"
"$script_dir/windows/internal/vc_env_helper.bat" "$script_dir/windows/internal/build_cmake.bat" $PARALLELISM
CONDA_PATH=$(dirname $(which python))
cp -r "C:/Program Files (x86)/torchvision/include/torchvision" $CONDA_PATH/include
else
make
make -j$PARALLELISM
make install

if [[ "$(uname)" == Darwin ]]; then
Expand All @@ -71,12 +76,12 @@ cp fasterrcnn_resnet50_fpn.pt build
cd build
cmake .. -DTorch_DIR=$TORCH_PATH/share/cmake/Torch -DWITH_CUDA=$CMAKE_USE_CUDA
if [[ "$OSTYPE" == "msys" ]]; then
"$script_dir/windows/internal/vc_env_helper.bat" "$script_dir/windows/internal/build_frcnn.bat"
"$script_dir/windows/internal/vc_env_helper.bat" "$script_dir/windows/internal/build_frcnn.bat" $PARALLELISM
mv fasterrcnn_resnet50_fpn.pt Release
cd Release
export PATH=$(cygpath "C:/Program Files (x86)/torchvision/bin"):$(cygpath $TORCH_PATH)/lib:$PATH
else
make
make -j$PARALLELISM
fi

# Run traced program
Expand All @@ -91,10 +96,10 @@ cd build
cmake .. -DTorch_DIR=$TORCH_PATH/share/cmake/Torch

if [[ "$OSTYPE" == "msys" ]]; then
"$script_dir/windows/internal/vc_env_helper.bat" "$script_dir/windows/internal/build_cpp_example.bat"
"$script_dir/windows/internal/vc_env_helper.bat" "$script_dir/windows/internal/build_cpp_example.bat" $PARALLELISM
cd Release
else
make
make -j$PARALLELISM
fi

# Run CPP example
Expand Down
4 changes: 2 additions & 2 deletions packaging/windows/internal/build_cmake.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo on
msbuild "-p:Configuration=Release" torchvision.vcxproj
msbuild "-p:Configuration=Release" INSTALL.vcxproj
msbuild "-p:Configuration=Release" "-p:BuildInParallel=true" "-p:MultiProcessorCompilation=true" "-p:CL_MPCount=%1" torchvision.vcxproj -maxcpucount:%1
msbuild "-p:Configuration=Release" "-p:BuildInParallel=true" "-p:MultiProcessorCompilation=true" "-p:CL_MPCount=%1" INSTALL.vcxproj -maxcpucount:%1
2 changes: 1 addition & 1 deletion packaging/windows/internal/build_cpp_example.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo on
set CL=/I"C:\Program Files (x86)\torchvision\include"
msbuild "-p:Configuration=Release" hello-world.vcxproj
msbuild "-p:Configuration=Release" "-p:BuildInParallel=true" "-p:MultiProcessorCompilation=true" "-p:CL_MPCount=%1" hello-world.vcxproj -maxcpucount:%1
2 changes: 1 addition & 1 deletion packaging/windows/internal/build_frcnn.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo on
set CL=/I"C:\Program Files (x86)\torchvision\include"
msbuild "-p:Configuration=Release" test_frcnn_tracing.vcxproj
msbuild "-p:Configuration=Release" "-p:BuildInParallel=true" "-p:MultiProcessorCompilation=true" "-p:CL_MPCount=%1" test_frcnn_tracing.vcxproj -maxcpucount:%1
1 change: 0 additions & 1 deletion test/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def set_rng_seed(seed):

ACCEPT = os.getenv('EXPECTTEST_ACCEPT')
TEST_WITH_SLOW = os.getenv('PYTORCH_TEST_WITH_SLOW', '0') == '1'
# TEST_WITH_SLOW = True # TODO: Delete this line once there is a PYTORCH_TEST_WITH_SLOW aware CI job


parser = argparse.ArgumentParser(add_help=False)
Expand Down
7 changes: 5 additions & 2 deletions test/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,15 @@ def test_voc_parse_xml(self, mock_download_extract):

@unittest.skipIf(not HAS_PYAV, "PyAV unavailable")
def test_ucf101(self):
cached_meta_data = None
with ucf101_root() as (root, ann_root):
for split in {True, False}:
for fold in range(1, 4):
for length in {10, 15, 20}:
dataset = torchvision.datasets.UCF101(
root, ann_root, length, fold=fold, train=split)
dataset = torchvision.datasets.UCF101(root, ann_root, length, fold=fold, train=split,
num_workers=2, _precomputed_metadata=cached_meta_data)
if cached_meta_data is None:
cached_meta_data = dataset.metadata
self.assertGreater(len(dataset), 0)

video, audio, label = dataset[0]
Expand Down
4 changes: 2 additions & 2 deletions test/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def test_resnet_dilation(self):
f = 2 ** sum(i)
self.assertEqual(out.shape, (1, 2048, 7 * f, 7 * f))

def test_mobilenetv2_residual_setting(self):
def test_mobilenet_v2_residual_setting(self):
model = models.__dict__["mobilenet_v2"](inverted_residual_setting=[[1, 16, 1, 1], [6, 24, 2, 2]])
model.eval()
x = torch.rand(1, 3, 224, 224)
Expand All @@ -286,7 +286,7 @@ def get_gn(num_channels):
self.assertFalse(any(isinstance(x, nn.BatchNorm2d) for x in model.modules()))
self.assertTrue(any(isinstance(x, nn.GroupNorm) for x in model.modules()))

def test_inceptionv3_eval(self):
def test_inception_v3_eval(self):
# replacement for models.inception_v3(pretrained=True) that does not download weights
kwargs = {}
kwargs['transform_input'] = True
Expand Down
6 changes: 5 additions & 1 deletion test/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np

import torch
from functools import lru_cache
from torch import Tensor
from torch.autograd import gradcheck
from torch.nn.modules.utils import _pair
Expand Down Expand Up @@ -496,6 +497,7 @@ def expected_fn(self, x, weight, offset, mask, bias, stride=1, padding=0, dilati
out += bias.view(1, n_out_channels, 1, 1)
return out

@lru_cache(maxsize=None)
def get_fn_args(self, device, contiguous, batch_sz, dtype):
n_in_channels = 6
n_out_channels = 2
Expand Down Expand Up @@ -614,9 +616,11 @@ def script_func_no_mask(x_, offset_, weight_, bias_, stride_, pad_, dilation_):
gradcheck(lambda z, off, wei, bi: script_func_no_mask(z, off, wei, bi, stride, padding, dilation),
(x, offset, weight, bias), nondet_tol=1e-5)

@unittest.skipIf(not torch.cuda.is_available(), "CUDA unavailable")
def test_compare_cpu_cuda_grads(self):
# Test from https://github.com/pytorch/vision/issues/2598
# Run on CUDA only
if "cuda" in device.type:
for contiguous in [False, True]:
# compare grads computed on CUDA with grads computed on CPU
true_cpu_grads = None

Expand Down
11 changes: 6 additions & 5 deletions test/test_transforms_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,17 +630,18 @@ def test_autoaugment(self):
tensor = torch.randint(0, 256, size=(3, 44, 56), dtype=torch.uint8, device=self.device)
batch_tensors = torch.randint(0, 256, size=(4, 3, 44, 56), dtype=torch.uint8, device=self.device)

s_transform = None
for policy in T.AutoAugmentPolicy:
for fill in [None, 85, (10, -10, 10), 0.7, [0.0, 0.0, 0.0], [1, ], 1]:
transform = T.AutoAugment(policy=policy, fill=fill)
s_transform = torch.jit.script(transform)
for _ in range(100):
transform = T.AutoAugment(policy=policy, fill=fill)
s_transform = torch.jit.script(transform)

self._test_transform_vs_scripted(transform, s_transform, tensor)
self._test_transform_vs_scripted_on_batch(transform, s_transform, batch_tensors)

with get_tmp_dir() as tmp_dir:
s_transform.save(os.path.join(tmp_dir, "t_autoaugment.pt"))
if s_transform is not None:
with get_tmp_dir() as tmp_dir:
s_transform.save(os.path.join(tmp_dir, "t_autoaugment.pt"))


@unittest.skipIf(not torch.cuda.is_available(), reason="Skip if no CUDA device")
Expand Down

0 comments on commit 4d2d8bb

Please sign in to comment.