Skip to content

Add torch._check hints for torch.export #5467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion detectron2/structures/image_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ def from_tensors(
# This seems slightly (2%) faster.
# TODO: check whether it's faster for multiple images as well
image_size = image_sizes[0]
padding_size = [0, max_size[-1] - image_size[1], 0, max_size[-2] - image_size[0]]
u0 = (max_size[-1] - image_size[1]).item()
u1 = (max_size[-2] - image_size[0]).item()
padding_size = [0, u0, 0, u1]
if torch.compiler.is_compiling():
torch._check(u0 >= 0)
torch._check(u1 >= 0)
batched_imgs = F.pad(tensors[0], padding_size, value=pad_value).unsqueeze_(0)
else:
# max_size can be a tensor in tracing mode, therefore convert to list
Expand Down