Instructions to use unsloth/Nanonets-OCR-s-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/Nanonets-OCR-s-GGUF with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="unsloth/Nanonets-OCR-s-GGUF") 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 AutoModel model = AutoModel.from_pretrained("unsloth/Nanonets-OCR-s-GGUF", dtype="auto") - llama-cpp-python
How to use unsloth/Nanonets-OCR-s-GGUF with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="unsloth/Nanonets-OCR-s-GGUF", filename="Nanonets-OCR-s-BF16.gguf", )
llm.create_chat_completion( 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" } } ] } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use unsloth/Nanonets-OCR-s-GGUF with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf unsloth/Nanonets-OCR-s-GGUF:UD-Q4_K_XL # Run inference directly in the terminal: llama-cli -hf unsloth/Nanonets-OCR-s-GGUF:UD-Q4_K_XL
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf unsloth/Nanonets-OCR-s-GGUF:UD-Q4_K_XL # Run inference directly in the terminal: llama-cli -hf unsloth/Nanonets-OCR-s-GGUF:UD-Q4_K_XL
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf unsloth/Nanonets-OCR-s-GGUF:UD-Q4_K_XL # Run inference directly in the terminal: ./llama-cli -hf unsloth/Nanonets-OCR-s-GGUF:UD-Q4_K_XL
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf unsloth/Nanonets-OCR-s-GGUF:UD-Q4_K_XL # Run inference directly in the terminal: ./build/bin/llama-cli -hf unsloth/Nanonets-OCR-s-GGUF:UD-Q4_K_XL
Use Docker
docker model run hf.co/unsloth/Nanonets-OCR-s-GGUF:UD-Q4_K_XL
- LM Studio
- Jan
- vLLM
How to use unsloth/Nanonets-OCR-s-GGUF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "unsloth/Nanonets-OCR-s-GGUF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "unsloth/Nanonets-OCR-s-GGUF", "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/unsloth/Nanonets-OCR-s-GGUF:UD-Q4_K_XL
- SGLang
How to use unsloth/Nanonets-OCR-s-GGUF 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 "unsloth/Nanonets-OCR-s-GGUF" \ --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": "unsloth/Nanonets-OCR-s-GGUF", "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 "unsloth/Nanonets-OCR-s-GGUF" \ --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": "unsloth/Nanonets-OCR-s-GGUF", "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" } } ] } ] }' - Ollama
How to use unsloth/Nanonets-OCR-s-GGUF with Ollama:
ollama run hf.co/unsloth/Nanonets-OCR-s-GGUF:UD-Q4_K_XL
- Unsloth Studio new
How to use unsloth/Nanonets-OCR-s-GGUF with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/Nanonets-OCR-s-GGUF to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/Nanonets-OCR-s-GGUF to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for unsloth/Nanonets-OCR-s-GGUF to start chatting
- Docker Model Runner
How to use unsloth/Nanonets-OCR-s-GGUF with Docker Model Runner:
docker model run hf.co/unsloth/Nanonets-OCR-s-GGUF:UD-Q4_K_XL
- Lemonade
How to use unsloth/Nanonets-OCR-s-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull unsloth/Nanonets-OCR-s-GGUF:UD-Q4_K_XL
Run and chat with the model
lemonade run user.Nanonets-OCR-s-GGUF-UD-Q4_K_XL
List all available models
lemonade list
Generates gibberish
I have tried the Q8 version which is on ollama and that works quite well. I'd say about 95% of the quality of the one hosted here: https://huggingface.co/spaces/Souvik3333/Nanonets-ocr-s
When I run the Q8 from Unsloth though, it's just gibberish; same for Q6. I've set the parameters correctly. Any idea why that would be? Do these quants work for anyone else?
Is this through Ollama?
Is this through Ollama?
Yes through Ollama with Msty . I tried the same models in LM Studio and they don't work properly for some reason. Not sure what Ollama does differently.
@danihend can you try redownloading and see if its fixed?
I downloaded in LM Studio as Ollama is not updated with the newest model yet. It works the same as others in LM Studio - not very well. I then imported it to Ollama and it just outputs nonsense like this in response to a image:
pdf
{
"bbox_2d": [1, 368, 497, 504],
"label": "εΎ"
}
Not sure if it's due to an error on my part or what. Does it work for you with Ollama?
Hi, I was wondering if I could get some help. I tried the BF16 model with llama-cpp-python but I don't get any output. (My llama_cpp version is 0.3.14)
Can the resolution of the images be an issue? Do I need to change the parameters? Any advice is welcome!
my code:
import os
from llama_cpp import Llama
model_path = "Nanonets-OCR-s-BF16.gguf"
mmproj_path = "mmproj-BF16.gguf"
image_path = "Swiss_QR-Bill_example.jpg" # wget https://upload.wikimedia.org/wikipedia/commons/9/9f/Swiss_QR-Bill_example.jpg
llm = Llama(
model_path=model_path,
mmproj_model_path=mmproj_path,
n_ctx=128000,
n_gpu_layers=0,
n_threads=4,
mlock=True,
verbose=False
)
prompt = """Extract the text from the above document as if you were reading it naturally. Return the tables in html format. Return the equations in LaTeX representation. If there is an image in the document and image caption is not present, add a small description of the image inside the <img></img> tag; otherwise, add the image caption inside <img></img>. Watermarks should be wrapped in brackets. Ex: <watermark>OFFICIAL COPY</watermark>. Page numbers should be wrapped in brackets. Ex: <page_number>14</page_number> or <page_number>9/22</page_number>. Prefer using β and β for check boxes."""
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": [
{"type": "image", "image": f"file://{os.path.abspath(image_path)}"},
{"type": "text", "text": prompt},
]},
]
response = llm.create_chat_completion(
messages=messages,
temperature=0.7,
min_p=0.01,
top_p=1.0,
top_k=-1,
repeat_penalty=1.0,
max_tokens=-1
)
print(response)
I get this:
{'id': 'chatcmpl-00eea211-5e4e-4675-b1a2-bdde4748271e',
'object': 'chat.completion',
'created': 1754567520,
'model': 'Nanonets-OCR-s-BF16.gguf',
'choices': [{'index': 0,
'message': {'role': 'assistant',
'content': '<watermark>Watermark Removed</watermark>'},
'logprobs': None,
'finish_reason': 'stop'}],
'usage': {'prompt_tokens': 296, 'completion_tokens': 11, 'total_tokens': 307}}