Skip to content

dots: the image tower on CUDA, with its GB10 runner checks - #2770

Merged
ashhart merged 11 commits into
ashhart:mainfrom
laudney:pr-dots-d
Nov 19, 2026
Merged

ashhart merged 11 commits into
ashhart:mainfrom
laudney:pr-dots-d

Conversation

@laudney

@laudney laudney commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor
Before After
dots.mocr's image tower on CUDA — 42 blocks and the 2×2 merger, at the HIP port's and Transformers' rounding points
Encode the same image twice (tf-cuda-test dots-image, GB10) — equal bytes
A generated 812×588 page's vision-merged sha256 — ac8c66b7…, pinned in the runner: a tower drift fails without the Python oracle
The tower against HF, stage by stage (dots-stages, our two pages) — the patch stages equal HF's in every value; past them, native is as close to HF as HF's own two SDPA backends are to each other (closer at block 0)
Served behavior text only unchanged: the recipe declares the tower in piece e

What this changes

This adds dots.mocr's image tower on CUDA and two GB10 runner commands for it. The recipe does not declare the tower yet, so --vision stays refused until piece e.

  • Tower (zig/src/families/dots_mocr/cuda_tower.zig): merge-ordered patches to the decoder's rows. It uses cuda/vit.zig's cuBLASLt projections, attention, LayerNorm and linears, the engine's norms and SwiGLU, and the vision rotary and patch bias launches from piece a. The patch weight is padded from K 588 to 592, and fc1|fc3 run as one projection. One call's scratch is held at the processor's 57,600 patches (39,592 bytes a patch), and every stage can be tapped for the oracle.

  • The tower's arithmetic is our own code, written to the reference's rounding points.

  • Runner (zig/tests/cuda/dots_tests.zig, one dispatch line and one dots-help usage line in main.zig):

    • dots-stages MODEL IMAGE OUT: one encode, each stage's rows written as BF16 .npy files for the oracle's stages mode (piece f).
    • dots-image MODEL [IMAGE]: a generated page (the processor fixture's pixel pattern, no file read) and an optional image, each encoded twice and compared byte for byte, then the page's vision-merged sha256 against its pin.
    • dots-help: the dots commands' usage.
  • Model licence: dots-studio/dots.mocr is published under the dots.mocr License Agreement (Xingyin Information Technology (Shanghai) Co., Ltd., on MIT terms; the model card reads license: mit). TensorFold redistributes no weights; the runner reads the publisher's files.

  • Issue: Refs Native OCR models on HIP: dots.mocr, GLM-OCR, LightOnOCR-3 and Nemotron Parse, CUDA to follow (tracker) #1927 (item 11). Remaining after this stack: Nemotron Parse and GLM-OCR on this engine.

  • Stacked on: dots: the image tower's weights on CUDA #2769 (piece 3, f4550b060). This PR's commits: b5e7f269e feat(dots): dots.mocr's image tower on CUDA; ff5fba4d9 test(cuda): a GB10 runner for dots.mocr's tower; 630f23519 test(dots): pin the tower's GEMM plan trim at max_plans; 1e1a2f0e6 test(cuda): dots-image names another SM instead of its pin; a4df65c45 style(dots): move long trailing comments and share the test dir; da27cc0fe docs(dots): describe vision_inv_freq.txt with the tower. Piece 4 of 7.

  • Conflicts: a local test merge of the stack's top cd1cb0baa into main 6b739dd5e is clean (git merge-tree).

Checks on this head

  • Head commit: da27cc0fe
  • Review fixes (Ash's 21:08 points) are new commits on this piece, listed above. On this head (Linux x86_64): zig build test-cuda-host, check-native-cuda-host 7/7, test-kernel-contract, zig fmt --check and git diff --check pass; lean 386 / 386, 0 new against piece c. On the GB10 at the stack's head cd1cb0baa: dots-image and dots-text (with --vision and text only) equal their pins; the projection check passes 24 of 24 and fails a planted value two BF16 steps off. The checks below ran on the earlier heads, whose code equals this head's but for these fixes.
  • Lean checker, python3 tools/zig/lean_check.py, on the base (cuda: a shared engine for dense decoders, with dots.mocr's text decoder on it #2673's head 05e5e5fdd) and on this head: 386 / 386, 0 new (also 0 new against piece c).
  • Tests run (Linux x86_64, no GPU):
    • zig build test-cuda-host: 378/378 steps, 0 failed (the test binaries this piece changes re-ran; the others are the parent's and passed there).
    • zig build test-cuda-dense-host: 33/33 passed, uncached. zig build test-dots-mocr-cuda-host: 23/23 passed, uncached.
    • zig build check-native-cuda-host: 7/7 steps. zig build test-kernel-contract: 32/32 steps, 0 failed. zig build compile-cuda-tests (the GB10 runner compiles): 10/10 steps.
    • zig fmt --check build.zig zig, git diff --check: pass.
  • CI: pending on this head.
  • zig build test test-golden (Linux x86_64) on the stack's top 6bb38b3a1: 662/665 steps, 8,692/8,760 tests passed, 67 skipped; the one failure is cuda_disk_test, whose write deadline fails on the base too under load.
  • Not run, and why: the GB10 device checks are in the receipt, not in this host list.

New host tests (in test-dots-mocr-cuda-host): the tower against the engine's contract, its marks and the template's own wrapping; the largest image (14,400 tokens); the scratch layout; the exact device bytes (weights 2,524,194,816, scratch and workspace 2,314,053,888) against a sparse checkpoint, with a missing tensor refused; the rotary inv_freq fixture against the float32 table bit for bit, with a one-ulp control; the refusals' words (the image budget names --vision-image-tokens); the grid checks; the patch rows' rounding and padding; zero limits refused before the config is read.

Receipt

  • Environment: the stack's head on cuda: a shared engine for dense decoders, with dots.mocr's text decoder on it #2673 05e5e5fdd, whose tree equals these heads except one moved comment; NVIDIA GB10 (sm_121), nvcc 13.4, Zig 0.17.0, 128 GB unified memory. Checkpoint dots-studio/dots.mocr@e539fbb52280393adc081b289ec597430a0f9031. HF: the pinned oracle (piece f) on the same GB10, Torch 2.14.1+cu130, Transformers 4.57.6, Pillow 12.2.0, qwen-vl-utils 0.0.10, the tower on SDPA.
  • tf-cuda-test dots-image MODEL: PASS. The generated 812×588 page encodes twice to equal bytes, and its vision-merged sha256 equals the pin ac8c66b76552c15c22af3bc776d285350c4d9596863de2a3359c9a909b971067. On another SM it still checks the two encodes and prints a SKIP line naming the device's SM instead of comparing the GB10 pin.
  • dots-stages against HF's oracle --vision-only taps (HF's tower on the efficient SDPA backend), compared by stages on our own two pages (piece e describes how they are made). The fraction of BF16 values equal to HF's, by stage:
Stage receipt.png (92×52, 4,784 patches) invoice.png (126×88, 11,088 patches) HF math backend (oracle --sdpa-backend math, piece f) against HF efficient backend, receipt.png
vision-patch-bias 1.0000 1.0000 —
vision-patch 1.0000 1.0000 —
vision-block0 0.9085 0.9134 0.8696
vision-block10 0.3643 0.3780 0.3486
vision-block41 0.1084 0.1025 0.1097
vision-merged 0.1077 0.1010 0.1096

The patch stages equal HF's in every value, so the twice-rounded patch bias matches. Past them, the native tower is as close to HF as HF's own two SDPA backends are to each other, and closer at block 0.

  • Served exactness with images (HF agreement, invariants, chunk cuts) needs the recipe's tower declaration: piece e's receipt.
  • Paths and platforms: the GB10 (sm_121) only. Not run: sm_80, sm_86, sm_89 and sm_120 devices.

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 10, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney. The tower follows the HIP port's rounding points step by step, and the image bound is enforced where it matters: whole merge blocks, at most 57,600 patches, the token count tied to the grid, and the scratch sized once for the largest image. A few small asks:

  • Could the max_plans trim get a host test that fails without it?

  • The vision-merged and reply pins are GB10 values. Could dots-image and dots-text skip, or name the device in the failure, on another SM, so a different GPU doesn't read as a drift?

  • The description compares native with HF's math backend against HF's efficient backend. How is the math-backend reference produced? We couldn't find a backend switch in the oracle.

  • Two trailing comments run past 120 columns (zig/build/cuda.zig:115, and the "the control" line in cuda_tower_test.zig); could they move above their lines?

  • cuda_tower.zig cites fixtures/README.md for vision_inv_freq.txt, but that entry arrives in the docs piece. Moving the README line here would keep the reference true at this head.

  • Synthena (Ash's Agent)

@laudney
laudney force-pushed the pr-dots-d branch 2 times, most recently from b305e3f to da27cc0 Compare November 11, 2026 08:14
@laudney

laudney commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, all five:

  • 630f23519: a host test (fake driver and fake cuBLASLt destroys) fails without the max_plans trim.
  • 1e1a2f0e6: on an SM other than sm_121, dots-image still checks that two encodes are equal, then prints SKIP dots-image's pins: they are GB10 (sm_121) values; this device is sm_N instead of comparing the pin. dots-text does the same (dots: serve dots.mocr's images on CUDA with --vision #2771).
  • The math-backend reference came from a local wrapper that turned off Torch's flash, memory-efficient and cuDNN SDPA around oracle --vision-only. dots: oracle image references and FP64 projection checks #2772 now has the switch, oracle --sdpa-backend math (1e685c118). Rerun on the GB10, it records "sdpa_backend": "math", and all 42 tower attention calls ran on MATH.
  • a4df65c45: both trailing comments sit above their lines.
  • da27cc0fe: the vision_inv_freq.txt entry in fixtures/README.md lands here now, so cuda_tower.zig's citation holds at this head.

@laudney laudney mentioned this pull request Nov 11, 2026
4 tasks done
@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney, all five are in. One note, no change needed: the max_plans test calls trim directly, so it wouldn't notice if encode stopped calling it. That's fine, since encode needs a device. The red desktop check is in a job this stack doesn't touch, and a rerun should clear it. Ready from our side.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

@laudney main landed dots changes of its own under this stack (fix(dots): read with our own prompt and hash-only fixtures and the dots licence docs), so the series conflicted in zig/src/families/dots_mocr/fixtures/README.md and tools/zig/dots_mocr_reference.py and the landing train left it out. To save you a round trip we rebased the whole stack (#2770 → #2771 → #2772 → #2773) onto current main and pushed each PR to its branch: main's own prompt file, hash-only fixtures and licence names are kept, and your CUDA image tower, serving and checks are unchanged. The dots host steps pass on each PR of the stack, as do the serving-pin check and our privacy gate. They go back in the landing queue in order once CI is green. No other asks.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney. The rebased tower retains the upload-drain ordering, the plan trim called from encode, the scratch and weight budget, and the GB10-only hash anchor with an explicit skip on other SMs. Main's fixture provenance and licence wording are retained. No new author changes requested; ready in order after the weight-loader parent, with current-head CI green.

  • Synthena (Ash's Agent)

@laudney

laudney commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Rebased #2770–#2773 onto #2769's current head (b3435d0b67), so they no longer carry the pre-merge copies of #2767–#2769's commits. Each PR's own patch is byte-identical to the head you rebased on 11-13; only the CHANGELOG hunk offset in #2773 moved. The 1.2.8 → Unreleased move for #2773's note is left to you, as you said.

PR Before After Own commits
#2770 05bdde7bc b2cb3b044 6
#2771 f7ed0ebe3 7b680c529 4
#2772 a45ea67e1 38eeb5e5f 5
#2773 51c146342 200cef933 2

On the new #2773 head: lean 341 problems, 341 on the base, 0 new; zig fmt --check and git diff --check clean; test-cuda-host 6586/6617 passed (31 skipped), check-native-cuda-host 7/7 steps, test-kernel-contract 242/242 passed. It merges into current main without conflicts.

@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney for the restack and for addressing all five earlier asks. We will keep the loader-first order, bring the CUDA command file back within 600 lines, and verify CI at the resolved head. The changelog remains with #2773 as agreed. No further changes are requested from you here.

  • Synthena

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney. To get this moving, we rebased it onto current main ourselves, keeping every one of your commits as it was (author and message) and fitting it to the code main has gained since; no behaviour changes. It is in the landing queue now, and if anything else is needed from you we will say so here.

  • Synthena

ashhart added a commit to laudney/TensorFold that referenced this pull request Nov 19, 2026
ashhart added a commit to laudney/TensorFold that referenced this pull request Nov 19, 2026
ashhart added a commit to laudney/TensorFold that referenced this pull request Nov 19, 2026
ashhart added a commit to laudney/TensorFold that referenced this pull request Nov 19, 2026
ashhart added a commit to laudney/TensorFold that referenced this pull request Nov 19, 2026
ashhart added a commit to laudney/TensorFold that referenced this pull request Nov 19, 2026
laudney and others added 11 commits November 19, 2026 16:55
The tower's tensors load as plain BF16 [n, k] matrices for cuBLASLt:
fc1 and fc3 stacked into one gate|up projection, and the patch weight
flattened to 588 columns and zero-padded to 592 so its rows meet the
library's alignment. Every vision_tower tensor is consumed, the device
bytes count the padding, and a failed load drains its uploads before
any buffer is freed.
The drain test called settle directly, so dropping the errdefer in
load, or registering it before the tower's own errdefer, would stay
green. A host test now runs load on a sparse checkpoint against a
fake device whose first upload's wait fails: the buffers must go only
after the context proved the copies done. The sparse checkpoint
helper moves to its own test file so the tower's tests can share it.
The dense engine's Tower contract gets its first real tower:
dots.mocr's 42-block image tower, which turns merge-ordered patches
into the decoder's rows at the rounding points of the HIP port and
of Transformers. The tower reuses the shared vit GEMMs, attention,
LayerNorm and linears, the engine's norms and SwiGLU, and the new
vision rotary and patch bias launches. It holds one call's scratch
at the processor's 57,600 patches and taps every stage for the
oracle's comparison. Host tests pin the contract, the exact weight,
scratch and open bytes against a sparse checkpoint, the rotary
inv_freq fixture, the refusals' words (the budget's naming
--vision-image-tokens, the flag the CLI accepts), the grid checks
and the patch rows; the recipe declares the tower in its own change.
The tower needs device checks that the host suite cannot run, so
tf-cuda-test gains two dots commands behind one dispatch line and a
dots-help that prints their usage. dots-stages encodes one image with
a tap that writes every stage's rows as BF16 .npy files for the
oracle's stages mode. dots-image encodes a generated page (the
processor fixture's pixel pattern, no file read) and an optional
image twice each, requires equal bytes, prints the merged rows' hash
and the time, and fails unless the page's hash equals its anchor, so
a tower drift fails without the Python oracle. The runner imports
the served dots module and its engine.
Nothing failed if the tower stopped trimming its cuBLASLt plans, so
each new image size could grow the cache without bound. A host test
fills the plan map on a fake driver and cuBLASLt: below max_plans
nothing drains and nothing goes, and at max_plans the stream drains
once and every plan's handle, descriptor, layouts and preference go.
The vision-merged pin is a GB10 value, so another GPU's rows would
read as a tower drift. dots-image still encodes twice and requires
equal bytes everywhere, but on a device other than sm_121 it skips
the pin comparison and names that device's SM.
Two trailing comments ran past 120 columns (the dots runner import in
the CUDA build and a control line in the tower test); each now sits
above its line. The tower test also takes the sparse checkpoint dir
from the shared test helper instead of keeping its own copy.
cuda_tower.zig cites fixtures/README.md for vision_inv_freq.txt, but
the entry arrived with the docs piece; it now lands with the tower
that reads the fixture, so the reference holds at this head.
@ashhart
ashhart merged commit 8c3e7b8 into ashhart:main Nov 19, 2026
3 of 11 checks passed
@ashhart

ashhart commented Nov 19, 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 laudney/TensorFold that referenced this pull request Nov 19, 2026
ashhart added a commit to laudney/TensorFold that referenced this pull request Nov 19, 2026
ashhart added a commit to laudney/TensorFold that referenced this pull request Nov 19, 2026
ashhart added a commit to laudney/TensorFold that referenced this pull request Nov 19, 2026
ashhart added a commit to laudney/TensorFold that referenced this pull request Nov 20, 2026
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
ashhart added a commit to laudney/TensorFold that referenced this pull request Nov 20, 2026
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
ashhart added a commit to laudney/TensorFold that referenced this pull request Nov 20, 2026
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
ashhart added a commit to gilby/TensorFold that referenced this pull request Nov 20, 2026
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
ashhart added a commit to BadAd84/TensorFold that referenced this pull request Nov 20, 2026
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
ashhart added a commit to ElderOrb/TensorFold that referenced this pull request Nov 20, 2026
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
@laudney
laudney deleted the pr-dots-d branch November 25, 2026 15:00
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.

2 participants