使用xinference部署自定义embedding模型(docker)

2024-08-28 15:12

本文主要是介绍使用xinference部署自定义embedding模型(docker),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

使用xinference部署自定义embedding模型(docker)

说明:

  • 首次发表日期:2024-08-27
  • 官方文档: https://inference.readthedocs.io/zh-cn/latest/index.html

使用docker部署xinference

FROM nvcr.io/nvidia/pytorch:23.10-py3# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1RUN python3 -m pip uninstall -y transformer-engine
RUN python3 -m pip install --upgrade pipRUN python3 -m pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --no-cache-dir --index-url https://download.pytorch.org/whl/cu121# If there are network issue, you can download torch whl file and use it
# ADD torch-2.3.0+cu121-cp310-cp310-linux_x86_64.whl /root/torch-2.3.0+cu121-cp310-cp310-linux_x86_64.whl
# RUN python3 -m pip install /root/torch-2.3.0+cu121-cp310-cp310-linux_x86_64.whlRUN python3 -m pip install packaging setuptools==69.5.1 --no-cache-dir -i https://mirror.baidu.com/pypi/simple
RUN python3 -m pip install -U ninja --no-cache-dir -i https://mirror.baidu.com/pypi/simple
RUN python3 -m pip install flash-attn==2.5.8 --no-build-isolation --no-cache-dir
RUN python3 -m pip install "xinference[all]" --no-cache-dir -i https://repo.huaweicloud.com/repository/pypi/simpleEXPOSE 80CMD ["sh", "-c", "tail -f /dev/null"]

构建镜像

docker build -t myxinference:latest .

参照 https://inference.readthedocs.io/zh-cn/latest/getting_started/using_docker_image.html#mount-your-volume-for-loading-and-saving-models 部署docker服务

另外,如果使用huggingface的话,建议使用 https://hf-mirror.com/ 镜像(记得docker部署时设置HF_ENDPOINT环境变量)。

以下假设部署后的服务地址为 http://localhost:9997

部署自定义 embedding 模型

准备embedding模型自定义JSON文件

创建文件夹custom_models/embedding

mkdir -p custom_models/embedding

然后创建以下模型自定义JSON文件:

360Zhinao-search.json:

{"model_name": "360Zhinao-search","dimensions": 1024,"max_tokens": 512,"language": ["en", "zh"],"model_id": "qihoo360/360Zhinao-search","model_format": "pytorch"
}

gte-Qwen2-7B-instruct.json

{"model_name": "gte-Qwen2-7B-instruct","dimensions": 4096,"max_tokens": 32768,"language": ["en", "zh"],"model_id": "Alibaba-NLP/gte-Qwen2-7B-instruct","model_format": "pytorch"
}

zpoint_large_embedding_zh.json:

{"model_name": "zpoint_large_embedding_zh","dimensions": 1792,"max_tokens": 512,"language": ["zh"],"model_id": "iampanda/zpoint_large_embedding_zh","model_format": "pytorch"
}

注意:对于下载到本地的模型可以设置 model_uri参数,例如 “[file:///path/to/llama-2-7b](file:///path/to/llama-2-7b)”。

注册自定义 embedding 模型

xinference register --model-type embedding --file custom_models/embedding/360Zhinao-search.json --persist --endpoint http://localhost:9997xinference register --model-type embedding --file custom_models/embedding/gte-Qwen2-7B-instruct.json --persist --endpoint http://localhost:9997xinference register --model-type embedding --file custom_models/embedding/zpoint_large_embedding_zh.json --persist --endpoint http://localhost:9997

启动自定义 embedding 模型

xinference launch --model-type embedding --model-name gte-Qwen2-7B-instruct --model-engine transformers  --model-format pytorch --endpoint http://localhost:9997xinference launch --model-type embedding --model-name 360Zhinao-search --model-engine transformers  --model-format pytorch --endpoint http://localhost:9997xinference launch --model-type embedding --model-name zpoint_large_embedding_zh --model-engine transformers  --model-format pytorch --endpoint http://localhost:9997

启动bge-m3和bge-reranker-base模型

bge-m3和bge-reranker-base是比较常用的embedding模型和reranking模型。

xinference launch --model-name bge-m3 --model-type embedding --endpoint http://localhost:9997xinference launch --model-name bge-reranker-base --model-type rerank --endpoint http://localhost:9997

curl调用测试

embedding:

curl http://localhost:9997/v1/embeddings \-H "Content-Type: application/json" \-d '{"input": "The food was delicious and the waiter...","model": "360Zhinao-search","encoding_format": "float"}'

reranking:

curl http://localhost:9997/v1/rerank \-H "Content-Type: application/json" \-d '{"model": "bge-reranker-base","query": "I love you","documents": ["I hate you","I really like you","天空是什么颜色的","黑芝麻味饼干"],"top_n": 3
}'

这篇关于使用xinference部署自定义embedding模型(docker)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1115124

相关文章

如何使用CSS3实现波浪式图片墙

《如何使用CSS3实现波浪式图片墙》:本文主要介绍了如何使用CSS3的transform属性和动画技巧实现波浪式图片墙,通过设置图片的垂直偏移量,并使用动画使其周期性地改变位置,可以创建出动态且具有波浪效果的图片墙,同时,还强调了响应式设计的重要性,以确保图片墙在不同设备上都能良好显示,详细内容请阅读本文,希望能对你有所帮助...

Rust中的注释使用解读

《Rust中的注释使用解读》本文介绍了Rust中的行注释、块注释和文档注释的使用方法,通过示例展示了如何在实际代码中应用这些注释,以提高代码的可读性和可维护性... 目录Rust 中的注释使用指南1. 行注释示例:行注释2. 块注释示例:块注释3. 文档注释示例:文档注释4. 综合示例总结Rust 中的注释

Linux使用cut进行文本提取的操作方法

《Linux使用cut进行文本提取的操作方法》Linux中的cut命令是一个命令行实用程序,用于从文件或标准输入中提取文本行的部分,本文给大家介绍了Linux使用cut进行文本提取的操作方法,文中有详... 目录简介基础语法常用选项范围选择示例用法-f:字段选择-d:分隔符-c:字符选择-b:字节选择--c

使用Go语言开发一个命令行文件管理工具

《使用Go语言开发一个命令行文件管理工具》这篇文章主要为大家详细介绍了如何使用Go语言开发一款命令行文件管理工具,支持批量重命名,删除,创建,移动文件,需要的小伙伴可以了解下... 目录一、工具功能一览二、核心代码解析1. 主程序结构2. 批量重命名3. 批量删除4. 创建文件/目录5. 批量移动三、如何安

springboot的调度服务与异步服务使用详解

《springboot的调度服务与异步服务使用详解》本文主要介绍了Java的ScheduledExecutorService接口和SpringBoot中如何使用调度线程池,包括核心参数、创建方式、自定... 目录1.调度服务1.1.JDK之ScheduledExecutorService1.2.spring

Java使用Tesseract-OCR实战教程

《Java使用Tesseract-OCR实战教程》本文介绍了如何在Java中使用Tesseract-OCR进行文本提取,包括Tesseract-OCR的安装、中文训练库的配置、依赖库的引入以及具体的代... 目录Java使用Tesseract-OCRTesseract-OCR安装配置中文训练库引入依赖代码实

Python使用Pandas对比两列数据取最大值的五种方法

《Python使用Pandas对比两列数据取最大值的五种方法》本文主要介绍使用Pandas对比两列数据取最大值的五种方法,包括使用max方法、apply方法结合lambda函数、函数、clip方法、w... 目录引言一、使用max方法二、使用apply方法结合lambda函数三、使用np.maximum函数

SpringBoot中整合RabbitMQ(测试+部署上线最新完整)的过程

《SpringBoot中整合RabbitMQ(测试+部署上线最新完整)的过程》本文详细介绍了如何在虚拟机和宝塔面板中安装RabbitMQ,并使用Java代码实现消息的发送和接收,通过异步通讯,可以优化... 目录一、RabbitMQ安装二、启动RabbitMQ三、javascript编写Java代码1、引入

Qt 中集成mqtt协议的使用方法

《Qt中集成mqtt协议的使用方法》文章介绍了如何在工程中引入qmqtt库,并通过声明一个单例类来暴露订阅到的主题数据,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录一,引入qmqtt 库二,使用一,引入qmqtt 库我是将整个头文件/源文件都添加到了工程中进行编译,这样 跨平台

C++使用栈实现括号匹配的代码详解

《C++使用栈实现括号匹配的代码详解》在编程中,括号匹配是一个常见问题,尤其是在处理数学表达式、编译器解析等任务时,栈是一种非常适合处理此类问题的数据结构,能够精确地管理括号的匹配问题,本文将通过C+... 目录引言问题描述代码讲解代码解析栈的状态表示测试总结引言在编程中,括号匹配是一个常见问题,尤其是在