ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

Xinference CLI 命令参考:本地到分布式模型部署全指南

Xinference CLI 命令参考:本地到分布式模型部署全指南 Xinference CLI 命令参考本地到分布式模型部署全指南【免费下载链接】inferenceSwap GPT for any LLM by changing a single line of code. Xinference lets you run open-source, speech, and multimodal models on cloud, on-prem, or your laptop — all through one unified, production-ready inference API.项目地址: https://gitcode.com/GitHub_Trending/in/inferenceXinference 的CLIxinference命令行入口用于在本机或集群上启动推理服务、部署与管理模型实例并处理缓存、内存评估等运维操作。所有操作通过一条统一命令完成默认服务地址为http://127.0.0.1:9997也可通过XINFERENCE_ENDPOINT环境变量或--endpoint参数指向远程集群。命令定义位于源码目录xinference/deploy/cmdline.py安装后直接可用。快速上手启动本地服务后另开终端部署一个 0.5B 的 Qwen 模型验证部署流程是否跑通# 终端 1启动本地集群前台运行CtrlC 停止 xinference local # 终端 2部署模型vLLM 引擎 xinference launch -en vllm -n qwen2.5-instruct -s 0_5 -f pytorch -q fp8launch执行时会输出Launching model进度条完成后打印Model uid: uid该 UID 用于后续的list、terminate、chat等命令。核心命令详解启动本地服务并配置日志与监控端口local在单机上启动包含协调与工作能力的完整服务适合开发测试和小规模生产。xinference local \ --log-level INFO \ # 日志级别DEBUG/INFO/WARNING/ERROR/CRITICAL --host 127.0.0.1 \ # 绑定地址默认 127.0.0.1 --port 9997 \ # 服务端口默认 9997 --metrics-exporter-port 9998 # Prometheus 指标端口可选参数可选值/示例说明注意事项--log-levelINFO、DEBUG等服务日志详细程度默认INFO--host127.0.0.1、0.0.0.0服务监听地址需外部访问时设为0.0.0.0--port9997服务端口默认9997--metrics-exporter-port9998指标导出端口未指定时与--host同机INFO xinference.core.worker: XOSCR starting... INFO xinference: Supervisor is ready at 127.0.0.1:9997 INFO xinference: Web UI available at http://127.0.0.1:9997⚠️ 直接运行裸xinference启动本地集群已被标记为弃用建议使用xinference local源码中两者等价入口见 pyproject.toml 的[project.scripts]。注册自定义模型供部署register把一个模型描述文件注册进集群之后即可用launch按名称部署常用于私有或自训模型。xinference register \ --model-type LLM \ # 模型类型默认 LLM --file ./custom_llama.json \ # 模型描述 JSON 文件路径 --worker-ip 10.0.0.11 \ # 目标 worker 的 IP分布式场景 --persist # 持久化到磁盘服务重启后仍保留参数可选值/示例说明注意事项--model-typeLLM、embedding等模型类型默认LLM--file./custom_llama.json模型描述文件文件必须可读内容为合法 JSON--worker-ip10.0.0.11指定部署目标节点仅分布式场景使用--persist标志位注册信息落盘不加则重启后丢失$ xinference registrations -t LLM Type Name Language Ability Is-built-in LLM custom-llama en, zh chat False LLM qwen2.5-instruct en, zh chat True⚠️register只登记元数据不下载权重权重在实际launch时拉取并缓存。 ⚠️ 需要按名称列出已注册模型时使用xinference registrations不要与list列出运行中实例混淆。部署模型实例并选择推理引擎launch是核心命令下载模型、初始化引擎、加载权重并返回模型 UID。LLM 类型必须指定--model-engine。xinference launch \ --model-name qwen2.5-instruct \ # 模型名称 --model-type LLM \ # 模型类型默认 LLM --model-engine vllm \ # 推理引擎LLM 必填 --size-in-billions 0_5 \ # 参数量用下划线表示小数 --model-format pytorch \ # 权重格式pytorch / ggufv2 等 --quantization fp8 \ # 量化方式如 fp8 / q4_0 --n-gpu 1 \ # 使用 GPU 数默认 auto --replica 1 \ # 副本数默认 1 --lora-modules adapter/path/to/lora # LoRA 模块namepath 形式参数可选值/示例说明注意事项--model-enginevllm、llama_cpp、transformers推理引擎LLM 不传会直接报错--size-in-billions0_5、7参数量B小数必须写0_5而非0.5--n-gpuauto、1、none每副本 GPU 数n-worker1时为每 worker 的 GPU 数--replica1–10副本数与--replica-config同用时必须相等--lora-modulesname/pathLoRA 模块可重复传入多个--quantizationfp8、q4_0等量化配置先查vllm-models确认支持Launch model name: qwen2.5-instruct with kwargs: {gpu_memory_utilization: 0.9} Launching model |████████████████████████████████| 100.0% Model uid: 5f9d8b7c-1a2b-3c4d-5e6f-7a8b9c0d1e2f⚠️launch支持透传引擎私有参数任意--key value形式的额外参数如--gpu_memory_utilization 0.9会原样传给引擎但不识别的键会报You must specify extra kwargs with -- prefix错误。 ⚠️ 按 CtrlC 中断进度条时会询问是否取消输入y才真正终止该次部署模型不会静默残留。查看运行实例与交互式对话list展示集群中所有运行中的模型实例chat/generate用于本地快速验证模型输出。# 查看运行中的模型 xinference list # 与模型对话输入空行结束 xinference chat --model-uid 5f9d8b7c-1a2b-3c4d-5e6f-7a8b9c0d1e2f参数可选值/示例说明注意事项--endpointhttp://10.0.0.10:9997目标服务地址省略时取XINFERENCE_ENDPOINT或本地默认值--model-uid5f9d8b7c-...模型 UIDchat/generate必填list不需要--max_tokens512单轮最大生成长度默认 512--streamTrue、False是否流式输出默认TrueUID Type Name Format Size (in billions) Quantization 5f9d8b7c-1a2b-3c4d-... LLM qwen2.5-instruct pytorch 0.5 fp8 a1b2c3d4-5e6f-7a8b-... embedding bge-large-en-v1.5 1024User: 用一句话介绍 Xinference Assistant: Xinference 是一个开源的模型推理服务框架支持多种引擎部署。⚠️ 对不支持对话的模型如 embedding执行chat会抛出does not support chat错误先用list确认模型类型。停止模型实例与整个集群terminate卸载单个模型实例释放显存stop-cluster停止整个集群。# 按 UID 停止单个模型 xinference terminate --model-uid 5f9d8b7c-1a2b-3c4d-5e6f-7a8b9c0d1e2f # 停止整个集群需先登录认证集群带交互确认 xinference stop-cluster --endpoint http://10.0.0.10:9997参数可选值/示例说明注意事项--model-uid5f9d8b7c-...要卸载的实例 UIDterminate必填--endpointhttp://10.0.0.10:9997目标集群地址stop-cluster必填--check标志位跳过交互确认直接执行省略时先打印集群信息再询问This command will stop Xinference cluster in http://10.0.0.10:9997. Supervisor information: {worker_count: 2, running_models: 3} Workers information: [{ip: 10.0.0.11}, {ip: 10.0.0.12}] Continue? [y/N]: y Cluster stopped: True⚠️terminate只释放实例模型权重仍留在缓存目录要彻底释放磁盘用remove-cache。 ⚠️stop-cluster的--check语义是跳过确认与直觉相反自动化脚本中注意方向。搭建分布式集群Supervisor 与 Worker分布式模式下Supervisor主节点负责 API 服务与调度Worker工作节点执行模型加载与推理。默认分布式监听地址为0.0.0.0。# 在 Supervisor 机器上 xinference supervisor \ --host 0.0.0.0 \ # 监听地址默认 0.0.0.0 --port 9997 \ # 对外服务端口 --supervisor-port 9999 # Supervisor 内部 RPC 端口可选 # 在 Worker 机器上 xinference worker \ --endpoint http://10.0.0.10:9997 \ # Supervisor 地址 --host 0.0.0.0 \ # 本机对外地址 --worker-port 10000 # Worker RPC 端口省略则自动分配参数可选值/示例说明注意事项--endpointhttp://10.0.0.10:9997Supervisor 地址worker专用省略时取XINFERENCE_ENDPOINT--host0.0.0.0本机监听地址分布式默认0.0.0.0--port9997Supervisor 服务端口仅supervisor使用--worker-port10000Worker RPC 端口不指定时自动找空闲端口--metrics-exporter-port10001本节点指标端口supervisor/worker均可用INFO xinference.deploy.supervisor: Supervisor listening on 0.0.0.0:9997 INFO xinference.deploy.worker: Worker registered, supervisor endpoint: http://10.0.0.10:9997⚠️ 旧文档中的coordinator命令在新版本中已由supervisor取代两者不可混用。 ⚠️ Worker 通过--endpoint向 Supervisor 获取内部 RPC 地址后再注册--endpoint指向的必须是 Supervisor 的 9997 端口而非内部端口。清理模型缓存释放磁盘cached查看各节点已缓存的模型文件remove-cache删除指定模型的缓存目录。# 查看缓存 xinference cached --model_name qwen2.5-instruct # 删除指定版本模型的缓存先打印路径交互确认后删除 xinference remove-cache --model_version qwen2.5-instruct-0.5b-fp8 --check参数可选值/示例说明注意事项--model_nameqwen2.5-instruct按名称过滤cached用下划线形式--model_versionqwen2.5-instruct-0.5b-fp8缓存版本号remove-cache下划线形式--worker-ip10.0.0.11指定目标节点分布式场景使用--check标志位直接执行删除不带时先交互确认cached_model: --------------------------------------------- | model_version | size | path | --------------------------------------------- | qwen2.5-instruct-0.5b-fp8 | 0.6 GB | /root/xinference/cache/... | ---------------------------------------------⚠️ 删除正在运行的模型缓存会导致该实例不可用先terminate再清理。 ⚠️ 找不到对应缓存时输出There is no model version named xxx.核对cached列表中的版本号拼写。进阶配置与调优显存不足是部署中最常见的问题。部署前先估算所需显存而不是直接试错xinference cal-model-mem \ --size-in-billions 7 \ # 参数量 --model-format pytorch \ # 权重格式 --quantization fp8 \ # 量化方式 --context-length 32768 \ # 目标上下文长度 --kv-cache-dtype 16 # KV cache 位宽8/16/32model_name: None kv_cache_dtype: 16 model size: 7.0 B quant: fp8 context: 32768 gpu mem usage: model mem: 7168 MB kv_cache: 1843 MB overhead: 1024 MB active: 2048 MB total: 12083 MB (12 GB)输出给出模型权重、KV cache、激活值与开销的拆解据此判断需要几张卡、是否降量化。若仍不足依次尝试--quantization降到q4_0、--n-gpu 2分摊权重、降低--context-length。当多个模型依赖不同版本的第三方库时可以用虚拟环境隔离避免依赖冲突xinference launch \ -en vllm -n qwen2.5-instruct -s 0_5 -f pytorch \ --enable-virtual-env \ # 为该模型创建独立环境 --virtual-env-package transformers \ # 环境中额外安装的包可重复 --virtual-env-find-link /data/wheels # worker 本地 wheel 目录离线环境虚拟环境在模型专属目录下创建删除该模型实例后随之回收离线集群通过--virtual-env-find-link指向本地 wheel 目录避免外网下载。相关管理界面与机制说明见官方文档 doc/source/models/virtualenv.rst。故障排查症状launch 进度条卡在加载阶段最终报 CUDA out of memory。排查步骤# 1. 用 cal-model-mem 确认所需显存是否超过单卡容量 xinference cal-model-mem -s 7 -f pytorch -q fp8 -c 32768 # 2. 查看当前节点还有哪些实例占用显存 xinference list解决方案终止无关实例释放显存或将--quantization降一档或用--n-gpu 2让权重跨卡分布。症状worker 启动后无法加入集群Supervisor 的 list 中看不到该节点。排查步骤# 1. 在 worker 机器上验证能否访问 Supervisor 的 endpoint curl http://10.0.0.10:9997 # 2. 检查 worker 日志位于 XINFERENCE_HOME/logs 下的 worker_*.log ls ~/.xinference/logs/解决方案确认--endpoint指向 Supervisor 的 9997 端口确认防火墙放行该端口及--worker-port--host需填 worker 对外可达的 IP 而不是127.0.0.1。症状执行命令报命令不存在如 No such command coordinator。排查步骤xinference --version xinference --help解决方案查看--help输出的实际子命令列表新版本集群主节点命令为supervisor旧教程中的coordinator已更名以当前版本输出为准。症状参数不生效或报 unknown option但确认拼写正确。排查步骤xinference launch --help | grep -E model_name|model_version|n-gpu解决方案注意部分参数使用下划线如--model_name、--model_version而非连字符launch未识别的--xxx会当作引擎透传参数写错的引擎参数不会立即报错而是在启动阶段失败。命令速查命令功能最常用参数适用场景xinference local启动本地单机服务--host,--port,--log-level开发测试、小规模生产xinference supervisor启动分布式主节点--port,--supervisor-port搭建多节点集群xinference worker工作节点加入集群--endpoint,--worker-port扩展 GPU 算力xinference register注册自定义模型--file,--persist,--model-type私有/自训模型入库xinference launch部署模型实例--model-engine,--quantization,--n-gpu部署任意类型模型xinference list查看运行中实例--endpoint日常巡检xinference terminate按 UID 卸载实例--model-uid释放显存xinference stop-cluster停止整个集群--endpoint,--check集群下线维护xinference chat与模型交互验证--model-uid,--stream部署后功能验证xinference generate非对话式文本生成--model-uid,--max_tokens验证 generate 能力模型xinference cached查看磁盘缓存--model_name,--worker-ip磁盘空间审计xinference remove-cache删除模型缓存--model_version,--check清理过期模型xinference registrations查看已注册模型--model-type核对注册结果xinference vllm-models查询 vLLM 支持的模型族--endpoint确认引擎兼容性xinference engine查询模型可用的引擎参数组合--model-name,--quantization组装 launch 参数前查证xinference cal-model-mem估算显存占用--size-in-billions,--context-length部署前容量规划xinference login认证集群登录--username,--password启用集群认证后 命令基于当前仓库版本supervisor/worker 架构不同版本参数可能有差异以官方文档为准。【免费下载链接】inferenceSwap GPT for any LLM by changing a single line of code. Xinference lets you run open-source, speech, and multimodal models on cloud, on-prem, or your laptop — all through one unified, production-ready inference API.项目地址: https://gitcode.com/GitHub_Trending/in/inference创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表