How to Run Soma-1X Lite Locally: Turn PDFs into Structured JSON with vLLM

A hands-on Soma-1X Lite tutorial: serve the 2B open OCR model with vLLM or llama.cpp, render PDF pages with PyMuPDF, call the OpenAI-compatible endpoint with the trained prompts, parse the block output into JSON, and let your coding agent test the endpoint with Apidog CLI.

Ashley Innocent

Ashley Innocent

1 December 2026

How to Run Soma-1X Lite Locally: Turn PDFs into Structured JSON with vLLM

Apidog for Enterprise

On-Premises Deploy

SSO & RBAC

SOC 2 Compliant

Explore Apidog Enterprise

To run Soma-1X Lite locally, serve the open weights with vllm serve AminiTech/Soma-1X-lite on one GPU (or with llama.cpp or Ollama on a CPU), render each PDF page to a PNG with PyMuPDF, send it to the OpenAI-compatible /v1/chat/completions endpoint with the model’s trained prompts, and parse the <block> tags it returns into JSON records with a label, a bounding box and the content.

What is Soma-1X Lite?

Soma-1X Lite is a 2-billion-parameter open-weight vision-language model from Amini, released on November 25, 2026, that turns document page images into structured output. It’s a fine-tune of Qwen3.5-2B under the Apache 2.0 licence, and it returns every page element with a semantic label, a bounding box and its text, in reading order.

These figures come from the model card and Amini’s technical post, and all are Amini’s own measurements:

Spec Value
Parameters 2B, fine-tuned from Qwen3.5-2B (SFT, then GRPO with verifiable rewards)
Licence Apache 2.0
Output One <block label="..." box="x0 y0 x1 y1"> per element, boxes on a 0 to 1000 grid
Tables and math HTML tables, LaTeX equations
olmOCR-Bench 84.7
OmniParse-Bench 84.37, or 86.53 with a multi-pass harness
Throughput Up to 15,000 pages per hour on one RTX PRO 6000

There are 15 labels: text, heading, caption, footnote, page_header, page_footer, annotation, image, chart, diagram, map, stamp, signature, table and equation. You get layout, not just characters.

How the local OCR pipeline works

You need four pieces: a PDF renderer, a model server, a client that calls it, and a parser that turns tagged text into JSON.

Sequence: for each PDF page, soma_pdf.py asks PyMuPDF to render a 1,792-pixel PNG, posts it to the local /v1/chat/completions endpoint with the trained prompts, gets block tags back, and parses them into JSON records

Every serving option exposes the same OpenAI-style API, so switching from vLLM to llama.cpp changes only the base URL.

Step 1: Serve Soma-1X Lite with vLLM

On a machine with an NVIDIA GPU, install vLLM and start the server with the flags from the model card:

pip install -U vllm openai huggingface_hub pymupdf

vllm serve AminiTech/Soma-1X-lite \
    --served-model-name soma-1x-lite \
    --host 127.0.0.1 \
    --port 8000 \
    --dtype bfloat16 \
    --tensor-parallel-size 1 \
    --max-model-len 32768 \
    --gpu-memory-utilization 0.90 \
    --default-chat-template-kwargs '{"enable_thinking": false}'

--default-chat-template-kwargs turns thinking off, which is how the model was trained to answer. --max-model-len 32768 leaves room for the image plus a long page of output. New to vLLM? Our vLLM guide covers installs and GPU memory.

Step 2: Render PDF pages with PyMuPDF

The model reads images, not PDFs. PyMuPDF renders each page at a 1,792-pixel long edge, the size the model card uses. In PyMuPDF 2.x, import pymupdf: the old fitz name now prints a deprecation warning.

Step 3: Call the endpoint with the trained prompts

Soma-1X Lite was trained with two prompt files from its repo: system_prompt.txt (label rules and output format) and user_prompt.txt (“Parse the page into layout blocks with their text.”). Load them from Hugging Face rather than writing your own, and set temperature to 0.

Step 4: Parse the block output into JSON

The reply is plain text with one tag per element:

<block label="heading" box="87 81 775 111">Quarterly Field Report: Maize Yields</block>
<block label="table" box="87 179 505 273"><table>
<tr><th>Site</th><th>Planted (ha)</th>...</table></block>
<block label="page_footer" box="85 953 161 965">Page 1 of 1</block>

Three details shape the parser. A signature block has no text and is self-closing (<block label="signature" box="..."/>). An empty page returns exactly [EMPTY PAGE]. Image, chart, diagram, map and stamp blocks open with a <desc>...</desc> description.

Here is the complete script for Steps 2 to 4. Save it as soma_pdf.py:

import base64, json, os, re, sys
import pymupdf
from huggingface_hub import hf_hub_download
from openai import OpenAI

MODEL_ID = "AminiTech/Soma-1X-lite"
client = OpenAI(base_url=os.getenv("SOMA_URL", "http://localhost:8000/v1"), api_key="EMPTY")
prompt = lambda name: open(hf_hub_download(MODEL_ID, name), encoding="utf-8").read()
SYSTEM, USER = prompt("system_prompt.txt"), prompt("user_prompt.txt")

BLOCK = re.compile(
    r'<block label="(?P<label>[a-z_]+)" box="(?P<box>\d+ \d+ \d+ \d+)"'
    r'(?:\s*/>|>(?P<content>.*?)</block>)', re.S)

def render(page, long_edge=1792):
    scale = long_edge / max(page.rect.width, page.rect.height)
    pix = page.get_pixmap(matrix=pymupdf.Matrix(scale, scale), alpha=False)
    return pix.tobytes("png"), pix.width, pix.height

def parse(raw, page_no, w, h):
    if raw.strip() == "[EMPTY PAGE]":
        return []
    out = []
    for i, m in enumerate(BLOCK.finditer(raw)):
        box = [int(v) for v in m["box"].split()]
        out.append({"page": page_no, "order": i, "label": m["label"], "box": box,
                    "box_px": [round(box[0]*w/1000), round(box[1]*h/1000),
                               round(box[2]*w/1000), round(box[3]*h/1000)],
                    "content": (m["content"] or "").strip()})
    return out

blocks = []
with pymupdf.open(sys.argv[1]) as pdf:
    for n, page in enumerate(pdf, start=1):
        png, w, h = render(page)
        url = "data:image/png;base64," + base64.b64encode(png).decode()
        resp = client.chat.completions.create(
            model="soma-1x-lite", temperature=0.0, max_tokens=16384,
            messages=[{"role": "system", "content": SYSTEM},
                      {"role": "user", "content": [
                          {"type": "image_url", "image_url": {"url": url}},
                          {"type": "text", "text": USER}]}])
        blocks += parse(resp.choices[0].message.content, n, w, h)

json.dump(blocks, sys.stdout, ensure_ascii=False, indent=2)

Run it with python soma_pdf.py report.pdf > report.json. box keeps the 0 to 1000 grid; box_px maps it to pixels on the rendered page, for cropping a table or drawing highlights.

Schema: each block tag from the model maps to a JSON record; the label becomes label, the box on a 0 to 1000 grid becomes box and box_px in pixels, and the inner text, HTML table or LaTeX becomes content

Run Soma-1X Lite on a laptop with llama.cpp or Ollama

No NVIDIA GPU? Amini publishes GGUF builds: Soma-1X-lite-Q8_0.gguf (2.0 GB, recommended) or Soma-1X-lite-BF16.gguf (3.8 GB), plus the vision encoder mmproj-Soma-1X-lite-F16.gguf (0.7 GB). There’s no 4-bit build: Amini says it hurt layout detection.

With llama.cpp, one command downloads both files and serves the same API on port 8080:

llama-server -hf AminiTech/Soma-1X-lite-GGUF:Q8_0 \
    --jinja \
    --ctx-size 32768 \
    --image-min-tokens 64 \
    --image-max-tokens 16384 \
    --chat-template-kwargs '{"enable_thinking": false}' \
    --port 8080

Then point the script at it: SOMA_URL=http://localhost:8080/v1 python soma_pdf.py report.pdf.

Schema: the soma_pdf.py client calls an OpenAI-compatible endpoint served by vLLM on port 8000 from the safetensors weights on a GPU, or by llama-server on port 8080 from the Q8 GGUF plus vision encoder; Ollama runs the same GGUF from its CLI

We ran this on an Apple M1 Pro laptop (32 GB RAM) with Homebrew’s llama.cpp 1.1.0, loading the same Q8 and encoder files with -m and --mmproj. A one-page test report took about 28 seconds end to end, 20 on the server: 12 seconds to read 3,392 prompt tokens (image plus system prompt), 8 to write 347. It returned five blocks: heading, text, table, text and page_footer.

Two things we noticed. Our borderless, tightly spaced test table came back with “North plot” and “120” merged into one cell, so check tables on your own layouts. And llama.cpp 1.1.0 warns that --chat-template-kwargs for thinking is deprecated in favour of --reasoning off; the card’s flag still worked.

For Ollama, download the Q8 weights, the encoder and the repo’s Modelfile (it sets the system prompt, temperature 0 and a 32K context), then create the model:

hf download AminiTech/Soma-1X-lite-GGUF \
    Soma-1X-lite-Q8_0.gguf mmproj-Soma-1X-lite-F16.gguf Modelfile \
    --local-dir soma-1x-lite
cd soma-1x-lite
ollama create soma-1x-lite -f Modelfile
ollama run soma-1x-lite --think=false "Parse the page into layout blocks with their text. ./document.png"

New to Ollama? Start with our Ollama guide.

Is Soma-1X Lite the best local OCR model?

It’s a strong candidate for its size, but read the scores with care. Every benchmark number on the card is Amini’s own run. Its olmOCR-Bench chart compares API models whose scores come from three different third-party evaluations (Unsiloed AI, Interfaze and the Nanonets IDP Leaderboard), each with its own harness, so those rows aren’t like-for-like.

The most distinctive claim is African-language transcription: a 2.90% mean character error rate across 10 languages on 435 held-out pages, best of five open models in 7 of 10. That test set is internal and covers open models only. On language-specific characters, Soma kept 93% of Hausa hooked letters, 99% of Yoruba dots-below and 87% of Lingala open vowels, against 60%, 69% and 25% for the best other model tested.

For alternatives, see our guides to DeepSeek-OCR, GLM-OCR and Mistral OCR. The honest test is your own documents: run 20 representative pages through each and diff the JSON.

Let your coding agent test the OCR endpoint with Apidog CLI

Your parser depends on one contract: the endpoint answers 200 with well-formed <block> tags and the labels you expect. A new GGUF build, a changed prompt or a forgotten server flag can break that without an error. Don’t check it by hand. Have your coding agent (Claude Code, Codex, Cursor) save it as a test with Apidog CLI and run it after every change.

Install the CLI and agent skill once:

npm install -g apidog-cli@latest
apidog login --with-token <YOUR_TOKEN>
npx -y skills add https://apidog.com   # pick your agent when prompted

Then give your agent one prompt:

Create an Apidog test scenario in project <projectId> called "Soma-1X Lite parse check". Add one custom HTTP step that posts page 1 of report.pdf, rendered to an image, with Soma-1X Lite's system_prompt.txt and user_prompt.txt, to http://127.0.0.1:8080/v1/chat/completions. Assert status 200, finish_reason "stop", a heading block, a table block in HTML and the text "North plot". Validate the steps with the CLI schema, run the scenario and summarize any failures.

The agent reads the schema, validates its steps, creates the scenario and runs it:

apidog cli-schema get test-scenario-update
apidog cli-schema validate test-scenario-update --file steps.json
apidog test-scenario create --project <projectId> --file create.json
apidog test-scenario update <scenarioId> --project <projectId> --file steps.json
apidog run -t <scenarioId> --project <projectId> -e <envId> -r cli
Apidog CLI running the Soma-1X Lite parse check against a local llama-server: one page posted to /v1/chat/completions, 6 of 6 assertions pass for status, finish_reason, heading block, HTML table and transcribed text

Swap -r cli for -r junit to run it in CI, as in our Apidog CLI CI/CD pipeline guide. For agent setup, see Apidog CLI in Claude Code.

When your team has several of these pipelines to build and test, Sharkly lets you hand them out as tasks to coding agents that run on your own computers with your own Claude Code, Codex or Gemini CLI plan, and review what each one ships; it’s free to start.

FAQ

Can Soma-1X Lite run without an NVIDIA GPU? Yes. The GGUF builds run through llama.cpp or Ollama on a CPU or a single GPU. Our M1 Pro laptop took about 20 seconds for one full page, so use vLLM on a GPU for large batches.

What does Soma-1X Lite output? One <block> per page element with a label, a box on a 0 to 1000 grid and the content. Tables come back as HTML, equations as LaTeX, and figures start with a short <desc> description.

Do I need the system prompt? Yes. The model was trained on system_prompt.txt and user_prompt.txt with thinking disabled and temperature 0. A custom prompt changes the output format your parser relies on.

Is Soma-1X Lite free for commercial use? The weights are Apache 2.0, which allows commercial use. Running it locally costs only your hardware.

Which languages does it support? The model card lists English, French, Spanish, Swahili, Yoruba, Hausa, Wolof, Lingala, Xhosa, Afrikaans, Kinyarwanda, Chichewa and Sango.

Can I use it as an open source OCR API? Yes. vLLM, SGLang and llama-server all expose an OpenAI-compatible /v1/chat/completions endpoint, so any OpenAI client can call your local server.

Conclusion

Soma-1X Lite is a 2B document parser you can host yourself: vLLM for throughput, llama.cpp or Ollama on a laptop. Render pages at 1,792 pixels, use the trained prompts, parse the blocks into JSON, and keep a test on the endpoint. Try Apidog free and let your agent run that check on every change.

Explore more

Best Open-Source OCR Models in 2027

Best Open-Source OCR Models in 2027

Eight open OCR models compared on size, licence, olmOCR-Bench score, output format, handwriting and local runtimes, with pick-X-if guidance and a way to test two side by side.

1 December 2026

How to Use MCP Inspector to Test Your MCP Server

How to Use MCP Inspector to Test Your MCP Server

A step-by-step MCP Inspector tutorial: launch the web UI or CLI, check the handshake, list and call tools, test resources and prompts, then turn the checks into a CI smoke test and an Apidog CLI suite your coding agent maintains.

1 December 2026

Claude Code Router: How to Run Claude Code With Any Model

Claude Code Router: How to Run Claude Code With Any Model

Want to run Claude Code with any model? Learn how Claude Code Router connects GLM, DeepSeek and OpenRouter, then set up routing and fallbacks.

1 December 2026

Practice API Design-first in Apidog

Discover an easier way to build and use APIs

How to Run Soma-1X Lite Locally: Turn PDFs into Structured JSON with vLLM