Skip to content

Commit 0e29b7a

Browse files
ppwwyyxxfacebook-github-bot
authored andcommitted
drop support for pytorch 1.7
Summary: changes in preparation for pytorch 1.10 Reviewed By: zhanghang1989 Differential Revision: D31575602 fbshipit-source-id: 95fa947aafa201386901ad5a6ff2726b0a43dcff
1 parent efd8f4d commit 0e29b7a

File tree

21 files changed

+14
-76
lines changed

21 files changed

+14
-76
lines changed

.circleci/config.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,6 @@ workflows:
229229
name: linux_cpu_tests_pytorch1.9
230230
pytorch_version: '1.9.0+cpu'
231231
torchvision_version: '0.10.0+cpu'
232-
- linux_gpu_tests:
233-
name: linux_gpu_tests_pytorch1.7
234-
pytorch_version: '1.7.0'
235-
torchvision_version: '0.8.1'
236-
# 1.7 wheels don't have +cu102 suffix, so use a cu102 specific index
237-
pytorch_index: 'https://download.pytorch.org/whl/cu102/torch_stable.html'
238232
- linux_gpu_tests:
239233
name: linux_gpu_tests_pytorch1.8
240234
pytorch_version: '1.8.1+cu102'

.github/workflows/workflow.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ jobs:
3636
strategy:
3737
fail-fast: false
3838
matrix:
39-
torch: [1.7, 1.8, 1.9]
39+
torch: [1.8, 1.9]
4040
include:
41-
- torch: 1.7
42-
torchvision: 0.8
4341
- torch: 1.8
4442
torchvision: 0.9
4543
- torch: 1.9

INSTALL.md

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

33
### Requirements
44
- Linux or macOS with Python ≥ 3.6
5-
- PyTorch ≥ 1.7 and [torchvision](https://github.com/pytorch/vision/) that matches the PyTorch installation.
5+
- PyTorch ≥ 1.8 and [torchvision](https://github.com/pytorch/vision/) that matches the PyTorch installation.
66
Install them together at [pytorch.org](https://pytorch.org) to make sure of this
77
- OpenCV is optional but needed by demo and visualization
88

detectron2/checkpoint/detection_checkpoint.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from torch.nn.parallel import DistributedDataParallel
88

99
import detectron2.utils.comm as comm
10-
from detectron2.utils.env import TORCH_VERSION
1110
from detectron2.utils.file_io import PathManager
1211

1312
from .c2_model_loading import align_and_update_state_dicts
@@ -54,8 +53,7 @@ def load(self, path, *args, **kwargs):
5453

5554
if need_sync:
5655
logger.info("Broadcasting model states from main worker ...")
57-
if TORCH_VERSION >= (1, 7):
58-
self.model._sync_params_and_buffers()
56+
self.model._sync_params_and_buffers()
5957
return ret
6058

6159
def _load_file(self, filename):

detectron2/export/torchscript.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
import torch
55

6-
from detectron2.utils.env import TORCH_VERSION
76
from detectron2.utils.file_io import PathManager
87

98
from .torchscript_patch import freeze_training_mode, patch_instances
@@ -48,7 +47,6 @@ def scripting_with_instances(model, fields):
4847
Returns:
4948
torch.jit.ScriptModule: the model in torchscript format
5049
"""
51-
assert TORCH_VERSION >= (1, 8), "This feature is not available in PyTorch < 1.8"
5250
assert (
5351
not model.training
5452
), "Currently we only support exporting models in evaluation mode to torchscript"

detectron2/modeling/proposal_generator/rrpn.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from ..box_regression import Box2BoxTransformRotated
1313
from .build import PROPOSAL_GENERATOR_REGISTRY
14+
from .proposal_utils import _is_tracing
1415
from .rpn import RPN
1516

1617
logger = logging.getLogger(__name__)
@@ -67,7 +68,10 @@ def find_top_rrpn_proposals(
6768
itertools.count(), proposals, pred_objectness_logits
6869
):
6970
Hi_Wi_A = logits_i.shape[1]
70-
num_proposals_i = min(pre_nms_topk, Hi_Wi_A)
71+
if isinstance(Hi_Wi_A, torch.Tensor): # it's a tensor in tracing
72+
num_proposals_i = torch.clamp(Hi_Wi_A, max=pre_nms_topk)
73+
else:
74+
num_proposals_i = min(Hi_Wi_A, pre_nms_topk)
7175

7276
# sort is faster than topk (https://github.com/pytorch/pytorch/issues/22812)
7377
# topk_scores_i, topk_idx = logits_i.topk(num_proposals_i, dim=1)
@@ -101,7 +105,7 @@ def find_top_rrpn_proposals(
101105
# filter empty boxes
102106
keep = boxes.nonempty(threshold=min_box_size)
103107
lvl = level_ids
104-
if keep.sum().item() != len(boxes):
108+
if _is_tracing() or keep.sum().item() != len(boxes):
105109
boxes, scores_per_img, lvl = (boxes[keep], scores_per_img[keep], level_ids[keep])
106110

107111
keep = batched_nms_rotated(boxes.tensor, scores_per_img, lvl, nms_thresh)

detectron2/structures/boxes.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,9 @@
66
import torch
77
from torch import device
88

9-
from detectron2.utils.env import TORCH_VERSION
10-
119
_RawBoxType = Union[List[float], Tuple[float, ...], torch.Tensor, np.ndarray]
1210

1311

14-
if TORCH_VERSION < (1, 8):
15-
_maybe_jit_unused = torch.jit.unused
16-
else:
17-
18-
def _maybe_jit_unused(x):
19-
return x
20-
21-
2212
@unique
2313
class BoxMode(IntEnum):
2414
"""
@@ -173,7 +163,6 @@ def clone(self) -> "Boxes":
173163
"""
174164
return Boxes(self.tensor.clone())
175165

176-
@_maybe_jit_unused
177166
def to(self, device: torch.device):
178167
# Boxes are assumed float32 and does not support to(dtype)
179168
return Boxes(self.tensor.to(device=device))
@@ -285,7 +274,6 @@ def scale(self, scale_x: float, scale_y: float) -> None:
285274
self.tensor[:, 1::2] *= scale_y
286275

287276
@classmethod
288-
@_maybe_jit_unused
289277
def cat(cls, boxes_list: List["Boxes"]) -> "Boxes":
290278
"""
291279
Concatenates a list of Boxes into a single Boxes

detectron2/structures/keypoints.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@
44
import torch
55
from torch.nn import functional as F
66

7-
from detectron2.utils.env import TORCH_VERSION
8-
9-
if TORCH_VERSION < (1, 8):
10-
11-
def script_if_tracing(fn):
12-
return fn
13-
14-
15-
else:
16-
script_if_tracing = torch.jit.script_if_tracing
17-
187

198
class Keypoints:
209
"""
@@ -172,7 +161,7 @@ def _keypoints_to_heatmap(
172161
return heatmaps, valid
173162

174163

175-
@script_if_tracing
164+
@torch.jit.script_if_tracing
176165
def heatmaps_to_keypoints(maps: torch.Tensor, rois: torch.Tensor) -> torch.Tensor:
177166
"""
178167
Extract predicted keypoint locations from heatmaps.

detectron2/structures/rotated_boxes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from detectron2.layers.rotated_boxes import pairwise_iou_rotated
77

8-
from .boxes import Boxes, _maybe_jit_unused
8+
from .boxes import Boxes
99

1010

1111
class RotatedBoxes(Boxes):
@@ -229,7 +229,6 @@ def clone(self) -> "RotatedBoxes":
229229
"""
230230
return RotatedBoxes(self.tensor.clone())
231231

232-
@_maybe_jit_unused
233232
def to(self, device: torch.device):
234233
# Boxes are assumed float32 and does not support to(dtype)
235234
return RotatedBoxes(self.tensor.to(device=device))
@@ -455,7 +454,6 @@ def scale(self, scale_x: float, scale_y: float) -> None:
455454
self.tensor[:, 4] = torch.atan2(scale_x * s, scale_y * c) * 180 / math.pi
456455

457456
@classmethod
458-
@_maybe_jit_unused
459457
def cat(cls, boxes_list: List["RotatedBoxes"]) -> "RotatedBoxes":
460458
"""
461459
Concatenates a list of RotatedBoxes into a single RotatedBoxes

detectron2/utils/comm.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import torch
1212
import torch.distributed as dist
1313

14-
from .env import TORCH_VERSION
15-
1614
_LOCAL_PROCESS_GROUP = None
1715
"""
1816
A torch process group which only includes processes that on the same machine as the current process.
@@ -80,7 +78,7 @@ def synchronize():
8078
world_size = dist.get_world_size()
8179
if world_size == 1:
8280
return
83-
if dist.get_backend() == dist.Backend.NCCL and TORCH_VERSION >= (1, 8):
81+
if dist.get_backend() == dist.Backend.NCCL:
8482
# This argument is needed to avoid warnings.
8583
# It's valid only for NCCL backend.
8684
dist.barrier(device_ids=[torch.cuda.current_device()])

0 commit comments

Comments
 (0)