--- library_name: transformers pipeline_tag: image-text-to-text base_model: llamaindex/OCRia-1 base_model_relation: quantized license: other license_name: ocria-1-license license_link: LICENSE language: - en tags: - ocr - pdf - markdown - document-parsing - tables - charts - parsebench - autoround - w4a16 - gptq - llm-compressor - compressed-tensors - quantized - vllm --- # OCRia-1 — W4A16 Quantized Collection This repository is part of the **W4A16 (4-bit weight, 16-bit activation)** quantized release of [llamaindex/OCRia-1](https://huggingface.co/llamaindex/OCRia-1) (fine-tuned from [Qwen/Qwen3.5-4B](https://huggingface.co/Qwen/Qwen3.5-4B)), quantized using [Intel AutoRound](https://github.com/intel/auto-round) (`SignRoundConfig`) and exported across three standard inference formats for drop-in compatibility with vLLM and Hugging Face Transformers. All non-weight auxiliary files from the upstream repository—including `prompt.txt`, `ocria_grounding/`, `fast_layout_models/`, `parse_rl_utils/`, `examples/`, and `LICENSE`—are bundled in each repository so layout grounding and prompt templates work out of the box. ## Available Quantized Models All three repositories share the exact same SignRound-optimized W4A16 calibration weights (`group_size=32`, symmetric) and differ only in their serialization schema: | Repository | Serialization Format | Target Runtimes & Kernels | | :--- | :--- | :--- | | **[OpenTensorLab/OCRia-1-W4A16-GPTQ](https://huggingface.co/OpenTensorLab/OCRia-1-W4A16-GPTQ)** | AutoGPTQ (`auto-gptq`) | vLLM (GPTQ / Marlin kernels), TGI, AutoGPTQ | | **[OpenTensorLab/OCRia-1-W4A16-AutoRound](https://huggingface.co/OpenTensorLab/OCRia-1-W4A16-AutoRound)** | AutoRound (`auto-round`) | vLLM (GPTQ / Marlin kernels), Transformers, AutoRound | | **[OpenTensorLab/OCRia-1-W4A16-LLM-Compressor](https://huggingface.co/OpenTensorLab/OCRia-1-W4A16-LLM-Compressor)** | Compressed-Tensors (`llm-compressor`) | vLLM (Compressed-Tensors / Marlin kernels), Neural Magic | ## Quantization Recipe & Architecture Details To preserve OCR fidelity, dense table structure, and visual token alignment on the Qwen3.5 hybrid architecture (`GatedDeltaNet` linear attention + full self-attention + Vision Transformer), selective layer preservation was applied during quantization: * **Algorithm:** Intel AutoRound (`SignRoundConfig` with `iters=1000`, `gradient_accumulate_steps=4`, effective batch size `8`). * **Precision & Grouping:** `W4A16`, symmetric (`sym=True`), `group_size=32` (compatible with vLLM Marlin/GPTQ kernels). * **Calibration:** `512` samples at `4096` sequence length (`NeelNanda/pile-10k`). * **Unquantized Modules (Kept in BF16):** * **Vision Encoder & Merger (`model.visual.*`):** All 24 vision blocks and the patch merger remain unquantized (`quant_nontext_module=False`) to prevent degradation on small text, formulas, and chart labels. * **Linear Attention Layers (`linear_attn.*`):** All Qwen3.5 `GatedDeltaNet` recurrent/linear attention projections (`in_proj_qkv`, `in_proj_z`, `in_proj_a`, `in_proj_b`, `out_proj`) are excluded (`ignore_layers`) to maintain numerical stability across long pages. * **Embeddings & Output Head (`embed_tokens`, `lm_head`):** Preserved in `bfloat16`. * **Quantized Modules:** Standard self-attention projections (`q_proj`, `k_proj`, `v_proj`, `o_proj`) and MLP layers (`gate_proj`, `up_proj`, `down_proj`) across the language decoder layers. ## Quickstart: Serving with vLLM Serve any of the three repositories with vLLM (`>= 0.30`). Because Qwen3.5 hybrid layers compile Triton/CUDA kernels on startup, ensure the CUDA toolkit (`nvcc`) is available in your environment (included in `vllm/vllm-openai` images): ```bash vllm serve OpenTensorLab/OCRia-1-W4A16-GPTQ \ --port 8000 \ --host 0.0.0.0 \ --max-model-len 42k \ --kv-cache-dtype fp8 \ --gpu-memory-utilization 0.90 \ --enable-prefix-caching \ --enable-chunked-prefill \ --trust-remote-code \ --dtype bfloat16 \ --limit-mm-per-prompt '{"image": 1}' ``` *(Replace `OpenTensorLab/OCRia-1-W4A16-GPTQ` with `OpenTensorLab/OCRia-1-W4A16-AutoRound` or `OpenTensorLab/OCRia-1-W4A16-LLM-Compressor` depending on your preferred weight format.)* ### Python Client Inference (OpenAI-Compatible API) Send one page image per request using the bundled `prompt.txt` as the system message. **Keep thinking disabled** (`enable_thinking: False`) and decode greedily (`temperature=0.0`); the Qwen3.5 chat template enables thinking by default, which breaks OCRia-1's structured Markdown/HTML output format. ```python import base64 import re from huggingface_hub import hf_hub_download from openai import OpenAI REPO_ID = "OpenTensorLab/OCRia-1-W4A16-GPTQ" # Load the exact system prompt bundled in this repository prompt = open(hf_hub_download(REPO_ID, "prompt.txt"), encoding="utf-8").read() with open("page.png", "rb") as f: page_b64 = base64.b64encode(f.read()).decode("utf-8") client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY") resp = client.chat.completions.create( model=REPO_ID, messages=[ {"role": "system", "content": prompt}, { "role": "user", "content": [ { "type": "image_url", "image_url": {"url": f"data:image/png;base64,{page_b64}"}, } ], }, ], temperature=0.0, max_tokens=24576, extra_body={"chat_template_kwargs": {"enable_thinking": False}}, ) raw_text = resp.choices[0].message.content match = re.search(r"```markdown\n(.*?)(?:\n```|$)", raw_text, re.S) markdown_output = match.group(1) if match else raw_text print(markdown_output) ``` ### Input Preprocessing Guidelines * **Resolution & Image Budget:** Render PDF pages at 300 DPI (e.g., `page.get_pixmap(dpi=300)` in `pymupdf`) and downscale to ~4.1 megapixels (~210 DPI on US Letter) to match OCRia-1's evaluation profile: ```python from PIL import Image img = Image.open("page.png").convert("RGB") scale = min(1.0, (4_100_000 / (img.width * img.height)) ** 0.5) img = img.resize((round(img.width * scale), round(img.height * scale)), Image.LANCZOS) ``` * **Token Budget:** Keep `max_tokens=24576` (and `--max-model-len` around `32768`–`42k`) as dense multi-column pages and large HTML financial tables regularly exceed 16k output tokens. ## Model Capabilities & Output Schema OCRia-1 transcribes a single page image directly into structured Markdown without an external OCR engine: | Content Type | Output Representation | | --- | --- | | **Tables & Charts** | HTML `