Skip to content

[Q] Non-causal / bidirectional attention in decoder models for sentence embeddings #478

Description

@dkuku

While working on sentence transformers support in Bumblebee, I hit an issue running popular decoder-based text embedding models (such as Alibaba-NLP/gte-Qwen2-7B-instruct or fine-tuned Llama/Mistral embedding backbones). These models require non-causal (bidirectional) attention across input tokens.

In #468, :use_bidirectional_attention (default false) was introduced for Gemma3Text, following Gemma3TextConfig.use_bidirectional_attention in huggingface/transformers.

However, in checkpoints for other decoder architectures (like Qwen, Llama, and Mistral), Hugging Face models typically set "is_causal": false in config.json instead of using use_bidirectional_attention.

Before opening a PR, I'd like to ask how you'd prefer to model this in Bumblebee:

  1. Expose :is_causal (default: true):
    Use :is_causal directly on the spec, or accept both and validate against conflicting values in Gemma - https://github.com/huggingface/transformers/blob/469230357aab0f2b303b0d638c1f8d06edb14184/src/transformers/models/gemma3/modeling_gemma3.py#L317.
  2. Unify on :use_bidirectional_attention (default: false):
    Add :use_bidirectional_attention to Shared.common_options/1 across Llama, Mistral, Qwen3, and Gemma 3, map "is_causal": false from HF configs, and validate against conflicting values in shared options.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions