Skip to content

feat: add BEiT support#1958

Open
aymen-000 wants to merge 5 commits into
lightly-ai:masterfrom
aymen-000:add-beit-support
Open

feat: add BEiT support#1958
aymen-000 wants to merge 5 commits into
lightly-ai:masterfrom
aymen-000:add-beit-support

Conversation

@aymen-000

Copy link
Copy Markdown

Description

This PR adds support for BEiT (BERT Pre-Training of Image Transformers) for masked image modeling to Lightly.

What was added

  • Implemented the BEiT masked image modeling architecture.
  • Added the BEiT image tokenizer.
  • Added the BEiT masking transform.
  • Added the masked image modeling prediction head.
  • Added training examples (single-GPU and distributed).
  • Added notebooks demonstrating BEiT training.
  • Added documentation and API references.
  • Added unit tests covering the new components.

Relation to the existing MAE implementation

While both MAE and BEiT are masked image modeling methods, they differ in their reconstruction targets:

  • MAE reconstructs the raw pixel values of masked image patches.
  • BEiT predicts discrete visual tokens generated by a pretrained image tokenizer instead of reconstructing pixels.

References

Documentation

  • I have updated the documentation.

Tests

  • I have updated the tests.

@liopeer

liopeer commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

/review

@liopeer

liopeer commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Thanks a lot @aymen-000, what a cool contribution! This will probably take a bit of time to review, but we will try to do it as quickly as possible.

@liopeer liopeer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is only an initial review with already some remarks. Will continue over the next few days. 🙂

Comment thread examples/pytorch/beit.py Outdated
Comment thread lightly/models/beit.py Outdated
Comment thread docs/source/examples/beit.rst Outdated
Comment thread lightly/models/modules/__init__.py Outdated
Comment thread lightly/models/modules/__init__.py Outdated
Comment thread examples/pytorch/beit.py
Comment thread examples/pytorch/beit.py Outdated
@aymen-000

Copy link
Copy Markdown
Author

Hi @liopeer thanks for the detailed review! I've addressed the comments:

  • Removed the tokenizer pretraining recipe.
  • Moved the BEiT implementation into the example.
  • Renamed the tokenizer, MIM head, and model class for consistency.
  • Froze the tokenizer parameters and set the tokenizer to evaluation mode.
  • Updated the documentation, including the suggested capitalization fix.

Thanks again! I'll keep an eye out for any additional comments from the rest of the review.

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