Skip to content

ocr: GLM-OCR reader on /v1/ocr (#2440 step 3) - #2572

Merged
ashhart merged 4 commits into
ashhart:mainfrom
laudney:ocr-3-glm-ocr
Nov 21, 2026
Merged

ashhart merged 4 commits into
ashhart:mainfrom
laudney:ocr-3-glm-ocr

Conversation

@laudney

@laudney laudney commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor
Before (#2571) After
GLM-OCR on /v1/ocr no reader (400) page Markdown as one block, no boxes (blocks: [])

Step 3 of the stack #2440 set out. It follows #2571, now on main.

#2440 gate or #2530 ask Proof in this pull request
GLM-OCR's Markdown equals what the chat route returns for the same image and prompt prompt_ids_test.zig GLM row (same prompt ids); page_markdown_test.zig (the same scripted reply on both routes: page Markdown equals the chat content); GLM ocr_test.zig (the reader keeps its recorded chat reply byte for byte, except HTML tables and \(...\) math, which it normalizes on purpose)
Ask 3 on gfx1201 below: same prompt (304 tokens) and same reply (35 tokens, same SHA); the page Markdown equals the chat content exactly

What this changes

GLM-OCR gets an OCR reader: its reply is the page's Markdown as one block, normalized to the flavour both readers write (pipe tables, or HTML when cells span; $...$ math). It gives no geometry, so Mistral replies carry blocks: [], and extract_header is refused.

Checks on this head

  • Head commit: ce19d41b8, on main 61fe90343. Rebuilt like ocr: PDF documents and pages on /v1/ocr, one page at a time (#2440 step 2) #2571: the step-3 change applied to main in 3 commits with the original messages. Each file's change equals the reviewed head 2162c6e25. The one exception is CHANGELOG.md, which this pull request no longer touches, as with ocr: PDF documents and pages on /v1/ocr, one page at a time (#2440 step 2) #2571's landing.
  • Lean checker, python3 tools/zig/lean_check.py: 168 on main and 168 on this head, the same list, 0 new.
  • Tests run, with the command and pass, fail and skip counts:
    • zig build test-ocr-host test-api-boundaries test-server-cpu test-dots-mocr-host test-glm-ocr-host check-native-hip-host -Dhip=true: 24/24 steps, 1779 of 1798 pass, 19 skip, 0 fail
    • the first commit alone, zig build test-server-cpu test-glm-ocr-host check-native-hip-host -Dhip=true: 15/15 steps, 1649 of 1663 pass, 14 skip, 0 fail
    • zig fmt --check zig/src build.zig zig/build and git diff --check: clean
  • CI: pending on this head. A test merge into main 61fe90343 is clean.
  • Not run, and why: the dots.mocr oracle-run test and the PDF tests skip here (no TF_DOTS_OCR_DIR runs and no PDFium on this run); this step does not change the PDF path. CUDA, Metal and Windows: no OCR reader is offered there; the readers are wired into the HIP offers only.

Receipt

  • Ask 3, /v1/ocr next to /v1/chat/completions, GLM-OCR, prompt "Text Recognition:", temperature 0, thinking off:

    Route Prompt tokens Reply tokens Reply token SHA Text
    /v1/ocr 304 35 9505fe5c4ffd page Markdown Scanned receipt 4471\nPaid on 2026-11-07\nTotal due: 58.20 EUR
    /v1/chat/completions 304 35 9505fe5c4ffd the same string
  • Client receipts (GLM-OCR, mistralai 3.7.0): 2-page PDF, pages="0-1", table_format="html": 200, blocks == [], tbl-0.html on page 0; extract_header=True: 400 with loc ["body","extract_header"]; a cut page: 422 unreadable_page.

  • Boxes it reaches: the HIP native server serving GLM-OCR with --vision.

  • New switch? No.

  • Environment: receipts on base 9c9bf542c, checks on main 61fe90343; Zig 0.17.0; ROCm 10.1 (hipcc HIP 7.16); one Radeon AI PRO R9700 (gfx1201); Linux; dots.mocr dots-studio/dots.mocr e539fbb52280393adc081b289ec597430a0f9031, GLM-OCR zai-org/GLM-OCR 2e85a62840ccac27daa451df36c736c4636b8628; PDFium chromium/7725; libjpeg-turbo 3.1.4.1. The end-to-end client receipts ran on the whole stack's code (c517f4379, byte-equal to step 6's OCR files), which serves this step's requests through this step's code.

  • Paths and platforms the change reaches, which I ran and which I could not: HIP gfx1201 end to end; CUDA, Metal and Windows not run.

  • Exactness: n/a; no generation path changes.

  • Main against this branch: n/a; GLM-OCR's chat path is unchanged (ask 3 table).

  • Decode speed before and after: n/a.

  • Prompt speed before and after: n/a.

  • Licence of any new weights or drafter, or "n/a": n/a

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney. We read step 3 early too. GLM-OCR's reader is small, and the Markdown normalization is bounded: code stays verbatim, a table the subset can't read stays raw, and the scan can't go quadratic on backticks. The prompt-id test and your gfx1201 pair show /v1/ocr and chat run the same tokens. The only difference is the documented table and math normalization afterwards, which is fine. No asks. It follows #2571: please rebase it once #2571 is on main.

  • Synthena (Ash's Agent)

@laudney

laudney commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart rebased onto main 61fe90343 (with #2571), as you asked, and marked ready. New head: ce19d41b8.

Before (2162c6e25) After (ce19d41b8)
Base 9c9bf542c, under the old #2571 main 61fe90343
Commits 3 for step 3, then 7 review commits 3, with the original messages
Change each file's change equals the old one; CHANGELOG.md is no longer touched, as with #2571's landing
Merge with main conflicted clean
Check on ce19d41b8 Result
zig build test-ocr-host test-api-boundaries test-server-cpu test-dots-mocr-host test-glm-ocr-host check-native-hip-host -Dhip=true 24/24 steps, 1779 of 1798 pass, 19 skip, 0 fail
The first commit alone (test-server-cpu test-glm-ocr-host check-native-hip-host) 15/15 steps, 1649 of 1663 pass, 14 skip, 0 fail
Lean checker 168 on main, 168 on this head, the same list

#2573 follows when this lands.

@AIFlowML

Copy link
Copy Markdown
Contributor

@laudney @ashhart The documented host command was reproducible from a clean export of ce19d41b8. On Apple M5 Max with Zig 0.17.0 I ran:

zig build test-ocr-host test-api-boundaries test-server-cpu test-dots-mocr-host \
  test-glm-ocr-host check-native-hip-host -Dhip=true -Dcpu=apple_m1 -j7 --summary all

All six targets passed, with 24/24 build steps, 1,772 tests passed and 21 skipped. That confirms the host route and Markdown fixture checks on a second platform. The real GLM-OCR, PDF and gfx1201 results remain the device receipt in the PR. The head test-merged cleanly with main 1ece6e6db.

Igor Lessio - AIFLOW LABS

laudney and others added 4 commits November 21, 2026 15:39
GLM-OCR reads a page as Markdown without boxes, so a reader now
states its geometry, a block's quad is optional, and GLM-OCR offers
an Ocr reader with the model card's text recognition prompt and no
geometry: the page becomes one block whose Markdown is the model's
reply, with HTML tables rewritten as pipe tables or clean spanned
HTML and \( \) and \[ \] math as $ and $$, cells included, while
fenced and inline code stays verbatim in a linear scan. A reader
without boxes refuses header and footer extraction, the page pixel
limit grows to GLM-OCR's, and greedy Hugging Face oracle outputs pin
the prompt and the parser in the fixture tests.
Issue 2440 asks that GLM-OCR's Markdown equal what the chat route
returns for the same image and prompt. The prompt-id test gains
GLM-OCR's prompt, so both routes give the model the same ids, and a
scripted reply sent through POST /v1/ocr with a reader of GLM-OCR's
contract and through /v1/chat/completions gives page Markdown equal
to the chat content; the reader test shows the reply kept verbatim
but for HTML tables and LaTeX delimiters.
The API guide named one reader. It now lists GLM-OCR with its
single page block, the header and footer refusal for a reader
without boxes, and the context a dense page needs under GLM-OCR's
default window; the changelog line stays with the maintainer.
@ashhart
ashhart merged commit acf5a6c into ashhart:main Nov 21, 2026
3 of 12 checks passed
@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thank you @laudney. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

ashhart added a commit to devopsfortunato/TensorFold that referenced this pull request Nov 21, 2026
ashhart added a commit that referenced this pull request Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants