使用 GPU 支持运行 Qdrant
从 v1.13.0 版本开始,Qdrant 提供 GPU 加速支持。
然而,由于额外的依赖项和库,默认的 Qdrant 二进制文件中不包含 GPU 支持。你需要使用带有 GPU 支持的专用 Docker 镜像(NVIDIA、AMD)。
配置
Qdrant 包含许多配置选项来控制 GPU 使用。以下选项可用:
gpu:
# Enable GPU indexing.
indexing: false
# Force half precision for `f32` values while indexing.
# `f16` conversion will take place
# only inside GPU memory and won't affect storage type.
force_half_precision: false
# Used vulkan "groups" of GPU.
# In other words, how many parallel points can be indexed by GPU.
# Optimal value might depend on the GPU model.
# Proportional, but doesn't necessary equal
# to the physical number of warps.
# Do not change this value unless you know what you are doing.
# Default: 512
groups_count: 512
# Filter for GPU devices by hardware name. Case insensitive.
# Comma-separated list of substrings to match
# against the gpu device name.
# Example: "nvidia"
# Default: "" - all devices are accepted.
device_filter: ""
# List of explicit GPU devices to use.
# If host has multiple GPUs, this option allows to select specific devices
# by their index in the list of found devices.
# If `device_filter` is set, indexes are applied after filtering.
# By default, all devices are accepted.
devices: null
# How many parallel indexing processes are allowed to run.
# Default: 1
parallel_indexes: 1
# Allow to use integrated GPUs.
# Default: false
allow_integrated: false
# Allow to use emulated GPUs like LLVMpipe. Useful for CI.
# Default: false
allow_emulated: false
除非你熟悉 Qdrant 内部结构和 Vulkan API,否则不建议更改这些选项。
独立 GPU 支持
对于独立使用,你可以通过运行以下命令来构建支持 GPU 的 Qdrant:
cargo build --release --features gpu
确保你的设备支持 Vulkan API v1.3。这包括与 Apple Silicon、Intel GPU 和 CPU 模拟器的兼容性。请注意,你必须在配置中设置 gpu.indexing: true 才能在运行时使用 GPU。
NVIDIA GPU
先决条件
要将 Docker 与 NVIDIA GPU 支持结合使用,请确保主机上安装了以下内容:
- 最新的 NVIDIA 驱动程序
- nvidia-container-toolkit
Amazon/GCP 上的大多数 AI 或 CUDA 镜像都预先配置了 NVIDIA 容器工具包。
支持 NVIDIA GPU 的 Docker 镜像
支持 NVIDIA GPU 的 Docker 镜像使用标签后缀 gpu-nvidia,例如 qdrant/qdrant:v1.13.0-gpu-nvidia。这些镜像包含所有必要的依赖项。
要启用 GPU 支持,请在 Docker 设置中使用 --gpus=all 标志。示例:
# `--gpus=all` flag says to Docker that we want to use GPUs.
# `-e QDRANT__GPU__INDEXING=1` flag says to Qdrant that we want to use GPUs for indexing.
docker run \
--rm \
--gpus=all \
-p 6333:6333 \
-p 6334:6334 \
-e QDRANT__GPU__INDEXING=1 \
qdrant/qdrant:gpu-nvidia-latest
要确保 GPU 正确初始化,你可以在日志中查看。Qdrant 首先打印所有找到的 GPU 设备而不进行过滤,然后打印所有已创建设备的列表。
2025-01-13T11:58:29.124087Z INFO gpu::instance: Found GPU device: NVIDIA GeForce RTX 3090
2025-01-13T11:58:29.124118Z INFO gpu::instance: Found GPU device: llvmpipe (LLVM 15.0.7, 256 bits)
2025-01-13T11:58:29.124138Z INFO gpu::device: Create GPU device NVIDIA GeForce RTX 3090
在这里你可以看到找到了两个设备:RTX 3090 和 llvmpipe(Docker 镜像中包含的 CPU 模拟 GPU)。稍后,你会看到只有 RTX 被初始化。
设置到此结束。现在,你可以开始使用此 Qdrant 实例了。
NVIDIA GPU 故障排除
如果 Docker 中未检测到你的 GPU,请确保你的驱动程序和 nvidia-container-toolkit 是最新的。如果需要,你可以从其 GitHub 发布页面安装最新版本的 nvidia-container-toolkit。
使用以下命令验证 Docker 容器中 Vulkan API 的可见性:
docker run --rm --gpus=all qdrant/qdrant:gpu-nvidia-latest vulkaninfo --summary
系统可能会显示错误消息,解释 NVIDIA 设备不可见的原因。请注意,如果你的 NVIDIA GPU 在 Docker 中不可见,Docker 镜像将无法在你的主机上使用 libGLX_nvidia.so.0。错误消息可能如下所示:
ERROR: [Loader Message] Code 0 : loader_scanned_icd_add: Could not get `vkCreateInstance` via `vk_icdGetInstanceProcAddr` for ICD libGLX_nvidia.so.0
WARNING: [Loader Message] Code 0 : terminator_CreateInstance: Failed to CreateInstance in ICD 0. Skipping ICD.
要解决错误,请更新你的 NVIDIA 容器运行时配置:
sudo nano /etc/nvidia-container-runtime/config.toml
设置 no-cgroups=false,保存配置,然后重新启动 Docker。
sudo systemctl restart docker
AMD GPU
先决条件
使用 AMD GPU 运行 Qdrant 需要在主机上安装 ROCm。
支持 AMD GPU 的 Docker 镜像
AMD GPU 的 Docker 镜像使用标签后缀 gpu-amd,例如 qdrant/qdrant:v1.13.0-gpu-amd。这些镜像包含所有必需的依赖项。
要为 Docker 启用 GPU,你需要额外的 --device /dev/kfd --device /dev/dri 标志。要为 Qdrant 启用 GPU,你需要设置启用标志。示例如下:
# `--device /dev/kfd --device /dev/dri` flags say to Docker that we want to use GPUs.
# `-e QDRANT__GPU__INDEXING=1` flag says to Qdrant that we want to use GPUs for indexing.
docker run \
--rm \
--device /dev/kfd --device /dev/dri \
-p 6333:6333 \
-p 6334:6334 \
-e QDRANT__LOG_LEVEL=debug \
-e QDRANT__GPU__INDEXING=1 \
qdrant/qdrant:gpu-amd-latest
检查日志以确认 GPU 初始化。示例日志输出:
2025-01-10T11:56:55.926466Z INFO gpu::instance: Found GPU device: AMD Radeon Graphics (RADV GFX1103_R1)
2025-01-10T11:56:55.926485Z INFO gpu::instance: Found GPU device: llvmpipe (LLVM 17.0.6, 256 bits)
2025-01-10T11:56:55.926504Z INFO gpu::device: Create GPU device AMD Radeon Graphics (RADV GFX1103_R1)
设置到此结束。在基本情况下,你不需要配置任何其他内容。
已知限制
平台支持:Docker 镜像仅适用于 Linux x86_64。不支持 Windows、macOS、ARM 和其他平台。
内存限制:每个 GPU 每次索引迭代最多可以处理 16GB 的向量数据。
由于此限制,你不应创建原始向量或量化向量大于 16GB 的段。
例如,一个包含 1536d 向量和标量量化的集合最多可以有:
16Gb / 1536 ~= 11 million vectors per segment
并且不进行量化:
16Gb / 1536 * 4 ~= 2.7 million vectors per segment
每个段的最大大小可以在集合设置中配置。使用以下操作来更改现有集合:
PATCH collections/{collection_name}
{
"optimizers_config": {
"max_segment_size": 1000000
}
}
请注意,max_segment_size 以千字节为单位。