zhiyi/deploy.sh

89 lines
2.6 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 织忆 v2.8 部署脚本
# 用法: bash deploy.sh [--gpu]
set -e
echo "=== 织忆 MemoryWeave v2.8 部署脚本 ==="
# 检测 GPU
GPU=false
if [[ "$1" == "--gpu" ]] && command -v nvidia-smi &>/dev/null; then
GPU=true
echo "[检测] NVIDIA GPU 可用,将安装 CUDA 版 torch"
else
echo "[检测] CPU 模式"
fi
# 1. 安装系统依赖(需要 sudo
if ! command -v redis-server &>/dev/null; then
echo "[步骤1] 安装 Redis..."
if command -v apt &>/dev/null; then
sudo apt install -y redis-server
elif command -v pacman &>/dev/null; then
sudo pacman -S redis
else
echo "[警告] 未检测到包管理器,请手动安装 Redis"
fi
else
echo "[步骤1] Redis 已安装 ✓"
fi
# 2. 创建虚拟环境
echo "[步骤2] 创建虚拟环境..."
if [ ! -d ".venv" ]; then
python3 -m venv .venv
fi
source .venv/bin/activate
# 3. 安装 Python 依赖
echo "[步骤3] 安装 Python 依赖..."
if $GPU; then
# GPU 机器:从系统 Python 复制 torch CUDA 版
# torch 没有官方 cu130 的 pip 包,需要手动处理)
echo "[警告] GPU 模式需要手动处理 torch CUDA 版本"
echo "[提示] 从本机 /home/muc/.local/lib/python3.12/site-packages/ 复制 torch + nvidia 到 .venv/lib/python3.12/site-packages/"
fi
# 安装基础依赖
pip install --upgrade pip
pip install -r requirements.txt
# 4. 下载 HF 模型
echo "[步骤4] 下载 moka-ai/m3e-base 模型..."
export HF_ENDPOINT=https://hf-mirror.com
python3 -c "
from sentence_transformers import SentenceTransformer
print('下载模型中(首次约 400MB...')
model = SentenceTransformer('moka-ai/m3e-base')
print('模型下载完成 ✓')
"
# 5. 配置 Redis
echo "[步骤5] 启动 Redis..."
if ! pgrep -x redis-server > /dev/null; then
redis-server --daemonize yes
echo "Redis 已启动 ✓"
else
echo "Redis 已运行 ✓"
fi
# 6. 验证部署
echo "[步骤6] 验证..."
python3 -c "
import faiss
import torch
from sentence_transformers import SentenceTransformer
print(f' torch: {torch.__version__} CUDA={torch.cuda.is_available()}')
print(f' faiss-cpu: {faiss.__version__}')
print(' 依赖验证通过 ✓')
"
echo ""
echo "=== 部署完成 ==="
echo ""
echo "启动服务:"
echo " HF_ENDPOINT=https://hf-mirror.com PYTHONPATH=src .venv/bin/uvicorn api.server:app --host 0.0.0.0 --port 7821"
echo ""
echo "或 GPU 模式(需要先手动复制 torch CUDA 版本到 venv"
echo " HF_ENDPOINT=https://hf-mirror.com PYTHONPATH=src ZHIYI_PORT=7821 .venv/bin/uvicorn api.server:app --host 0.0.0.0 --port 7821"