Skip to content
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

3432 make vit support torchscript #3782

Merged

Conversation

yiheng-wang-nv
Copy link
Contributor

@yiheng-wang-nv yiheng-wang-nv commented Feb 9, 2022

Signed-off-by: Yiheng Wang vennw@nvidia.com

Fixes #3432 .

Description

This PR is used to fix #3422 , different from the way used in #3433 which requires to remove einops, this PR keeps this library.

During this PR, the direct calling of einops.arrange in forward functions of class SABlock has been replaced by using Rearrange layers in order to support torchscript.

Status

Ready/Work in progress/Hold

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

Signed-off-by: Yiheng Wang <vennw@nvidia.com>
Copy link
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks this looks good me, if @ahatamiz has no further comments we merge it today.

@wyli
Copy link
Contributor

wyli commented Feb 9, 2022

@ericspod
Copy link
Member

ericspod commented Feb 9, 2022

There may be some deep-seated incompatibilities between Torchscript and Einops: arogozhnikov/einops#115 The issue with build-gpu/GPU-quick-py3 (PT18+CUDA102) failing may be related, later versions of Pytorch after 1.8 may work, I ran tests with Pytorch 1.10 just now and that version at least works. We may have to state only a certain Pytorch version is scriptable and put the condition on the script test for ViT.

yiheng-wang-nv and others added 4 commits February 10, 2022 10:20
Signed-off-by: Yiheng Wang <vennw@nvidia.com>
Signed-off-by: Yiheng Wang <vennw@nvidia.com>
Signed-off-by: Yiheng Wang <vennw@nvidia.com>
@wyli
Copy link
Contributor

wyli commented Feb 10, 2022

/build

@wyli wyli enabled auto-merge (squash) February 10, 2022 08:20
@wyli wyli merged commit 0be3341 into Project-MONAI:dev Feb 10, 2022
wyli pushed a commit to wyli/MONAI that referenced this pull request Feb 10, 2022
* make vit support torchscript

Signed-off-by: Yiheng Wang <vennw@nvidia.com>

* add torch version restriction

Signed-off-by: Yiheng Wang <vennw@nvidia.com>

* change skip decorator order

Signed-off-by: Yiheng Wang <vennw@nvidia.com>

* remove extra cls

Signed-off-by: Yiheng Wang <vennw@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ViT does not support torchscript
3 participants