Instructions to use lightonai/LightOnOCR-2-1B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lightonai/LightOnOCR-2-1B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="lightonai/LightOnOCR-2-1B") 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)# Load model directly from transformers import AutoProcessor, AutoModelForSeq2SeqLM processor = AutoProcessor.from_pretrained("lightonai/LightOnOCR-2-1B") model = AutoModelForSeq2SeqLM.from_pretrained("lightonai/LightOnOCR-2-1B") 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=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use lightonai/LightOnOCR-2-1B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lightonai/LightOnOCR-2-1B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lightonai/LightOnOCR-2-1B", "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/lightonai/LightOnOCR-2-1B
- SGLang
How to use lightonai/LightOnOCR-2-1B 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 "lightonai/LightOnOCR-2-1B" \ --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": "lightonai/LightOnOCR-2-1B", "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 "lightonai/LightOnOCR-2-1B" \ --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": "lightonai/LightOnOCR-2-1B", "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 lightonai/LightOnOCR-2-1B with Docker Model Runner:
docker model run hf.co/lightonai/LightOnOCR-2-1B
Incredible Model, Thank You!
I just wanted to take a moment to thank the development team at LightOn AI for this model.
I process very complex legal documents that can have strange formatting, mixture of one and two columns on the same page, inconsistent fonts and font sizes, variable headers, unusual signature blocks, tables with definitions, etc. Not only is this model perfectly accurate in my tests so far, but the speed is staggering. I previously had to use large visual models that could comprehend the content and parse out the formatting, and it could take up to one minute per page at times for dense agreements. This model retrieves perfect content in less than 2 seconds per page (RTX 6000 Pro or RTX 5090). And it basically uses no VRAM compared to the larger models I was using previously. And does not require any specialized pipeline, I dropped this model in my OCR pipeline and it worked on the first shot. This is a miracle! :)
If there are any VCs/PE firms looking for a great investment, call up this company and see if they want your money! This is an amazing product that will kill in enterprise.
Thank you again LightOn team, the community appreciates your work here!
MD
My use case is also legal documents, and I agree this model is really great. I have gotten far better results with this model than deepseek OCR 1 and 2. I appreciate how it retains page numbers in the headers and footers. This is important because lawyers need to cite page numbers. Thank you.
My use case is also legal documents, and I agree this model is really great. I have gotten far better results with this model than deepseek OCR 1 and 2. I appreciate how it retains page numbers in the headers and footers. This is important because lawyers need to cite page numbers. Thank you.
same here. as a lawyer, i work with badly scanned documents A LOT. so i've (we've?) built an app to run local ocr models locally with mlx-vlm and pretty ui using 5.3-codex via codex app
i've used 4 recently released models converted to mlx format by mlx-community:
- DeepSeek-OCR-2-bf16
- GLM-OCR-bf16
- LightOnOCR-2-1B-bf16
- PaddleOCR-VL-1.5-bf16
i've tested them all a bit and so far the most usable one is LightOnOCR-2 by @lightonai. tbh i thought i was going to be deepseek-ocr-2 because (i) their model is bigger (3b vs 1b) and (ii) c'mon it's deepseek
idk maybe the reason other models are lagging has smth to do with how they were converted to mlx
will keep testing but huge thanks to lighton team for sharing a great open model with the community! i'll definitely use their model a lot (until a better one comes out obviously)
what a time to be alive!
(this is mostly a copy of my recent tweet - just thought it'd be nice to repeat it here to once again thank the team - you did a great job!)