Skip to content

Commit 5c380fd

Browse files
Yanghan Wangfacebook-github-bot
authored andcommitted
fix Github actions
Summary: Pull Request resolved: #5274 Add a new test to cover PyTorch 2.0 (we'll probably drop the support for 1.x). Reviewed By: ayushidalmia Differential Revision: D56911192 fbshipit-source-id: cc57079319c2f3aac285c232791ea399599dead9
1 parent 8f22855 commit 5c380fd

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

.github/workflows/workflow.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: CI
2-
on: [push, pull_request]
2+
on:
3+
push:
4+
pull_request:
5+
schedule:
6+
- cron: "0 0 * * *" # @daily
37

48
# Run linter with github actions for quick feedbacks.
59
# Run macos tests with github actions. Linux (CPU & GPU) tests currently runs on CircleCI
@@ -37,14 +41,12 @@ jobs:
3741
strategy:
3842
fail-fast: false
3943
matrix:
40-
torch: ["1.8", "1.9", "1.10"]
44+
torch: ["1.13.1", "2.2.2"]
4145
include:
42-
- torch: "1.8"
43-
torchvision: 0.9
44-
- torch: "1.9"
45-
torchvision: "0.10"
46-
- torch: "1.10"
47-
torchvision: "0.11.1"
46+
- torch: "1.13.1"
47+
torchvision: "0.14.1"
48+
- torch: "2.2.2"
49+
torchvision: "0.17.2"
4850
env:
4951
# point datasets to ~/.torch so it's cached by CI
5052
DETECTRON2_DATASETS: ~/.torch/datasets
@@ -66,11 +68,13 @@ jobs:
6668
- name: Install dependencies
6769
run: |
6870
python -m pip install -U pip
69-
python -m pip install ninja opencv-python-headless onnx pytest-xdist
71+
python -m pip install wheel ninja opencv-python-headless onnx pytest-xdist
7072
python -m pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html
7173
# install from github to get latest; install iopath first since fvcore depends on it
7274
python -m pip install -U 'git+https://github.com/facebookresearch/iopath'
7375
python -m pip install -U 'git+https://github.com/facebookresearch/fvcore'
76+
wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
77+
python collect_env.py
7478
7579
- name: Build and install
7680
run: |

detectron2/layers/nms.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from torchvision.ops import boxes as box_ops
66
from torchvision.ops import nms # noqa . for compatibility
77

8+
from detectron2.layers.wrappers import disable_torch_compiler
9+
810

911
def batched_nms(
1012
boxes: torch.Tensor, scores: torch.Tensor, idxs: torch.Tensor, iou_threshold: float
@@ -22,7 +24,7 @@ def batched_nms(
2224

2325
# Note: this function (nms_rotated) might be moved into
2426
# torchvision/ops/boxes.py in the future
25-
@torch.compiler.disable
27+
@disable_torch_compiler
2628
def nms_rotated(boxes: torch.Tensor, scores: torch.Tensor, iou_threshold: float):
2729
"""
2830
Performs non-maximum suppression (NMS) on the rotated boxes according

detectron2/layers/roi_align_rotated.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
from torch.autograd.function import once_differentiable
66
from torch.nn.modules.utils import _pair
77

8+
from detectron2.layers.wrappers import disable_torch_compiler
9+
810

911
class _ROIAlignRotated(Function):
1012
@staticmethod
11-
@torch.compiler.disable
13+
@disable_torch_compiler
1214
def forward(ctx, input, roi, output_size, spatial_scale, sampling_ratio):
1315
ctx.save_for_backward(roi)
1416
ctx.output_size = _pair(output_size)

detectron2/layers/wrappers.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
is implemented
99
"""
1010

11+
import functools
1112
import warnings
1213
from typing import List, Optional
1314
import torch
@@ -39,14 +40,28 @@ def shapes_to_tensor(x: List[int], device: Optional[torch.device] = None) -> tor
3940

4041

4142
def check_if_dynamo_compiling():
42-
if TORCH_VERSION >= (1, 14):
43+
if TORCH_VERSION >= (2, 1):
4344
from torch._dynamo import is_compiling
4445

4546
return is_compiling()
4647
else:
4748
return False
4849

4950

51+
def disable_torch_compiler(func):
52+
if TORCH_VERSION >= (2, 1):
53+
# Use the torch.compiler.disable decorator if supported
54+
@torch.compiler.disable
55+
@functools.wraps(func)
56+
def wrapper(*args, **kwargs):
57+
return func(*args, **kwargs)
58+
59+
return wrapper
60+
else:
61+
# Return the function unchanged if torch.compiler.disable is not supported
62+
return func
63+
64+
5065
def cat(tensors: List[torch.Tensor], dim: int = 0):
5166
"""
5267
Efficient version of torch.cat that avoids a copy if there is only a single element in a list

tests/test_export_onnx.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import io
44
import unittest
55
import warnings
6+
import onnx
67
import torch
8+
from packaging import version
79
from torch.hub import _check_module_exists
810

911
from detectron2 import model_zoo
@@ -95,6 +97,10 @@ def inference_func(model, image):
9597
inference_func,
9698
)
9799

100+
@unittest.skipIf(
101+
version.Version(onnx.version.version) == version.Version("1.16.0"),
102+
"This test fails on ONNX Runtime 1.16",
103+
)
98104
def testKeypointHead(self):
99105
class M(torch.nn.Module):
100106
def __init__(self):

0 commit comments

Comments
 (0)