本文档记录 GLM-OCR-bf16 在 vLLM-Ascend 0.18.0rc1 环境的快速部署与验证结果。
GLM-OCR 是智谱 AI(Zhipu AI)发布的多模态 OCR 模型,基于 GLM-V encoder-decoder 架构,视觉编码器采用 CogViT,语言解码器为 GLM-0.5B,总参数量约 0.9B。该模型在 OmniDocBench V1.5 上取得 94.62 分(排名第一),支持文档、表格、公式、代码、印章等多种场景的文字识别。
相关获取地址:
quay.io/ascend/vllm-ascend:v0.18.0rc1参考文档:
| 组件 | 版本 |
|---|---|
vllm-ascend | 0.18.0rc1 |
vllm | 0.18.0+empty |
transformers | 4.57.6 |
torch-npu | 2.9.0.post1+gitee7ba04 |
torch | 2.9.0+cpu |
2 逻辑卡(Ascend 910)/opt/atomgit/weights/GLM-OCR-bf168000启动前可先检查端口:
ss -lntp | grep ':8000 ' || true已验证通过的启动命令:
export ASCEND_RT_VISIBLE_DEVICES=0,1
export VLLM_USE_MODELSCOPE=true
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
export HCCL_BUFFSIZE=512
export OMP_PROC_BIND=false
export OMP_NUM_THREADS=1
export TASK_QUEUE_ENABLE=1
vllm serve /opt/atomgit/weights/GLM-OCR-bf16 \
--host 0.0.0.0 \
--port 8000 \
--data-parallel-size 1 \
--tensor-parallel-size 1 \
--seed 1024 \
--served-model-name glm-ocr \
--max-num-seqs 32 \
--max-model-len 8192 \
--max-num-batched-tokens 4096 \
--trust-remote-code \
--gpu-memory-utilization 0.85 \
--no-enable-prefix-caching \
--compilation-config '{"cudagraph_mode":"FULL_DECODE_ONLY"}'关键参数说明:
--trust-remote-code:必须携带,GLM-OCR 使用自定义架构 GlmOcrForConditionalGeneration,需要 trust remote code--tensor-parallel-size 1:0.9B 模型单卡即可运行--max-model-len 8192:模型支持的最大上下文长度--gpu-memory-utilization 0.85:HBM 利用率--compilation-config FULL_DECODE_ONLY:ACL Graph 加速编译基础检查:
curl -sf http://127.0.0.1:8000/v1/models
curl -sf http://127.0.0.1:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "glm-ocr",
"messages": [
{"role": "user", "content": "请用一句话介绍 GLM-OCR 模型。"}
],
"temperature": 0,
"max_tokens": 128
}'验证结果:
/v1/models 返回 200/v1/chat/completions 返回 200测试条件:128 input / 128 output,API 级基准测试。
| 指标 | 数值 |
|---|---|
| Latency mean | 71.5 ms |
| Latency p99 | 101.2 ms |
| Throughput | 25.14 req/s |
| Token throughput | 326.81 tok/s |
注:测试并发度为 2,总请求数 10。实际性能受输入长度、并发度及编译参数影响,以上数据仅供参考。
压测命令:
# 需先确保 vLLM 服务已在 8000 端口运行
python scripts/bench_perf.py \
--url http://localhost:8000/v1/chat/completions \
--model glm-ocr \
--max-tokens 128 \
--latency-iters 5 \
--throughput-requests 10 \
--throughput-concurrency 2采用 NPU 与 CPU 基线对比的方式,对模型输出的 Logits 和 Hidden States 进行精度评估。验证指标包括:
| 指标 | Logits | Hidden States |
|---|---|---|
| max_abs_error | 0.171875 | 0.250000 |
| mean_abs_error | 0.028762 | 0.018531 |
| relative_error | 2.8886% | 7.4675% |
| cosine_similarity | 0.999978 | 0.999889 |
| threshold | 1.0 | 1.0 |
| 结果 | PASS | PASS |
结论:NPU 与 CPU 基线高度一致,cosine_similarity > 0.9998,验证通过。
说明:
- 绝对误差(max_abs_error < 1.0)与余弦相似度(> 0.999)均满足通过标准。
- 相对误差受 bfloat16 近零值影响偏大,仅作参考,不作为硬性判定依据。
运行精度评测:
python scripts/eval_accuracy.py \
--model /opt/atomgit/weights/GLM-OCR-bf16 \
--output accuracy_result.json项目提供 inference.py 一键推理脚本,支持本地 transformers 与 API 服务两种模式:
# 本地 transformers 模式(纯文本)
python inference.py --mode local \
--model /opt/atomgit/weights/GLM-OCR-bf16 \
--prompt "Text Recognition:"
# 本地 transformers 模式(图像 OCR)
python inference.py --mode local \
--model /opt/atomgit/weights/GLM-OCR-bf16 \
--image test.png \
--prompt "Text Recognition:"
# API 服务模式(调用已部署的 vLLM 服务)
python inference.py --mode api \
--url http://localhost:8000/v1/chat/completions \
--model-name glm-ocr \
--prompt "Text Recognition:"vLLM 原生支持
GlmOcrForConditionalGeneration 已在 vLLM 0.18.0 中注册,无需额外适配代码--trust-remote-code,因为模型使用自定义架构类多模态能力
显存占用
3-4 GB HBM64 GB Atlas 910 可轻松承载,无需张量并行模型特点