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
Add Data2Vec for Vision in TF #17008
Conversation
The documentation is not available anymore as the PR was closed or merged. |
I used these steps for styling: #16255 (comment). On my end, when I am running
The CI console is also suggestive of this change. Should I add these cleaned files to the PR? |
Make sure you update |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thanks a lot for adding this model in TensorFlow!
src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
Outdated
Show resolved
Hide resolved
src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
Outdated
Show resolved
Hide resolved
src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
Outdated
Show resolved
Hide resolved
src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
Outdated
Show resolved
Hide resolved
src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
Outdated
Show resolved
Hide resolved
@sgugger I see that |
You'll probably need to rebase your PR on master to get the changes in the setup for the quality check to pass (otherwise the CI uses the cached installed libraries). |
Thanks, @sgugger! I first rebased my main with the upstream and then merged the main into the PR branch. And then I force-pushed. Let's see. |
Hi, @sayakpaul
please? 🙏 Thank you! |
@ydshieh after rebasing, won't I need to merge the main into my PR branch so that it has the full effect? |
In order to incorporate the changes in main into your PR branch, you can either use Once you have latest changes from upstream main in your local main, you can checkout to your PR branch, and do something like
(sometimes there might be conflicts to fix, but I think there won't be conflict in this case) Then you will have to force push. |
@ydshieh oops looks like I have made things worse instead of making them work. I am not sure how I can revert to a mergeable state now. Any suggestion? |
Let me give it a try - I am definitely NOT a Git Pro 😢 Could you let me know what steps you have done, please? |
I just followed your suggestions:
I think you mistakenly made a push to my PR branch which is what may have caused the unnecessary changes to reflect in this PR. I am happy to work on the necessary steps per your suggestions too. |
Currently, the follow checkpoint crashes (after the two suggestions I have made on the PR):
Same for "facebook/data2vec-vision-large", therefore I can't convert those checkpoints (and it looks like something needs fixing?) Here is the traceback:
I have converted |
@sgugger thanks for providing the update. Let me check from my end once. |
@sgugger should be all good now. I have verified from my end too: |
Can confirm it works. TF weights added for all 4 facebook Data2Vec Image models. |
@sgugger thanks! I have also run the tests on my end locally, they're passing. Over to you. |
Repinging @Rocketknight1 to have another set of eyes on this :-) |
src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sayakpaul for this work!
I will review the part regarding the test more thoroughly today, but so far having 2 questions.
src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
Outdated
Show resolved
Hide resolved
src/transformers/models/data2vec/modeling_tf_data2vec_vision.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the model code looks very solid! I had some comments but they've already been addressed, so I'm happy to approve this once tests are green.
Thanks! Looks like they are all green now. |
Thanks again for your contribution! |
* add utilities till TFData2VecVisionLayer. * chore: pass window_size to attention layer. * feat: add TFData2VecVisionRelativePositionBias. * feat: initial implementation ready for tf data2vec. * fix: relative position bias index, table to be fixed. * chore: implementation added, tests remaining. * add: tests, other PR files. * fix: code quality. * fix: import structure in init. * chore: run make fix-copies. * chore: address PR feedback (round I). * chore: styling nit. * fix: tests due to removal of to_2tuple(). * chore: rebase with upstream main and move the test. * Update src/transformers/models/auto/modeling_tf_auto.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * Update src/transformers/models/auto/modeling_tf_auto.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * fix: layer call. * chore: remove from_pt=True and rerun test. * chore: remove cast and tf.divide. * chore: minor edits to the test script. * Update src/transformers/models/data2vec/modeling_tf_data2vec_vision.py Co-authored-by: Matt <Rocketknight1@users.noreply.github.com> * fix: expand() on TF tensors with broadcast_to(). * fix: test import. Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>
* add utilities till TFData2VecVisionLayer. * chore: pass window_size to attention layer. * feat: add TFData2VecVisionRelativePositionBias. * feat: initial implementation ready for tf data2vec. * fix: relative position bias index, table to be fixed. * chore: implementation added, tests remaining. * add: tests, other PR files. * fix: code quality. * fix: import structure in init. * chore: run make fix-copies. * chore: address PR feedback (round I). * chore: styling nit. * fix: tests due to removal of to_2tuple(). * chore: rebase with upstream main and move the test. * Update src/transformers/models/auto/modeling_tf_auto.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * Update src/transformers/models/auto/modeling_tf_auto.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * fix: layer call. * chore: remove from_pt=True and rerun test. * chore: remove cast and tf.divide. * chore: minor edits to the test script. * Update src/transformers/models/data2vec/modeling_tf_data2vec_vision.py Co-authored-by: Matt <Rocketknight1@users.noreply.github.com> * fix: expand() on TF tensors with broadcast_to(). * fix: test import. Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>
* add utilities till TFData2VecVisionLayer. * chore: pass window_size to attention layer. * feat: add TFData2VecVisionRelativePositionBias. * feat: initial implementation ready for tf data2vec. * fix: relative position bias index, table to be fixed. * chore: implementation added, tests remaining. * add: tests, other PR files. * fix: code quality. * fix: import structure in init. * chore: run make fix-copies. * chore: address PR feedback (round I). * chore: styling nit. * fix: tests due to removal of to_2tuple(). * chore: rebase with upstream main and move the test. * Update src/transformers/models/auto/modeling_tf_auto.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * Update src/transformers/models/auto/modeling_tf_auto.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * fix: layer call. * chore: remove from_pt=True and rerun test. * chore: remove cast and tf.divide. * chore: minor edits to the test script. * Update src/transformers/models/data2vec/modeling_tf_data2vec_vision.py Co-authored-by: Matt <Rocketknight1@users.noreply.github.com> * fix: expand() on TF tensors with broadcast_to(). * fix: test import. Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>
* add utilities till TFData2VecVisionLayer. * chore: pass window_size to attention layer. * feat: add TFData2VecVisionRelativePositionBias. * feat: initial implementation ready for tf data2vec. * fix: relative position bias index, table to be fixed. * chore: implementation added, tests remaining. * add: tests, other PR files. * fix: code quality. * fix: import structure in init. * chore: run make fix-copies. * chore: address PR feedback (round I). * chore: styling nit. * fix: tests due to removal of to_2tuple(). * chore: rebase with upstream main and move the test. * Update src/transformers/models/auto/modeling_tf_auto.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * Update src/transformers/models/auto/modeling_tf_auto.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * fix: layer call. * chore: remove from_pt=True and rerun test. * chore: remove cast and tf.divide. * chore: minor edits to the test script. * Update src/transformers/models/data2vec/modeling_tf_data2vec_vision.py Co-authored-by: Matt <Rocketknight1@users.noreply.github.com> * fix: expand() on TF tensors with broadcast_to(). * fix: test import. Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>
This PR adds the data2vec [1] model for vision in TensorFlow.
Todo:
* Fix cross-loading.* Add integration test.* Add remaining tests.* Rest of the files remaining for the PR.* TF weight uploading to Hub (to be done by someone from the 🤗 team)Notes
...ForSegmentation
. This can be done in a separate PR I think.RUN_SLOW=1 python -m pytest tests/data2vec/test_modeling_tf_data2vec_vision.py
.References
[1] data2vec: https://arxiv.org/abs/2202.03555
@sgugger @Rocketknight1 @ydshieh