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

Fix bug in BEiT adapters #439

Merged
merged 1 commit into from
Oct 27, 2022

Conversation

jannik-brinkmann
Copy link

This pull request fixes a bug in the BEiT adapter implementation, which I contributed in the first place. Although the tests were successful and the model converged on the test data set, during latest experimentation I became aware that the model in Adapter-Transformers, when it was not equipped with adapters, did output different embeddings than the original HF-Transformers model, which is obviously not intended. The bug fix contains two changes:

  • Move the attention adapters call to the first residual connection, instead of calling it before lambda_1.
  • Move the output adapters call into BeitLayer. In contrast to e.g. ViT it cannot be called in Output, due to the necessary lambda_2 and drop_path calls in BeitLayer before adapters need to be called.

This ensures that the model without adapters has the same output as the original HF-Transformers model it is built upon. In addition, I observed a significantly faster convergence on the same training data set as before (EuroSAT): previously it achieved 88 % accuracy after 10 epochs, now it achieves 97.4 % accuracy after 1 epoch and 98.2 % accuracy after 3 epochs. The newly observed convergence rate is similar to that of ViT with adapters.

Changes to be committed:
	modified:   src/transformers/adapters/mixins/beit.py
	modified:   src/transformers/models/beit/modeling_beit.py
@calpt calpt self-requested a review October 27, 2022 08:54
Copy link
Member

@calpt calpt left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the detailed investigation on this and the bug fix!

@calpt calpt merged commit 2aa1d36 into adapter-hub:master Oct 27, 2022
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