Instructions to use Vishva007/OCRia-1-W4A16-AutoRound with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Vishva007/OCRia-1-W4A16-AutoRound with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Vishva007/OCRia-1-W4A16-AutoRound") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("Vishva007/OCRia-1-W4A16-AutoRound") model = AutoModelForMultimodalLM.from_pretrained("Vishva007/OCRia-1-W4A16-AutoRound", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Vishva007/OCRia-1-W4A16-AutoRound with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Vishva007/OCRia-1-W4A16-AutoRound" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Vishva007/OCRia-1-W4A16-AutoRound", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/Vishva007/OCRia-1-W4A16-AutoRound
- SGLang
How to use Vishva007/OCRia-1-W4A16-AutoRound with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Vishva007/OCRia-1-W4A16-AutoRound" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Vishva007/OCRia-1-W4A16-AutoRound", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Vishva007/OCRia-1-W4A16-AutoRound" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Vishva007/OCRia-1-W4A16-AutoRound", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use Vishva007/OCRia-1-W4A16-AutoRound with Docker Model Runner:
docker model run hf.co/Vishva007/OCRia-1-W4A16-AutoRound
OCRia-1 — W4A16 Quantized Collection
This repository is part of the W4A16 (4-bit weight, 16-bit activation) quantized release of llamaindex/OCRia-1 (fine-tuned from Qwen/Qwen3.5-4B), quantized using Intel AutoRound (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 |
|---|---|---|
| Vishva007/OCRia-1-W4A16-GPTQ | AutoGPTQ (auto-gptq) |
vLLM (GPTQ / Marlin kernels), TGI, AutoGPTQ |
| Vishva007/OCRia-1-W4A16-AutoRound | AutoRound (auto-round) |
vLLM (GPTQ / Marlin kernels), Transformers, AutoRound |
| Vishva007/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 (
SignRoundConfigwithiters=1000,gradient_accumulate_steps=4, effective batch size8). - Precision & Grouping:
W4A16, symmetric (sym=True),group_size=32(compatible with vLLM Marlin/GPTQ kernels). - Calibration:
512samples at4096sequence 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.5GatedDeltaNetrecurrent/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 inbfloat16.
- Vision Encoder & Merger (
- 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):
vllm serve Vishva007/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 Vishva007/OCRia-1-W4A16-GPTQ with Vishva007/OCRia-1-W4A16-AutoRound or Vishva007/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.
import base64
import re
from huggingface_hub import hf_hub_download
from openai import OpenAI
REPO_ID = "Vishva007/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)inpymupdf) and downscale to4.1 megapixels (210 DPI on US Letter) to match OCRia-1's evaluation profile:
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-lenaround32768–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 <table> with colspan / rowspan (charts are converted into tables of underlying data points) |
| Diagrams & Flowcharts | Fenced ````mermaid` blocks |
| Mathematics | Inline $ ... $ and display $$ ... $$ LaTeX (including handwritten equations) |
| Chemical Formulas | Plain text with HTML <sub> and <sup> (e.g., K<sub>3</sub>Fe(CN)<sub>6</sub>) |
| Text Formatting | **bold**, *italic*, ~~strikethrough~~, <u>underline</u>, <mark> highlights |
| Forms & Checkboxes | [ ], [x], and [___] for blank fill-in fields |
| Embedded Visuals | ![label: description] (logo, icon, photo, illustration, screenshot, map, signature, seal, code, drawing, image) |
| Page Furniture | <page_header>, <page_footer>, <page_number>, and <watermark> tags |
Experimental Layout Grounding (ocria_grounding)
All files required for post-generation bounding box extraction (ocria_grounding/, fast_layout_models/, parse_rl_utils/, and examples/) are included directly in this repository. For full details on PDF text-layer alignment, Heron layout detection, and fast-layout CPU postprocessing, refer to the upstream llamaindex/OCRia-1 documentation.
🚀 Deploy on RunPod
One-click launch environments pre-configured with PyTorch, CUDA, and dependencies for fine-tuning or quantization.
🎁 Need GPU compute? Sign up via RunPod and get $5–$500 in free credits when you add your first $10.
PyTorch 2.15
PyTorch 2.14
PyTorch 2.13
PyTorch 2.12
License & Attribution
This quantized release inherits the OCRia-1 Model and Code License (based on AI Pubs Open RAIL-M) from llamaindex/OCRia-1:
- Research & Personal Use: Free for academic/non-profit research, benchmarking, internal R&D, and personal use.
- Commercial Use: Free for organizations under $2M in annual revenue and under $2M in total funding, provided the model is not used in a document parsing/OCR product or service competing with LlamaParse or LlamaCloud. Contact LlamaIndex for commercial licensing.
- Base Architecture: Fine-tuned from Qwen/Qwen3.5-4B (Apache-2.0).
Citation
@misc{rangapur2026ocria1,
title = {{OCRia-1} Technical Report},
author = {Rangapur, Aman and Jimeno Yepes, Antonio and Bustamante, Daniel and Dendumrongsup, Nutchapol and
Acosta, Sebasti{\'a}n G. and Doulcet, Pierre-Lo{\"i}c and Suo, Simon},
year = {2026},
eprint = {2611.00092},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2611.00092},
}
- Downloads last month
- -