Lychee-Rerank-MM部署教程:后台nohup运行+日志监控与PID管理
1. 项目概述
Lychee-Rerank-MM是基于Qwen2.5-VL的多模态重排序模型,专门用于图文检索场景的精排任务。这个7B参数的模型采用BF16精度推理,由哈工大深圳NLP团队开发,能够处理文本到文本、文本到图像、图像到文本以及图像到图像等多种模态组合的重排序需求。
2. 环境准备
2.1 硬件要求
- GPU显存:建议16GB及以上
- 存储空间:模型文件约15GB,确保有足够空间
- 内存:建议32GB以上以获得最佳性能
2.2 软件依赖
确保系统中已安装以下基础组件:
# 检查Python版本 python3 --version # 需要3.8+ # 检查PyTorch安装 python3 -c "import torch; print(torch.__version__)" # 需要2.0+3. 部署步骤
3.1 获取模型文件
模型默认路径为/root/ai-models/vec-ai/lychee-rerank-mm,如果路径不存在,需要先下载模型:
mkdir -p /root/ai-models/vec-ai cd /root/ai-models/vec-ai git clone https://www.modelscope.cn/vec-ai/lychee-rerank-mm.git3.2 安装依赖
进入项目目录安装所需依赖:
cd /root/ai-models/vec-ai/lychee-rerank-mm pip install -r requirements.txt4. 运行与管理
4.1 启动服务
推荐使用以下三种方式之一启动服务:
# 方式1:使用启动脚本(推荐) ./start.sh # 方式2:直接运行 python app.py # 方式3:后台运行(生产环境推荐) nohup python app.py > /tmp/lychee_server.log 2>&1 &4.2 进程管理
查找运行中的进程
ps aux | grep "python app.py"输出示例:
user 12345 0.5 2.1 1234567 89012 pts/0 Sl 14:30 0:05 python app.py停止服务
kill 12345 # 替换为实际的PID查看日志
tail -f /tmp/lychee_server.log4.3 自动重启脚本
创建监控脚本monitor.sh确保服务持续运行:
#!/bin/bash while true; do if ! pgrep -f "python app.py" > /dev/null; then echo "$(date): Service not running, restarting..." >> /var/log/lychee_monitor.log nohup python /root/lychee-rerank-mm/app.py > /tmp/lychee_server.log 2>&1 & fi sleep 60 done赋予执行权限并启动监控:
chmod +x monitor.sh nohup ./monitor.sh > /dev/null 2>&1 &5. 服务验证
5.1 检查服务状态
curl http://localhost:7860/health预期返回:
{"status":"healthy"}5.2 测试API接口
curl -X POST http://localhost:7860/api/v1/rerank \ -H "Content-Type: application/json" \ -d '{ "instruction": "Given a web search query, retrieve relevant passages that answer the query", "query": "What is the capital of China?", "documents": ["The capital of China is Beijing.", "Shanghai is the largest city in China."] }'6. 性能优化建议
6.1 批量处理
对于大量文档,使用批量模式可显著提升效率:
# 示例Python代码 import requests url = "http://localhost:7860/api/v1/batch_rerank" data = { "instruction": "Given a product image and description, retrieve similar products", "query": "product_image.jpg", # 或文本查询 "documents": ["doc1.txt", "doc2.jpg", ...] # 支持混合模态 } response = requests.post(url, json=data)6.2 参数调整
根据硬件配置调整以下参数:
max_length:控制处理文本的最大长度(默认3200)batch_size:批量处理时的文档数量flash_attention:确保启用以获得最佳性能
7. 常见问题解决
7.1 模型加载失败
检查步骤:
# 确认模型路径 ls /root/ai-models/vec-ai/lychee-rerank-mm # 检查GPU可用性 nvidia-smi # 验证依赖版本 pip list | grep torch7.2 内存不足
解决方案:
- 减少
batch_size - 使用
--precision bf16参数 - 增加GPU内存或使用多卡推理
7.3 服务无响应
排查方法:
# 检查端口占用 netstat -tulnp | grep 7860 # 检查日志错误 grep -i error /tmp/lychee_server.log8. 总结
本教程详细介绍了Lychee-Rerank-MM模型的部署和管理方法,重点包括:
- 环境配置:硬件要求与依赖安装
- 服务部署:多种启动方式与后台运行
- 进程管理:PID查找、停止服务和日志监控
- 性能优化:批量处理与参数调整建议
- 故障排查:常见问题解决方法
通过本指南,您可以轻松地在生产环境中部署和管理这个强大的多模态重排序模型,为图文检索应用提供精准的排序能力。
获取更多AI镜像
想探索更多AI镜像和应用场景?访问 CSDN星图镜像广场,提供丰富的预置镜像,覆盖大模型推理、图像生成、视频生成、模型微调等多个领域,支持一键部署。