GLM-OCR · FP8 (dynamic)
8-bit quantization of zai-org/GLM-OCR for vLLM serving. Quantized by axteam.
Revision 2026-11-02 (config fix): the earlier
config.jsonexcluded the vision tower from quantization with the patternre:model\.visual\..*, which does not match the names vLLM uses for these modules (visual.*). vLLM 0.32 therefore built the vision layers as FP8 and loaded the BF16 vision weights into them, so image input gave wrong answers; text input was not affected. Onlyconfig.jsonchanged (the pattern now also matches vLLM's names); the weights are the same. Checked with vLLM 0.32.0 on 2026-11-02: the vision weights now load as BF16, and the caption of a synthetic test image ("QWEN TEST 2026") is transcribed exactly. If you downloaded this repo before 2026-11-01 23:41:41 UTC (revision3d09e56), downloadconfig.jsonagain.
| Base model | zai-org/GLM-OCR |
| Method | FP8 (dynamic) |
| Format | compressed-tensors float-quantized (scheme FP8_DYNAMIC) |
| Weights / activations | W8A8 — FP8 E4M3 weights (per-channel), dynamic per-token FP8 activations |
| Architecture | Dense · GLM text backbone + vision encoder · MTP head · document/OCR VLM |
| Size on disk | ~2.2 GB |
| Calibration | None (data-free) |
| License | mit |
Quantization details
- Scheme — W8A8 — FP8 E4M3 weights (per-channel), dynamic per-token FP8 activations, stored as compressed-tensors
float-quantized(schemeFP8_DYNAMIC). - Kept in BF16 — the vision tower (
model.visual.*), the multi-token-prediction layer, token embeddings, the LM head, and all RMSNorms (about 63% of all parameters in this build). Only the language-model backbone's attention & MLP projections are quantized, so the OCR/vision path is untouched. - Post-training quantization (no retraining). Tokenizer /
chat_template/ processor identical to the original.
Evaluation (measured)
Fidelity to the BF16 original on an internal mixed EN/KO set (100 prompts, text next-token scoring).
| Metric | This model | BF16 original |
|---|---|---|
| Perplexity (lower = closer) | 1.3726 | 1.3599 (+0.9%) |
| Top-1 next-token agreement | 96.5% | 99.4% |
Requirements
| Runtime | vLLM — the architecture is in vLLM ≥ 0.16.0; tested here with vLLM 0.32.0. |
| vLLM install | vLLM 0.32 itself needs Python 3.11–3.14, torch 2.13 (CUDA 13.0 build, so an NVIDIA driver with CUDA 13 support), transformers ≥5.16.1,<5.20 and compressed-tensors 0.17.0 (both pinned by vLLM; 0.17.0 reads this checkpoint, which was saved with 0.19.0 — do not upgrade it separately). |
| GPU | NVIDIA Turing (sm75, e.g. T4) or newer. FP8 math runs on Ada / Hopper / Blackwell (sm89+); on Turing and Ampere vLLM switches to weight-only FP8 automatically. V100 (sm70) is not supported. (Kernel choice per GPU from vLLM 0.32's selection code; only B200 was run here.) |
| Memory | Weights: 2.2 GB. Add KV cache (grows with context length × concurrent requests) and a few GB for activations / CUDA graphs; use --tensor-parallel-size N when the weights do not fit one GPU. |
| Transformers (without vLLM) | transformers>=5.1.0 + compressed-tensors>=0.15.0 (text path checked; image input not tested). |
| trust_remote_code | not needed |
Usage (vLLM)
Start an OpenAI-compatible server:
vllm serve axteam/GLM-OCR-FP8-dynamic --max-model-len 32768
Query it:
curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -d '{
"model": "axteam/GLM-OCR-FP8-dynamic",
"messages": [{"role": "user", "content": [
{"type": "image_url", "image_url": {"url": "https://example.com/your-image.png"}},
{"type": "text", "text": "Extract all text from this image."}]}],
"max_tokens": 512
}'
Offline inference in Python:
from vllm import LLM, SamplingParams
llm = LLM(model="axteam/GLM-OCR-FP8-dynamic", max_model_len=32768)
params = SamplingParams(max_tokens=1024)
# image input (URL or data: URI)
messages = [{"role": "user", "content": [
{"type": "image_url", "image_url": {"url": "https://example.com/your-image.png"}},
{"type": "text", "text": "Extract all text from this image."},
]}]
out = llm.chat(messages, params)
print(out[0].outputs[0].text)
Thinking mode is on by default in the chat template; to turn it off pass
chat_template_kwargs={"enable_thinking": False}(Pythonllm.chat(..., chat_template_kwargs=...), or"chat_template_kwargs": {"enable_thinking": false}in the request body). For task-specific OCR prompts (tables, formulas, layout) see the original model card. This is an OCR model: send an image. Text-only chat is not its purpose — in our vLLM check of this build it answered "대한민국의 수도는 어디인가요? 한 문장으로 답하세요." by repeating the question.
Reducing KV-cache memory (optional, serve-time)
The KV cache is kept in BF16 by default. KV-cache precision is a runtime choice, independent of the weight quantization above; for long contexts or large batches FP8 roughly halves KV-cache memory:
vllm serve axteam/GLM-OCR-FP8-dynamic --kv-cache-dtype fp8
License
Quantized derivative of zai-org/GLM-OCR (mit). Original weights & processor belong to the upstream authors.
한국어 요약
zai-org/GLM-OCR의 FP8 (W8A8) 양자화 빌드 · 제작 axteam
개요
| 항목 | 내용 |
|---|---|
| 원본 모델 | zai-org/GLM-OCR |
| 양자화 방식 | FP8 동적 양자화 (W8A8) |
| 저장 형식 | compressed-tensors float-quantized (scheme FP8_DYNAMIC) |
| 모델 구조 | Dense · GLM 텍스트 백본 + 비전 타워 · MTP 헤드 · 문서·OCR용 VLM |
| 용량 | 약 2.2 GB |
| 보정 데이터 | 없음 (가중치 스케일은 가중치만으로 계산, 활성화 스케일은 실행 시 계산) |
양자화 상세
- 가중치: FP8(E4M3), 출력 채널별 스케일
- 활성화: 실행 시 토큰별 동적 FP8
- 양자화 절차: PTQ(학습 후 양자화, 재학습 없음), 가중치 스케일은 미리 계산하고 활성화 스케일은 실행 시 토큰마다 계산
- BF16 유지: 비전 타워(
model.visual.*), MTP 헤드(다중 토큰 예측 층), 토큰 임베딩, LM 헤드, 모든 RMSNorm — 전체 파라미터의 약 63% - 양자화 대상: 언어모델 백본의 어텐션·MLP 선형층(projection) (OCR·비전 경로는 원본 그대로)
- 원본 파일: 토크나이저·chat template·processor는 원본과 동일
품질 (실측)
- 원본 대비 충실도: PPL 1.3726 (원본 1.3599, +0.9%, 낮을수록 원본에 가까움), 다음 토큰 top-1 일치율 96.5% (원본 자체 기준값 99.4%) — 내부 영어·한국어 혼합 프롬프트 100개, 텍스트 다음 토큰 기준으로 측정
요구사항
- 실행 엔진: vLLM 0.16.0 이상(이 구조를 지원하는 첫 버전), 이 빌드는 vLLM 0.32.0에서 실행 확인
- vLLM 0.32 설치 조건: Python 3.11~3.14, torch 2.13(CUDA 13.0 빌드, CUDA 13 지원 드라이버 필요), transformers 5.16.1 이상 5.20 미만, compressed-tensors 0.17.0 — transformers·compressed-tensors는 vLLM이 버전을 고정하므로 compressed-tensors를 따로 업그레이드하지 말 것 (이 체크포인트는 0.19.0으로 저장됐지만 0.17.0에서도 로드됨)
- GPU: NVIDIA Turing(sm75, 예: T4) 이상, V100(sm70) 미지원 — FP8 연산은 Ada·Hopper·Blackwell(sm89 이상)에서 수행, Turing·Ampere는 vLLM이 가중치 전용 FP8로 자동 전환 (GPU별 지원 여부는 vLLM 0.32 커널 선택 코드 기준, 실제 실행은 B200에서만 확인)
- 메모리: 가중치 2.2 GB + KV 캐시(컨텍스트 길이 × 동시 요청 수에 비례) + 활성화·CUDA graph용 수 GB — GPU 한 장에 다 들어가지 않으면
--tensor-parallel-size N으로 분산 - Transformers로 직접 사용: transformers 5.1.0 이상 + compressed-tensors 0.15.0 이상 (텍스트 경로만 확인, 이미지 입력은 실행 미확인)
- trust_remote_code: 불필요
사용법
- 서버 실행:
vllm serve axteam/GLM-OCR-FP8-dynamic --max-model-len 32768— OpenAI 호환 API - Python:
LLM(model="axteam/GLM-OCR-FP8-dynamic", max_model_len=32768).chat(...)— 전체 예시는 위 영어 본문 'Usage (vLLM)' 절 참고 - thinking 모드: 기본 켜짐 — 끄려면
chat_template_kwargs={"enable_thinking": False}전달(Python은llm.chat()인자, HTTP는 요청 본문의"chat_template_kwargs": {"enable_thinking": false}) - 이미지 입력: 메시지에
image_url항목 사용 - OCR 프롬프트: 표·수식·레이아웃 등 작업별 프롬프트는 원본 카드 참고
- 텍스트 전용 질문: 용도 아님, 이미지 입력으로 사용 — 이 빌드의 vLLM 점검에서 "대한민국의 수도는 어디인가요? 한 문장으로 답하세요."에 답 대신 질문을 그대로 되풀이
- KV 캐시 절감(선택):
vllm serve에--kv-cache-dtype fp8추가 — 기본 BF16인 KV 캐시를 FP8로 저장해 KV 캐시 메모리를 약 절반으로 줄임 (긴 컨텍스트·동시 요청이 많을 때 유리, 가중치 양자화와 별개인 실행 옵션)
참고
- 수정 이력 (2026-11-02, 설정 수정): 이전
config.json은 비전 타워를 양자화에서 빼는 규칙(re:model\.visual\..*)이 vLLM이 쓰는 모듈 이름(visual.*)과 맞지 않아, vLLM 0.32가 비전 층을 FP8로 만들고 BF16 비전 가중치를 그대로 넣었음 → 이미지 입력 답이 틀림(텍스트 입력은 영향 없음) —config.json의 규칙만 vLLM 이름까지 맞게 고침(가중치 동일) — vLLM 0.32.0 확인(2026-11-02): 비전 가중치가 BF16으로 로드됨, 모델이 시험 그림의 글자("QWEN TEST 2026")를 정확히 옮겨 적음 — 2026-11-01 23:41:41 UTC(리비전3d09e56) 이전에 받았다면config.json만 다시 받을 것
라이선스
- 라이선스: MIT — 원본 모델의 라이선스를 그대로 따름
- 권리: 원본 가중치·processor는 Z.ai 소유, 이 리포는 양자화 파생물