-
Notifications
You must be signed in to change notification settings - Fork 179
new: Added multi-gpu example #422
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| { | ||
hh-space-invader marked this conversation as resolved.
Show resolved
Hide resolved
hh-space-invader marked this conversation as resolved.
Show resolved
Hide resolved
hh-space-invader marked this conversation as resolved.
Show resolved
Hide resolved
hh-space-invader marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "### Fastembed Multi-GPU Tutorial\n", | ||
| "This tutorial demonstrates how to leverage multi-GPU support in Fastembed. Fastembed supports embedding text and images utilizing modern GPUs for acceleration. Let's explore how to use Fastembed with multiple GPUs step by step." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "#### Prerequisites\n", | ||
| "To get started, ensure you have the following installed:\n", | ||
| "- Python 3.9 or later\n", | ||
| "- Fastembed (`pip install fastembed-gpu`)\n", | ||
| "- Refer to [this](https://github.com/qdrant/fastembed/blob/main/docs/examples/FastEmbed_GPU.ipynb) tutorial if you have issues with GPU dependencies\n", | ||
| "- Access to a multi-GPU server" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "### Multi-GPU using cuda argument with TextEmbedding Model" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from fastembed import TextEmbedding\n", | ||
| "\n", | ||
| "# define the documents to embed\n", | ||
| "docs = [\"hello world\", \"flag embedding\"] * 100\n", | ||
| "\n", | ||
| "# define gpu ids\n", | ||
| "device_ids = [0, 1]\n", | ||
| "\n", | ||
| "if __name__ == \"__main__\":\n", | ||
| " # initialize a TextEmbedding model using CUDA\n", | ||
| " text_model = TextEmbedding(\n", | ||
| " model_name=\"sentence-transformers/all-MiniLM-L6-v2\",\n", | ||
| " cuda=True,\n", | ||
| " device_ids=device_ids,\n", | ||
| " lazy_load=True,\n", | ||
| " )\n", | ||
| "\n", | ||
| " # generate embeddings\n", | ||
| " text_embeddings = list(text_model.embed(docs, batch_size=2, parallel=len(device_ids)))\n", | ||
| " print(text_embeddings)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "In this snippet:\n", | ||
| "- `cuda=True` enables GPU acceleration.\n", | ||
| "- `device_ids=[0, 1]` specifies GPUs to use. Replace `[0, 1]` with available GPU IDs.\n", | ||
| "- `lazy_load=True`\n", | ||
| "\n", | ||
| "**NOTE**: When using multi-GPU settings, it is important to configure `parallel` and `lazy_load` properly to avoid inefficiencies:\n", | ||
| "\n", | ||
| "`parallel`: This parameter enables multi-GPU support by spawning child processes for each GPU specified in device_ids. To ensure proper utilization, the value of `parallel` must match the number of GPUs in device_ids. If using a single GPU, this parameter is not necessary.\n", | ||
| "\n", | ||
| "`lazy_load`: Enabling `lazy_load` prevents redundant memory usage. Without `lazy_load`, the model is initially loaded into the memory of the first GPU by the main process. When child processes are spawned for each GPU, the model is reloaded on the first GPU, causing redundant memory consumption and inefficiencies." | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": ".venv", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "name": "python", | ||
| "version": "3.10.15" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 2 | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.