核心内容摘要
Flask快速搭建AnythingtoRealCharacters2511演示网站
Lychee-Rerank-MM部署教程后台nohup运行日志监控与PID管理
1.
项目概述Lychee-Rerank-MM是基于Qwen
5-VL的多模态重排序模型专门用于图文检索场景的精排任务。
这个7B参数的模型采用BF16精度推理由哈工大深圳NLP团队开发能够处理文本到文本、文本到图像、图像到文本以及图像到图像等多种模态组合的重排序需求。
环境准备
1 硬件要求GPU显存建议16GB及以上存储空间模型文件约15GB确保有足够空间内存建议32GB以上以获得最佳性能
2 软件依赖确保系统中已安装以下基础组件# 检查Python版本 python3 --version # 需要
8 # 检查PyTorch安装 python3 -c import torch; print(torch.__version__) # 需要
2.
部署步骤
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.git
2 安装依赖进入项目目录安装所需依赖cd /root/ai-models/vec-ai/lychee-rerank-mm pip install -r requirements.txt
运行与管理
1 启动服务推荐使用以下三种方式之一启动服务# 方式1使用启动脚本推荐 ./start.sh # 方式2直接运行 python app.py # 方式3后台运行生产环境推荐 nohup python app.py /tmp/lychee_server.log 21
2 进程管理查找运行中的进程ps aux | grep python app.py输出示例user 12345
5
1 1234567 89012 pts/0 Sl 14:30 0:05 python app.py停止服务kill 12345 # 替换为实际的PID查看日志tail -f /tmp/lychee_server.log
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 21 fi sleep 60 done赋予执行权限并启动监控chmod x monitor.sh nohup ./monitor.sh /dev/null 21
服务验证
1 检查服务状态curl http://localhost:7860/health预期返回{status:healthy}
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.] }
性能优化建议
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: [doc
txt, doc
jpg, ...] # 支持混合模态 } response requests.post(url, jsondata)
2 参数调整根据硬件配置调整以下参数max_length控制处理文本的最大长度默认3200batch_size批量处理时的文档数量flash_attention确保启用以获得最佳性能
7.
常见问题解决
1 模型加载失败检查步骤# 确认模型路径 ls /root/ai-models/vec-ai/lychee-rerank-mm # 检查GPU可用性 nvidia-smi # 验证依赖版本 pip list | grep torch
2 内存不足解决方案减少batch_size使用--precision bf16参数增加GPU内存或使用多卡推理
3 服务无响应排查方法# 检查端口占用 netstat -tulnp | grep 7860 # 检查日志错误 grep -i error /tmp/lychee_server.log
8.