Zhimu-1.0 实际体验部署清单

3157 字
8 分钟

Zhimu-1.0 实际体验部署清单

发布于

结论速览

本机:RTX 4050 Laptop 6GB + pytorch 环境(py3.8 / torch 1.10.1 / CUDA 可用,2026-08-27 实测通过)——但 torch 1.10.1 太老无法跑 transformers 4.57,且 bf16 权重需 18.6GB 显存 >> 6GB。

结论:正式体验走【方案一 云端租卡】(每 2-3 小时 ≈ 几块钱);本机 4050 只能走【方案二 4bit 量化】(实验性,见文末)。

方案一:云端租卡(推荐)

平台:AutoDL / 恒源云等按小时租卡平台。

规格:

  • RTX 3090 或 4090(24GB 及以上显存)
  • 镜像选 PyTorch 2.x + CUDA 12.x(官网推荐:Python 3.11 + PyTorch 2.10.0 + CUDA 12.8)
  • 单价参考:3090 档约 2-3 元/小时(随行情浮动),按秒计费

一、进实例后,终端逐条执行

  1. 克隆推理仓库
git clone https://github.com/wangdianyu954-xixi/AIR-CAS-zhimu
cd Zhimu
  1. 下载模型权重(必须完整仓库,不只权重分片)
hf download AIR-CAS-kx/Zhimu-1.0 --local-dir ./Zhimu-1.0
  • 若提示登录:huggingface-cli login 后粘贴你的 HF token
  • 若下载极慢:加环境变量走国内镜像
export HF_ENDPOINT=https://hf-mirror.com
  1. 安装依赖(镜像自带 torch 就不用装 torch)
pip install "transformers==4.57.6" "huggingface-hub>=0.34.0,<1.0" \
    accelerate safetensors numpy pillow tifffile scipy

二、四模态推理(仓库 examples/ 自带示例数据)

RGB:

python test.py --model-dir ./Zhimu-1.0 --input ./examples/rgb.jpg \
  --modality rgb \
  --prompt "Classify the given image in one of the following classes. Classes: palace, beach, dense residential, ground track field, medium residential, railway, harbor, sea ice, desert, chaparral. Answer in one word or a short phrase." \
  --max-new-tokens 128

SAR(1 通道):

python test.py --model-dir ./Zhimu-1.0 --input ./examples/sar.npy \
  --modality sar \
  --prompt "Locate all targets in this SAR image. Valid labels: ship, aircraft, car, tank, bridge, harbor. Output a JSON array, where each item has \"bbox_2d\" and \"label\"." \
  --max-new-tokens 128

MSI(12 通道):

python test.py --model-dir ./Zhimu-1.0 --input ./examples/multispectral.tif \
  --modality multispectral \
  --prompt "What is the shape of the road in the image?" \
  --max-new-tokens 128

HSI(218 通道):

python test.py --model-dir ./Zhimu-1.0 --input ./examples/hyperspectral.npy \
  --modality hyperspectral \
  --prompt "What is the correct level3 land-cover class for this remote sensing image? Choose the best answer from the options below and reply with the option letter and class name only. A. durum_hard_wheat B. lentils C. pasture_meadow_grassland_grass D. triticale" \
  --max-new-tokens 128

三、玩你自己的数据

  • 上传数据:npy / tif 均可;二维数组(灰度)会自动补通道维
  • 通道数必须匹配:SAR=1、RGB=3、MSI=12、HSI=218(这是 checkpoint 固定的四条默认配置;多光谱/高光谱其他通道数会报错)
  • 值域建议:HSI 按 uint16 满量程 0~65535(处理器会自动除以 65535)
  • 通道布局:默认自动识别,报”通道数不匹配”就指定:
    • --input-layout chw(数组是 通道×高×宽)
    • --input-layout hwc(数组是 高×宽×通道)
  • 中文提问(Qwen3-VL 支持中文):
python test.py --model-dir ./Zhimu-1.0 --input 你的图 --modality rgb \
  --prompt "图中主要地物是什么?请简述。" --max-new-tokens 128

四、省钱技巧(重要)

  • 平台一般有”无卡模式”(超便宜):先在上面传权重/数据、装依赖,再开机跑,跑完立刻关机(按秒计费,忘关会一直扣钱)
  • 体验一次:租 2-3 小时 ≈ 6-10 元

五、常见报错速查

  • “显存不足”:确认未改 dtype(默认 bf16 已是最省之一);仍不足说明 224×224 输入下峰值 ~17.6GB 超过卡了 → 换 40GB 档或走方案二
  • “模型类/处理器找不到”:没下载完整 HF 仓库,重新 hf download
  • “通道数不匹配”:检查输入数组 shape + --input-layout chw/hwc
  • 依赖版本报错:严格按仓库 README 版本安装(transformers==4.57.6

方案二:本机 4050(6GB)4bit 量化——实验性

前提:新建干净环境(现有 pytorch env 的 torch 1.10 太老必弃):

conda create -n zhimu-q python=3.11 -y
conda activate zhimu-q
pip install torch transformers==4.57.6 bitsandbytes accelerate \
    safetensors numpy pillow tifffile scipy \
    --index-url https://pypi.tuna.tsinghua.edu.cn/simple

加载脚本(modeling/processor 用仓库同目录的远程代码):

from transformers import AutoModel, AutoProcessor, BitsAndBytesConfig
config = BitsAndBytesConfig(load_in_4bit=True,
                            bnb_4bit_compute_dtype=None)
processor = AutoProcessor.from_pretrained("./Zhimu-1.0",
            trust_remote_code=True)
model = AutoModel.from_pretrained("./Zhimu-1.0",
            quantization_config=config, trust_remote_code=True)

风险提示(实验前先读):

  • 权重 4bit ≈ 4.7GB + 激活 >> 6GB 显存,很可能仍 OOM——若 OOM,只能降低输入分辨率(提前把图缩到 128×128 左右再喂)
  • 自定义的卷积/MoE 层量化兼容性未知,可能部分层退回 bf16
  • 4050 Laptop 带宽有限,生成约 1-2 秒/token,体验一般
  • 结论:有耐心可以当玩具,正式体验用方案一