-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add example for Optimum integration, fix docs, CI (#526)
* feat: Add example for Optimum integration, fix docs, CI * Apply suggestions from code review Co-authored-by: Stefano Fiorucci <[email protected]> --------- Co-authored-by: Stefano Fiorucci <[email protected]>
- Loading branch information
Showing
9 changed files
with
136 additions
and
97 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,30 +1,24 @@ | ||
# optimum | ||
|
||
[![PyPI - Version](https://img.shields.io/pypi/v/optimum.svg)](https://pypi.org/project/optimum-haystack) | ||
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/optimum.svg)](https://pypi.org/project/optimum-haystack) | ||
[![PyPI - Version](https://img.shields.io/pypi/v/optimum-haystack.svg)](https://pypi.org/project/optimum-haystack) | ||
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/optimum-haystack.svg)](https://pypi.org/project/optimum-haystack) | ||
|
||
----- | ||
--- | ||
|
||
Component to embed strings and Documents using models loaded with the HuggingFace Optimum library. This component is designed to seamlessly inference models using the high speed ONNX runtime. | ||
|
||
**Table of Contents** | ||
|
||
- [Installation](#installation) | ||
- [License](#license) | ||
- [optimum](#optimum) | ||
- [Installation](#installation) | ||
- [License](#license) | ||
|
||
## Installation | ||
|
||
To use the ONNX runtime for CPU, use the CPU version: | ||
```console | ||
pip install optimum-haystack[cpu] | ||
pip install optimum-haystack | ||
``` | ||
|
||
For using the GPU runtimes: | ||
```console | ||
pip install optimum-haystack[gpu] | ||
``` | ||
|
||
|
||
## License | ||
|
||
`optimum-haystack` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license. |
This file contains 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This example requires GPU support to execute. | ||
|
||
from haystack import Pipeline | ||
|
||
from haystack_integrations.components.embedders.optimum import ( | ||
OptimumTextEmbedder, | ||
OptimumEmbedderPooling, | ||
OptimumEmbedderOptimizationConfig, | ||
OptimumEmbedderOptimizationMode, | ||
) | ||
|
||
pipeline = Pipeline() | ||
embedder = OptimumTextEmbedder( | ||
model="intfloat/e5-base-v2", | ||
normalize_embeddings=True, | ||
onnx_execution_provider="CUDAExecutionProvider", | ||
optimizer_settings=OptimumEmbedderOptimizationConfig( | ||
mode=OptimumEmbedderOptimizationMode.O4, | ||
for_gpu=True, | ||
), | ||
working_dir="/tmp/optimum", | ||
pooling_mode=OptimumEmbedderPooling.MEAN, | ||
) | ||
pipeline.add_component("embedder", embedder) | ||
|
||
results = pipeline.run( | ||
{ | ||
"embedder": { | ||
"text": "Ex profunditate antiquae doctrinae, Ad caelos supra semper, Hoc incantamentum evoco, draco apparet, Incantamentum iam transactum est" | ||
}, | ||
} | ||
) | ||
|
||
print(results["embedder"]["embedding"]) |
This file contains 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 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 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 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 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