3432 remove einops and let vit support torchscript#3433
3432 remove einops and let vit support torchscript#3433yiheng-wang-nv wants to merge 1 commit intoProject-MONAI:devfrom
Conversation
Signed-off-by: Yiheng Wang <[email protected]>
|
Hi Yiheng, is it possible to keep the einops implementation? It seems it's pytorch layers support TS and it has a much better readability. Cc @ahatamiz |
|
Is it possible to close this PR ? : (1) einpos is compatible with TS (2) we certainly should not impose such huge breaking changes. |
|
@yiheng-wang-nv Please check here: The support is also indicated here: |
Hi @ahatamiz , I'm confused about the comments, why do you say "huge breaking changes"? Does the network structure change? In addition, can you point out which changes impact the backward compatibility? Thanks. |
|
I did not change the existing test cases, and none of them failed. Therefore, if this PR brings huge breaking changes, is it proved that the current test cases are incomplete? The purpose of this PR is to solve the torchscript error in https://github.com/Project-MONAI/MONAI/runs/4383941246?check_suite_focus=true#step:10:8707 |
|
Would be nice if both einops and torchscript are supported and included here... |
|
Hi @ahatamiz , this is a simplified code that can test if torchscript works on |
|
ok, looks like it's difficult if we don't specify the dimensionality in advance |
Test cases are not incomplete. But if einops is removed, models trained with older versions will not be compatible with this new version. In addition, it needs to be investigated whether your new implementation changes the behavior of patch embedding or not. I suggest closing this PR. |
@yiheng-wang-nv did you check here where we use Torchscript for UNETR? |
|
Maybe you look at this: torchscript works on |
Hi @ahatamiz , I double checked the einops library, and I'm sure I used the latest release (0.3.2), but it cannot support torchscript. Can you have a try first? |
|
The link you set
Hi @ahatamiz , I'm sure the changes will not impact the behavior. Yes, the new state dict is not 100% the same as the old version. The reason is that in patch embedding, a The old trained weights can still be used, and the output of the network is exactly the same. Therefore, I admit that this PR brings breaking changes, but I do not think that it is: As I said, the purpose is to solve the torchscript error in https://github.com/Project-MONAI/MONAI/runs/4383941246?check_suite_focus=true#step:10:8707 I did not know |
|
Another idea would be having a system-wide configuration flag, to indicate whether we start a torchscriptable instance of the network with reduced functionality/readability. |
|
Hi @yiheng-wang-nv and @wyli Thanks for the comments. Unfortunately, there is no such as a concept as huge or small breaking change ( my bad to mention in that way earlier). A breaking change, no matter what it is, will disrupt the continuity of MONAI and hence shall be avoided unless absolutely necessary. @yiheng-wang-nv I like the fix you proposed for enabling the use of old weights with this version, but I doubt that all users from previous versions can adopt it correctly (some users may not be aware of this post or any announcements we make as a migrations guide). I am also surprised that you mention einops still does not support Torchscript despite the provided links. I will look into it to see what can cause the issue you are facing. Overall, I believe we need a wider discussion with the group to avoid these situations. Maybe we need better CI/CD pipelines. At this point, I don't believe we still have agreed upon a solution regarding this. |
|
Thanks for the great discussions!
Thanks in advance. |
|
|
Thanks @ericspod for the discussion. Thanks in advance. |
|
Hi @Nic-Ma Thanks for the efforts. I hope you and @wyli can review and comment on this PR. If you believe something needs to be changed in any ways, please feel free to address it based on guidelines and policies. As such, I don't have any further suggestions or recommendations for this PR. Thanks P.S: The einops is still supported by TorchScript and this can be acheived, however I leave the final decision to the discretion of other reviewers of this PR. |
|
New comments: |
Looks like the new version is released, shall we revisit this ticket? https://github.com/arogozhnikov/einops/releases/tag/v0.4.0 |
|
Hi @ahatamiz , Could you please help take a look? Thanks in advance. |
|
I think Ali is currently busy, @yiheng-wang-nv could you please help try to reenable this test https://github.com/yiheng-wang-nv/MONAI/blob/19e39562bdb70b68bd251bc1a524050586789c5a/tests/test_vit.py#L138 |
|
Hi @wyli , sure, I'll update this PR today |

Signed-off-by: Yiheng Wang [email protected]
Fixes #3432 .
Description
This PR makes ViT supports torchscript via:
Status
Ready
Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests.make htmlcommand in thedocs/folder.