From 7f0faf005ff9931009104c0e809de4544a916816 Mon Sep 17 00:00:00 2001 From: Xu Zhao Date: Wed, 2 Mar 2022 12:52:34 -0500 Subject: [PATCH] Atttempt to reduce unnecessary cuda sync --- torchvision/models/detection/anchor_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torchvision/models/detection/anchor_utils.py b/torchvision/models/detection/anchor_utils.py index 202294153ea..6771dda0ce4 100644 --- a/torchvision/models/detection/anchor_utils.py +++ b/torchvision/models/detection/anchor_utils.py @@ -121,8 +121,8 @@ def forward(self, image_list: ImageList, feature_maps: List[Tensor]) -> List[Ten dtype, device = feature_maps[0].dtype, feature_maps[0].device strides = [ [ - torch.tensor(image_size[0] // g[0], dtype=torch.int64, device=device), - torch.tensor(image_size[1] // g[1], dtype=torch.int64, device=device), + torch.empty((), dtype=torch.int64, device=device).fill_(image_size[0] // g[0]), + torch.empty((), dtype=torch.int64, device=device).fill_(image_size[1] // g[1]), ] for g in grid_sizes ]