Repository navigation
Studio: stop loading EmbeddingGemma in float16 in the RAG embedder - #12864
Merged
Merged
Conversation
Member
Author
|
Reached Codex review convergence at oobabooga#337. |
This was referenced Oct 7, 2026
Studio: use llama-server for embedding models the installed sentence-transformers cannot load
#13005
Merged
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.
With
RAG_EMBED_DEVICE=gpu, the sentence-transformers RAG embedder loads every model in float16. EmbeddingGemma does not support that. Its model card says:With
unsloth/embeddinggemma-300mon GPU, a document indexes without an error, and then every search of that knowledge base fails with a 500.Root cause
embeddings._getpicks the dtype from the device alone:"float32" if device == "cpu" else "float16".chunks_vec.store.search_densecomputes1.0 - r["distance"], which raisesTypeError. In chat,build_rag_autoinjectcatches it and logs a warning, so the answer is generated without the documents.Fix
_load_dtype(device, name)keeps float16 on an accelerator, except for models in_FLOAT16_UNSAFE_MODELS, matched as a substring of the lowercased model name. The list holdsembeddinggemma. Those models load in bfloat16 where the device has native bf16 (native_bf16_supported,native_bf16_supported_xpu) and in float32 otherwise.store.search_denseskips rows whose distance is NULL or not finite, so knowledge bases indexed in float16 stop failing the whole search.Behavior that stays as on main:
RAG_EMBED_DEVICE=autostill loads on CPU in float32, every other model still loads in float16 on GPU, and the llama-server backend is untouched.embedding_identitydoes not include the dtype, so existing NaN vectors stay in the index and are skipped. Re-uploading the same file does not replace them, because ingestion deduplicates by content hash; delete the document and upload it again.A fine-tune of EmbeddingGemma whose name does not contain "embeddinggemma" is not matched and still loads in float16.
Testing
Live A/B on an RTX 6000 Ada, with
RAG_EMBED_DEVICE=gpu RAG_EMBED_BACKEND=sentence-transformers RAG_EMBEDDING_MODEL=unsloth/embeddinggemma-300m. Each side created a knowledge base through the API, uploaded a three-sentence text file and searched "Where is the Eiffel Tower?".completedcompletedTypeErrorTypeErrorThe last row ran on the first commit, which had the same
search_densechange; the other rows were repeated on the final commit.test_opted_in_accelerator_loads_float16still passes unchanged. Newtest_float16_unsafe_model_avoids_float16covers EmbeddingGemma on CUDA and XPU, with and without native bf16.test_dense_skips_nan_vectors_instead_of_raisingfails on main with the sameTypeError.test_rag_store.py,test_rag_embeddings.py,test_rag_embedding_identity.pyandtest_rag_embed_llama_server.py: 222 passed.Not tested:
modules.jsondeclares a4_Normalizefolder the repository does not have, so the download is never considered complete.