-
Notifications
You must be signed in to change notification settings - Fork 118
Add Qwen3 model support #423
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
Open
nyo16
wants to merge
26
commits into
elixir-nx:main
Choose a base branch
from
nyo16:qwen3-dense-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
8adaf2e
Add Qwen3 model support
nyo16 0499d71
Add last token pooling support for Qwen3-Embedding models
nyo16 1d92e9e
Add Qwen3 embedding architecture and instruction prompts support
nyo16 47c337d
Add .lexical/ to gitignore and IEx usage guide
nyo16 6f68d8f
mix format and rebuilding lock
nyo16 5641a4f
Add Qwen3-Reranker support and example
nyo16 fa592c3
Organize Qwen3 examples into dedicated folder
nyo16 8208efd
Address PR review feedback for Qwen3 support
1f24cc6
Fix Qwen3 layer naming for Layers.Transformer.blocks
cb181f3
Map qwen3 model type to :qwen2 tokenizer type
1651488
Add comprehensive Qwen3 notebook with examples
c02c295
Add instruction format to embeddings example in Qwen3 notebook
bd19c79
Add Qwen3 model tests with reference values
8d787ee
Fix Qwen3 embedding pooling to use attention mask instead of pad_toke…
nyo16 a1923e1
Add :for_reranker architecture for Qwen3
nyo16 0f271b5
Address PR #423 review comments: simple fixes
nyo16 66e2a1b
Update lib/bumblebee/text/pre_trained_tokenizer.ex
nyo16 81285e7
Merge branch 'qwen3-dense-support' of github.com:nyo16/bumblebee into…
nyo16 1e189b8
Merge branch 'main' into qwen3-dense-support
nyo16 cc92ccc
Rename text_reranking to text_reranking_qwen3
nyo16 660ef1b
Remove :for_reranker architecture, use :for_causal_language_modeling
nyo16 9fccfaa
Fix syntax error and document :last_token_pooling option
b289b75
Make query_norm and key_norm always functions
7604f42
Fix duplicate rotary_embedding key in transformer blocks
7a7eb93
Update Qwen3 tests to use bumblebee-testing models
bd4f915
run formatter
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -385,6 +385,9 @@ defmodule Bumblebee.Text do | |
| Note that we currently assume that the CLS token is the first token | ||
| in the sequence | ||
|
|
||
| * `:last_token_pooling` - takes the embedding for the last non-padding | ||
| token in each sequence | ||
|
|
||
| By default no pooling is applied | ||
|
|
||
| * `:embedding_processor` - a post-processing step to apply to the | ||
|
|
@@ -444,6 +447,49 @@ defmodule Bumblebee.Text do | |
| defdelegate text_embedding(model_info, tokenizer, opts \\ []), | ||
| to: Bumblebee.Text.TextEmbedding | ||
|
|
||
| @type text_reranking_qwen3_input :: {String.t(), String.t()} | [{String.t(), String.t()}] | ||
| @type text_reranking_qwen3_output :: %{ | ||
| scores: text_reranking_qwen3_score() | list(text_reranking_qwen3_score()) | ||
| } | ||
| @type text_reranking_qwen3_score :: %{score: number(), query: String.t(), document: String.t()} | ||
|
|
||
| @doc """ | ||
| Builds a serving for text reranking with Qwen3 reranker models. | ||
|
|
||
| The serving expects input in one of the following formats: | ||
|
|
||
| * `{query, document}` - a tuple with query and document text | ||
| * `[{query1, doc1}, {query2, doc2}, ...]` - a list of query-document pairs | ||
|
|
||
| ## Options | ||
|
|
||
| See `Bumblebee.Text.TextRerankingQwen3.text_reranking_qwen3/3` for available options. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| ## Examples | ||
|
|
||
| {:ok, model_info} = Bumblebee.load_model({:hf, "Qwen/Qwen3-Reranker-0.6B"}) | ||
| {:ok, tokenizer} = Bumblebee.load_tokenizer({:hf, "Qwen/Qwen3-Reranker-0.6B"}) | ||
|
|
||
| serving = Bumblebee.Text.text_reranking_qwen3(model_info, tokenizer) | ||
|
|
||
| query = "What is the capital of France?" | ||
| documents = [ | ||
| "Paris is the capital of France.", | ||
| "Berlin is the capital of Germany." | ||
| ] | ||
|
|
||
| pairs = Enum.map(documents, &{query, &1}) | ||
| Nx.Serving.run(serving, pairs) | ||
|
|
||
| """ | ||
| @spec text_reranking_qwen3( | ||
| Bumblebee.model_info(), | ||
| Bumblebee.Tokenizer.t(), | ||
| keyword() | ||
| ) :: Nx.Serving.t() | ||
| defdelegate text_reranking_qwen3(model_info, tokenizer, opts \\ []), | ||
| to: Bumblebee.Text.TextRerankingQwen3 | ||
|
|
||
| @type fill_mask_input :: String.t() | ||
| @type fill_mask_output :: %{predictions: list(fill_mask_prediction())} | ||
| @type fill_mask_prediction :: %{score: number(), token: String.t()} | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
There is no
Qwen3ForEmbeddingin HF transformers, so we can remove this, and the:for_embeddingarchitecture.