LEO: Boosting Mixture of Vision Encoders for Multimodal Large Language Models
Paper • 2501.06986 • Published
How to use dipankar500/NetraOCR-1.0 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-text-to-text", model="dipankar500/NetraOCR-1.0")
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, AutoModelForSeq2SeqLM
processor = AutoProcessor.from_pretrained("dipankar500/NetraOCR-1.0")
model = AutoModelForSeq2SeqLM.from_pretrained("dipankar500/NetraOCR-1.0", 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]:]))How to use dipankar500/NetraOCR-1.0 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "dipankar500/NetraOCR-1.0"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "dipankar500/NetraOCR-1.0",
"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 run hf.co/dipankar500/NetraOCR-1.0
How to use dipankar500/NetraOCR-1.0 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "dipankar500/NetraOCR-1.0" \
--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": "dipankar500/NetraOCR-1.0",
"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 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 "dipankar500/NetraOCR-1.0" \
--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": "dipankar500/NetraOCR-1.0",
"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"
}
}
]
}
]
}'How to use dipankar500/NetraOCR-1.0 with Docker Model Runner:
docker model run hf.co/dipankar500/NetraOCR-1.0
NetraOCR-1.0 is a unified, single-checkpoint 1,273,967,936-parameter multimodal OCR model built on the Qwen3.5-0.8B hybrid Gated-DeltaNet + full-attention architecture. It combines IndicOCR (bodhan-ai/indic-ocr) and OvisOCR3 (ATH-MaaS/OvisOCR3) into a single model via Branch-Train-MiX (BTX, arXiv:2403.07816) and Dual Interleaved Vision Token Fusion (Leo, arXiv:2501.06986).
model.visual (OvisOCR3 ViT + merger) and model.visual_indic (IndicOCR ViT + merger).[indic(h,w), ovis(h,w)] with 3D M-RoPE temporal coordinates $t=0$ (Indic) and $t=1$ (Ovis).max_abs_drift = 0.0), while both 2-layer MLP mergers (visual.merger and visual_indic.merger) are trained to project into a shared latent space.NetraMoEFFN):GatedDeltaNet layers + 6 full-attention layers) and RMSNorms are initialized by exact arithmetic weight averaging (M0_avg) and trained end-to-end in Stage M2.NetraMoEFFN containing Expert 0 (IndicOCR FFN, frozen) and Expert 1 (OvisOCR3 FFN, frozen) weighted by a learned token-level linear router (router.weight $\in \mathbb{R}^{2 \times 1024}$).303,101 tokens, padded to 303,104):248,070 OvisOCR3/Qwen3.5 tokens at identical IDs (0..248,069) and appends 55,031 pure-Indic-script tokens from Sarvam's tokenizer (248,070..303,100), initialized via orthogonal Procrustes alignment ($s = 1.1483$, median cosine similarity $0.830$ across $85,892$ shared tokens).split_page_regions(img) in processing_netra.py to automatically segment high-resolution multi-line handwritten ledger pages into horizontal text bands prior to area_clamp.import torch
from PIL import Image
from modeling_netra import NetraForConditionalGeneration
from processing_netra import NetraProcessor, area_clamp, split_page_regions
model_id = "dipankar500/NetraOCR-1.0"
model = NetraForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.bfloat16).cuda().eval()
proc = NetraProcessor.from_pretrained(model_id, frames=2)
img = area_clamp(Image.open("sample.png").convert("RGB"))
prompt = proc.prompt("Extract all text from the image.")
batch = {k: v.cuda() for k, v in proc([prompt], [img]).items()}
with torch.no_grad(), torch.autocast("cuda", dtype=torch.bfloat16):
out = model.generate(**batch, max_new_tokens=512, do_sample=False)
text = proc.decode(out[0, batch["input_ids"].shape[1]:])
print(text)