feat: add GPU/XPU support to fastembed rankers via model_kwargs - #3728
Open
chinyixiang wants to merge 4 commits into
Open
feat: add GPU/XPU support to fastembed rankers via model_kwargs#3728chinyixiang wants to merge 4 commits into
model_kwargs#3728chinyixiang wants to merge 4 commits into
Conversation
Contributor
|
Heads-up for maintainers This PR is from a fork and touches integrations whose integration tests require API keys. Affected integrations:
Please run the integration tests locally ( |
Contributor
Coverage report (fastembed)Click to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||
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.
Related Issues
Proposed Changes:
The fastembed library supports GPU acceleration through its
providers,cuda, anddevice_idsconstructor arguments (backed by ONNX Runtime execution providers). Previously, only the four
embedder components exposed this via
model_kwargs. The two ranker components —FastembedRankerandFastembedLateInteractionRanker— were hardcoded to the CPU path with noway to opt into GPU execution.
This PR is to enable gpu execution path for both
FastembedRankerandFastembedLateInteractionRankerFastembedRankerandFastembedLateInteractionRanker(integrations/fastembed/src/.../rankers/):model_kwargs: dict[str, Any] | None = Noneparameter to__init__self.model_kwargs, serialized into_dict, deserialized via the existingdefault_from_dictpath**model_kwargsinto the underlyingTextCrossEncoder/LateInteractionTextEmbeddingconstructor in
warm_up(), enabling any ONNX Runtime execution providerFastembedTextEmbedderandFastembedDocumentEmbedder(integrations/fastembed/src/.../embedders/)::param model_kwargs:docstring to mentionOpenVINOExecutionProvideralongsideCUDAExecutionProvider(upstream only documented CUDA)Users can now select the execution backend at component construction time:
The
providerskey is the recommended path. The fastembed library also acceptscuda=True/device_ids=[0, 1]as shorthand for single- or multi-GPU CUDA setups; these work throughmodel_kwargsas well.How did you test it?
hatch run fmt— all checks passed, 23 files unchangedhatch run test:types— no issues found in 10 source fileshatch run test:unit— 84 passed, 10 deselected (integration tests, expected)New unit tests added for both rankers:
test_init_with_model_kwargs_parameters— verifies the param is stored correctlytest_to_dict_with_custom_init_parameters— verifiesmodel_kwargsround-trips through serializationtest_from_dict_with_custom_init_parameters— verifies deserialization restoresmodel_kwargstest_warm_up_forwards_model_kwargs— verifiesmodel_kwargsis actually unpacked and passed tothe underlying fastembed model constructor (the key correctness test)
Notes for the reviewer
model_kwargspattern is identical to what the four embedder components already use —this change extends it to the two rankers that were missing it.
FastembedSparseTextEmbedder,FastembedSparseDocumentEmbedder) alsoexpose
model_kwargsbut for BM25 tuning parameters (k,b,avg_len,language), notexecution providers — those were intentionally left untouched.
from fastembed import LateInteractionTextEmbedding(fastembed re-exports it dynamically) is not introduced by this PR — it exists on the unchanged
upstream file and is confirmed to work at runtime.
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:.