Skip to content

Commit

Permalink
Fix torch export issue
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dvorjackz authored and facebook-github-bot committed Aug 5, 2024
1 parent 2a420ed commit 31bebde
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions detectron2/export/c10.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def set(self, name, value):
else:
data_len = len(value)
if len(self.batch_extra_fields):
# If we are tracing with Dynamo, the check here is needed since len(self)
# represents the number of bounding boxes detected in the image and thus is
# an unbounded SymInt.
if torch._utils.is_compiling():
torch._check(len(self) == data_len)
assert (
len(self) == data_len
), "Adding a field of length {} to a Instances of length {}".format(data_len, len(self))
Expand Down

0 comments on commit 31bebde

Please sign in to comment.