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

Perceiver interpolate position embedding #30979

Merged
merged 8 commits into from
May 24, 2024

Conversation

g1y5x3
Copy link
Contributor

@g1y5x3 g1y5x3 commented May 23, 2024

What does this PR do?

Add interpolate position embedding to Perceiver #30579. Not really sure how to test the correctness of output value since it does change the entire forward pass. However, correctness of output shape is pretty straight forward.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@amyeroberts

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

Just a few small comments

src/transformers/models/perceiver/modeling_perceiver.py Outdated Show resolved Hide resolved
src/transformers/models/perceiver/modeling_perceiver.py Outdated Show resolved Hide resolved
src/transformers/models/perceiver/modeling_perceiver.py Outdated Show resolved Hide resolved
tests/models/perceiver/test_modeling_perceiver.py Outdated Show resolved Hide resolved
src/transformers/models/perceiver/modeling_perceiver.py Outdated Show resolved Hide resolved
inputs: torch.LongTensor,
pos: Optional[torch.Tensor] = None,
network_input_is_1d: bool = True,
interpolate_pos_encoding: bool = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

The argument doesn't appear to be used in this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I ran the test, TextPreprocesor and AudioPreprocessor didn't fail but only MutimodalPreprocessor did so I missed those. Just added.

Copy link
Collaborator

Choose a reason for hiding this comment

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

interpolate_pos_encoding still isn't used in this method., or the one for PerceiverAudioPreprocessor. Is this for providing a consistent signature?

src/transformers/models/perceiver/modeling_perceiver.py Outdated Show resolved Hide resolved
src/transformers/models/perceiver/modeling_perceiver.py Outdated Show resolved Hide resolved
src/transformers/models/perceiver/modeling_perceiver.py Outdated Show resolved Hide resolved
@g1y5x3 g1y5x3 force-pushed the perceiver_inter_pos_embed branch from 9a55e50 to 2891e0d Compare May 23, 2024 17:57
@g1y5x3
Copy link
Contributor Author

g1y5x3 commented May 23, 2024

Thanks for the review, I have addressed the comments. Turns out after working on the no longer needed DETR, it makes sorting through the code path of a different model much faster.

@g1y5x3 g1y5x3 requested a review from amyeroberts May 23, 2024 18:03
inputs: torch.LongTensor,
pos: Optional[torch.Tensor] = None,
network_input_is_1d: bool = True,
interpolate_pos_encoding: bool = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

interpolate_pos_encoding still isn't used in this method., or the one for PerceiverAudioPreprocessor. Is this for providing a consistent signature?

Comment on lines 871 to +874
if self.input_preprocessor is not None:
inputs, modality_sizes, inputs_without_pos = self.input_preprocessor(inputs)
inputs, modality_sizes, inputs_without_pos = self.input_preprocessor(
inputs, interpolate_pos_encoding=interpolate_pos_encoding
)
Copy link
Contributor Author

@g1y5x3 g1y5x3 May 23, 2024

Choose a reason for hiding this comment

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

@amyeroberts since self.input_processor here could also be either TextPreprocessor or MultimodalPreprosessor, it would complain got unexpected keyword argument if it was not added to the forward() of those two corresponding methods. Alternatively, maybe we could add another condition here to call self.input_processor with just two arguments unless it is ImagePreprocessor?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, that's OK, I just wanted to make sure that this was deliberate

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for adding this!

@amyeroberts amyeroberts merged commit 42d8dd8 into huggingface:main May 24, 2024
18 checks passed
itazap pushed a commit that referenced this pull request May 24, 2024
* add test that currently fails

* test passed

* all perceiver passed

* fixup, style, quality, repo-consistency, all passed

* Apply suggestions from code review: default to False + compute sqrt once only

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

* fix a minor bracket

* replace dim with self._num_channels

* add arguments to the rest preprocessors

---------

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
@g1y5x3 g1y5x3 deleted the perceiver_inter_pos_embed branch May 24, 2024 14:46
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request Jun 11, 2024
* add test that currently fails

* test passed

* all perceiver passed

* fixup, style, quality, repo-consistency, all passed

* Apply suggestions from code review: default to False + compute sqrt once only

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

* fix a minor bracket

* replace dim with self._num_channels

* add arguments to the rest preprocessors

---------

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.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.

2 participants