Skip to content

6973 sincos pos embed #6986

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

Merged
merged 19 commits into from
Sep 16, 2023
Merged

6973 sincos pos embed #6986

merged 19 commits into from
Sep 16, 2023

Conversation

NoTody
Copy link
Contributor

@NoTody NoTody commented Sep 14, 2023

Fixes #6973

Description

Adding support for sincos positional embedding for monai.networks.blocks.patchembedding.PatchEmbedding class.

This pull request corresponds to this opened issue #6973

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.

@NoTody
Copy link
Contributor Author

NoTody commented Sep 14, 2023

The checks don't pass because they don't include timm package. Do I need to write these functions I used from timm? I included timm in requirements-dev.txt.

@wyli
Copy link
Contributor

wyli commented Sep 15, 2023

Thanks for the PR! looks like only minor utility functions are from timm, perhaps we can drop those for now instead of introducing a new dependency?

Also the argument renaming makes sense, ideally we should keep them backward compatibility as well because it's been used in many places https://github.com/search?q=org%3AProject-MONAI+pos_embed&type=code. For example PatchEmbeddingBlock(patch_embed="conv") should still work in the same way before and after this PR; and module instance PatchEmbeddingBlock(pos_embed="none", patch_embed="conv") can use the model checkpoint trained before this PR with PatchEmbeddingBlock(patch_embed="conv")

@NoTody
Copy link
Contributor Author

NoTody commented Sep 15, 2023

Thanks for the PR! looks like only minor utility functions are from timm, perhaps we can drop those for now instead of introducing a new dependency?

Also the argument renaming makes sense, ideally we should keep them backward compatibility as well because it's been used in many places https://github.com/search?q=org%3AProject-MONAI+pos_embed&type=code. For example PatchEmbeddingBlock(patch_embed="conv") should still work in the same way before and after this PR; and module instance PatchEmbeddingBlock(pos_embed="none", patch_embed="conv") can use the model checkpoint trained before this PR with PatchEmbeddingBlock(patch_embed="conv")

Ok, I can just rewrite these two functions I used from timm.

For the second point, how should I make it backward compatible? Originally, you used pos_embed='conv' to represent patch_embed='conv'. Do you want to remain the same naming and introduce another name for pos_embed='none' or should I deprecate it?

@wyli
Copy link
Contributor

wyli commented Sep 15, 2023

Sure, another way would be marking the original 'pos_embed' as deprecating in monai v1.4.

def deprecated_arg(
then add two options 'pos_embed_type' and 'proj_type' (or something similar), User provided 'pos_embed' is then interpreted as an equivalent of the latter.

@NoTody
Copy link
Contributor Author

NoTody commented Sep 15, 2023

Sure, another way would be marking the original 'pos_embed' as deprecating in monai v1.4.

def deprecated_arg(

then add two options 'pos_embed_type' and 'proj_type' (or something similar), User provided 'pos_embed' is then interpreted as an equivalent of the latter.

Hi, @wyli ,

I modified my pull request accordingly. I'm not sure why "premerge / packaging (pull_request)" don't pass on

Traceback (most recent call last):
  File "/tmp/tmp.hM3vB5K1Tk/tests/test_patchembedding.py", line 130, in test_ill_arg
    PatchEmbeddingBlock(
AssertionError: ValueError not raised

I tested it locally and it was able to raise the error. Could you help me to check?

@wyli
Copy link
Contributor

wyli commented Sep 15, 2023

Ok please sync up the tags to your fork... https://stackoverflow.com/questions/70678073/how-do-i-sync-tags-to-a-forked-github-repo I'll have a look soon.

@wyli
Copy link
Contributor

wyli commented Sep 16, 2023

/build

Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
@wyli
Copy link
Contributor

wyli commented Sep 16, 2023

/build

@wyli
Copy link
Contributor

wyli commented Sep 16, 2023

/build

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, integration tests work fine now, merging for more model tests

@wyli wyli merged commit 281cb01 into Project-MONAI:dev Sep 16, 2023
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.

sincos Positional Embedding
2 participants