使用 GPU 支持运行 Qdrant

从 v1.13.0 版本开始,Qdrant 提供 GPU 加速支持。

但是,由于额外的依赖和库,GPU 支持不包含在默认的 Qdrant 二进制文件中。相反,您需要使用带有 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 支持,请确保您的主机上已安装以下组件:

Amazon/GCP 上的大多数 AI 或 CUDA 镜像都预先配置了 NVIDIA container toolkit。

带有 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 Releases 页面安装最新版本的 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,您需要设置 enable 标志。示例如下:

# `--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 以千字节(KiloBytes)为单位指定。

此页面有用吗?

感谢您的反馈!🙏

得知您不满意我们很抱歉。😔 您可以在 GitHub 上编辑此页面,或者创建一个 GitHub issue。