Skip to content

Commit 31bebde

Browse files
jackzhxngfacebook-github-bot
authored andcommitted
Fix torch export issue
Summary: X-link: fairinternal/detectron2#604 Pull Request resolved: #5334 Add a check to deal with dynamic shapes so that the model can be exported with `torch.export`. This check prevents the graph break caused by the SymInt by delaying the assertion to runtime. Reviewed By: wat3rBro Differential Revision: D60126415 fbshipit-source-id: a2a75530db523bfdde984b890595e02360d8e07f
1 parent 2a420ed commit 31bebde

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

detectron2/export/c10.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ def set(self, name, value):
8484
else:
8585
data_len = len(value)
8686
if len(self.batch_extra_fields):
87+
# If we are tracing with Dynamo, the check here is needed since len(self)
88+
# represents the number of bounding boxes detected in the image and thus is
89+
# an unbounded SymInt.
90+
if torch._utils.is_compiling():
91+
torch._check(len(self) == data_len)
8792
assert (
8893
len(self) == data_len
8994
), "Adding a field of length {} to a Instances of length {}".format(data_len, len(self))

0 commit comments

Comments
 (0)