使用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

相关文章

SpringBoot中ResponseEntity的使用方法举例详解

《SpringBoot中ResponseEntity的使用方法举例详解》ResponseEntity是Spring的一个用于表示HTTP响应的全功能对象,它可以包含响应的状态码、头信息及响应体内容,下... 目录一、ResponseEntity概述基本特点:二、ResponseEntity的基本用法1. 创

使用Java填充Word模板的操作指南

《使用Java填充Word模板的操作指南》本文介绍了Java填充Word模板的实现方法,包括文本、列表和复选框的填充,首先通过Word域功能设置模板变量,然后使用poi-tl、aspose-words... 目录前言一、设置word模板普通字段列表字段复选框二、代码1. 引入POM2. 模板放入项目3.代码

使用EasyPoi快速导出Word文档功能的实现步骤

《使用EasyPoi快速导出Word文档功能的实现步骤》EasyPoi是一个基于ApachePOI的开源Java工具库,旨在简化Excel和Word文档的操作,本文将详细介绍如何使用EasyPoi快速... 目录一、准备工作1、引入依赖二、准备好一个word模版文件三、编写导出方法的工具类四、在Export

Python爬虫HTTPS使用requests,httpx,aiohttp实战中的证书异步等问题

《Python爬虫HTTPS使用requests,httpx,aiohttp实战中的证书异步等问题》在爬虫工程里,“HTTPS”是绕不开的话题,HTTPS为传输加密提供保护,同时也给爬虫带来证书校验、... 目录一、核心问题与优先级检查(先问三件事)二、基础示例:requests 与证书处理三、高并发选型:

MySQL之搜索引擎使用解读

《MySQL之搜索引擎使用解读》MySQL存储引擎是数据存储和管理的核心组件,不同引擎(如InnoDB、MyISAM)采用不同机制,InnoDB支持事务与行锁,适合高并发场景;MyISAM不支持事务,... 目录mysql的存储引擎是什么MySQL存储引擎的功能MySQL的存储引擎的分类查看存储引擎1.命令

Python sys模块的使用及说明

《Pythonsys模块的使用及说明》Pythonsys模块是核心工具,用于解释器交互与运行时控制,涵盖命令行参数处理、路径修改、强制退出、I/O重定向、系统信息获取等功能,适用于脚本开发与调试,需... 目录python sys 模块详解常用功能与代码示例获取命令行参数修改模块搜索路径强制退出程序标准输入

5 种使用Python自动化处理PDF的实用方法介绍

《5种使用Python自动化处理PDF的实用方法介绍》自动化处理PDF文件已成为减少重复工作、提升工作效率的重要手段,本文将介绍五种实用方法,从内置工具到专业库,帮助你在Python中实现PDF任务... 目录使用内置库(os、subprocess)调用外部工具使用 PyPDF2 进行基本 PDF 操作使用

docker 重命名镜像的实现方法

《docker重命名镜像的实现方法》在Docker中无法直接重命名镜像,但可通过添加新标签、删除旧镜像后重新拉取/构建,或在DockerCompose中修改配置文件实现名称变更,感兴趣的可以了解一下... 目录使用标签(Tagging)删除旧的php镜像并重新拉取或构建使用docker Compose在Do

vue监听属性watch的用法及使用场景详解

《vue监听属性watch的用法及使用场景详解》watch是vue中常用的监听器,它主要用于侦听数据的变化,在数据发生变化的时候执行一些操作,:本文主要介绍vue监听属性watch的用法及使用场景... 目录1. 监听属性 watch2. 常规用法3. 监听对象和route变化4. 使用场景附Watch 的

nodejs打包作为公共包使用的完整流程

《nodejs打包作为公共包使用的完整流程》在Node.js项目中,打包和部署是发布应用的关键步骤,:本文主要介绍nodejs打包作为公共包使用的相关资料,文中通过代码介绍的非常详细,需要的朋友可... 目录前言一、前置准备二、创建与编码三、一键构建四、本地“白嫖”测试(可选)五、发布公共包六、常见踩坑提醒