xinference注册、启动多个本地模型

xinference注册、启动多个本地模型

bash

#!/bin/bash

# 启动 xinference 服务
/opt/conda/bin/xinference-local --host 0.0.0.0 --port 9997 &

# 等待服务完全启动
sleep 10

# 注册 embedding 模型
echo "Registering /model/bge-large-zh as custom-bge-large-zh"
/opt/conda/bin/xinference register --model-type embedding --file /workspace/custom-bge-large-zh.json --persist

# 等待模型注册完成
sleep 5

# 注册 rerank 模型
echo "Registering /model/bge-reranker-v2-m3 as custom-bge-reranker-v2-m3"
/opt/conda/bin/xinference register --model-type rerank --file /workspace/custom-bge-reranker-v2-m3.json --persist

# 等待模型注册完成
sleep 5

# 启动 embedding 模型
echo "Launching custom-bge-large-zh embedding model..."
/opt/conda/bin/xinference launch --model-name custom-bge-large-zh --model-type embedding

# 等待模型启动完成
sleep 5

# 启动 rerank 模型
echo "Launching custom-bge-reranker-v2-m3 rerank model..."
/opt/conda/bin/xinference launch --model-name custom-bge-reranker-v2-m3 --model-type rerank

注意

  1. 在bash中使用xinference命令的决定路径 ,/opt/conda/bin/xinference;
  2. 足够的启动时间,使用sleep保证每行命令完成后在执行下一条命令。

python

在解决bash上述两个问题前,考虑转成python脚本的方式注册启动多个本地模型。

import subprocess
import time

# 启动 xinference 服务
def start_xinference():
    print("Starting xinference-local service...")
    subprocess.Popen(['/opt/conda/bin/xinference-local', '--host', '0.0.0.0', '--port', '9997'])
    time.sleep(10)  # 等待服务完全启动

# 注册模型
def register_model(model_type, json_file, custom_name):
    print(f"Registering {custom_name} as {model_type} model...")
    subprocess.run(['/opt/conda/bin/xinference', 'register', '--model-type', model_type, '--file', json_file, '--persist'])
    time.sleep(5)  # 等待注册完成

# 启动模型
def launch_model(model_type, custom_name):
    print(f"Launching {custom_name} {model_type} model...")
    subprocess.run(['/opt/conda/bin/xinference', 'launch', '--model-name', custom_name, '--model-type', model_type])
    time.sleep(5)  # 等待启动完成

if __name__ == "__main__":
    # 启动 xinference 服务
    start_xinference()

    # 注册 embedding 模型
    register_model('embedding', '/workspace/custom-bge-large-zh.json', 'custom-bge-large-zh')

    # 注册 rerank 模型
    register_model('rerank', '/workspace/custom-bge-reranker-v2-m3.json', 'custom-bge-reranker-v2-m3')

    # 启动 embedding 模型
    launch_model('embedding', 'custom-bge-large-zh')

    # 启动 rerank 模型
    launch_model('rerank', 'custom-bge-reranker-v2-m3')

### 启动多个 Xinference 本地模型实例 为了在同一台机器上成功启动多个 Xinference 本地模型实例,需注意端口管理和资源分配策略。每个多实例配置应确保独立的网络端口和服务路径,防止服务间冲突。 #### 方法一:通过不同端口号区分多实例 当在相同硬件环境中部署多个 Xinference 实例时,可以通过指定不同的监听端口来避免冲突。例如: ```bash # 第一个实例绑定到默认端口 (假设为8000) xinference start --port 8000 # 第二个实例绑定至其他可用端口如9000 xinference start --port 9000 ``` 这种方法简单易行,在同一物理节点上支持并发访问多个推理API接口[^1]。 #### 方法二:利用容器化技术隔离环境 采用Docker或其他容器解决方案能够有效管理依赖关系并简化多版本共存问题。对于每个Xinference实例创建单独镜像或容器,并设置各自独特的内部/外部映射端口组合: ```dockerfile FROM python:3.8-slim-buster WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt COPY . . EXPOSE ${PORT} CMD ["sh", "-c", "xinference start --port=${PORT}"] ``` 构建和运行命令如下所示: ```bash docker build -t xinference-instance . for port in {8000..8002}; do \ docker run -d -p $port:$port --name=xinference-$port \ -e PORT=$port xinference-instance; \ done ``` 此方法不仅有助于提高系统的可移植性和稳定性,还便于扩展集群规模。 #### 方法三:基于 AlpaServe 的资源共享机制优化调度效率 考虑到GPU等计算资源的有效利用率,借鉴AlpaServe中的模型切分复用理念,可以在一台服务器内部分配有限数量的加速卡给更多逻辑上的工作单元。这通常涉及更复杂的编程控制以及对底层框架的支持程度考量[^2]。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值