马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
利用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=1
- RUN python3 -m pip uninstall -y transformer-engine
- RUN python3 -m pip install --upgrade pip
- RUN 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.whl
- RUN 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/simple
- EXPOSE 80
- CMD ["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:9997
- xinference register --model-type embedding --file custom_models/embedding/gte-Qwen2-7B-instruct.json --persist --endpoint http://localhost:9997
- xinference 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:9997
- xinference launch --model-type embedding --model-name 360Zhinao-search --model-engine transformers --model-format pytorch --endpoint http://localhost:9997
- xinference 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:9997
- xinference 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
- }'
复制代码 |