Add bidirectional attention support to Gemma 3 - #468
Merged
Merged
Conversation
Member
|
Please rebase on top of main, and then we can merge this. |
dkuku
force-pushed
the
feature/gemma3-bidirectional
branch
from
September 30, 2026 17:27
d78e616 to
dc96970
Compare
Author
|
馃憤馃徎 Done |
This was referenced Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for bidirectional attention in
Bumblebee.Text.Gemma3Text.Motivation
In
huggingface/transformers,Gemma3TextConfigintroduces theuse_bidirectional_attentionboolean configuration option. When set totrue, the model uses non-causal (bidirectional) attention across all layers rather than causal masking. This is required for embedding and encoder tasks built on top of the Gemma 3 backbone (such asEmbeddingGemma).Changes
:use_bidirectional_attentionoption (defaulting tofalse) toBumblebee.Text.Gemma3Text.causal: not spec.use_bidirectional_attentionwhen building transformer blocks.use_bidirectional_attentioninBumblebee.HuggingFace.Transformers.Config.load/2.test/bumblebee/text/gemma3_text_test.exswith reference values generated from Pythontransformers.Reference verification (Python)
Output verified against PyTorch
transformerswithatol: 1.0e-4usingbumblebee-testing/tiny-random-Gemma3TextModel: