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

Make ViT and Unetr to be torchscript comaptible #7937

Merged
merged 8 commits into from
Jul 23, 2024

Conversation

KumoLiu
Copy link
Contributor

@KumoLiu KumoLiu commented Jul 22, 2024

Fixes #7936

Description

  • Pre-define self.causal_mask = torch.Tensor() before register buffer
  • Move norm_cross_attn and cross_attn out of if block

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: YunLiu <55491388+KumoLiu@users.noreply.github.com>
KumoLiu and others added 4 commits July 22, 2024 17:36
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
@KumoLiu
Copy link
Contributor Author

KumoLiu commented Jul 22, 2024

/build

@KumoLiu
Copy link
Contributor Author

KumoLiu commented Jul 22, 2024

Hi @ericspod and @virginiafdez, the issue is introduced by merging the gen-ai-dev branch: #7886. ViT and Unetr can't support torchscript converting after merging the PR.
Could you please help review this PR? Thanks!

Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
@KumoLiu KumoLiu changed the title Make ViT to be torchscript comaptible Make ViT and Unetr to be torchscript comaptible Jul 23, 2024
Copy link
Contributor

@virginiafdez virginiafdez left a comment

Choose a reason for hiding this comment

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

I have checked this with Eric. The only concern we have is in selfattention.py, when you add the CrossAttention block as an attribute by default, it might lead to incompatibilities when loading the module weights from old models, as weights are expected to be there unless you choose strict=False

@KumoLiu
Copy link
Contributor Author

KumoLiu commented Jul 23, 2024

/build

Copy link
Member

@ericspod ericspod left a comment

Choose a reason for hiding this comment

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

Let's put this through now and we'll come back to the issue of weights later, if we're lucky no one's saved models are broken by this anyway.

@KumoLiu
Copy link
Contributor Author

KumoLiu commented Jul 23, 2024

I have checked this with Eric. The only concern we have is in selfattention.py, when you add the CrossAttention block as an attribute by default, it might lead to incompatibilities when loading the module weights from old models, as weights are expected to be there unless you choose strict=False

Yes, it will potential be an issue, may need to add a load_old_state_dict as @ericspod suggested to fix the loading issue.

@KumoLiu KumoLiu enabled auto-merge (squash) July 23, 2024 17:15
@KumoLiu KumoLiu merged commit 37917e0 into Project-MONAI:dev Jul 23, 2024
28 checks passed
@KumoLiu KumoLiu deleted the fix-vit branch July 24, 2024 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Module 'SABlock' has no attribute 'causal_mask'
3 participants