Skip to content

dots: oracle image references and FP64 projection checks - #2772

Closed
laudney wants to merge 19 commits into
ashhart:mainfrom
laudney:pr-dots-f
Closed

laudney wants to merge 19 commits into
ashhart:mainfrom
laudney:pr-dots-f

Conversation

@laudney

@laudney laudney commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor
Before (#2673) After
The oracle's image references on a GB10 need flash-attn (no aarch64 wheel) the tower runs on SDPA, and the backend Torch picks is recorded
The oracle's image modes in dots_mocr_reference.py (600 lines) in dots_mocr_images.py, loaded by path; every command and output unchanged, also under python3 -I
Native tower taps against HF no tool stages: max abs and a BF16-ulp histogram for each stage
Projections against FP64 (dots-projections, 24 classes, tower and decoder, our receipt page) — 24 of 24 pass: each no worse than Torch's BF16 matmul on the same inputs
Served passes — unchanged: the new projection tap is null when served

What this changes

This adds the oracle and check tools that the image receipts use, and an optional tap on the dense pass for the projection check.

  • Oracle (tools/zig/dots_mocr_reference.py, tools/zig/dots_mocr_images.py): on the GB10, oracle, score and text install a stand-in for the tower's flash-attn import, put the tower on SDPA and refuse a block that is not VisionSdpaAttention. oracle and score record the SDPA backend Torch picks. score teacher-forces image prompts with the reference's pixel_values and image_grid_thw. oracle saves BF16 tower taps (with the patch embed before its norm), the tower rotary inv_freq fixture text and cos/sin, and decides whether the patch bias rounds once or twice. stages compares native taps by max abs and BF16-ulp histogram. Image references pin Pillow 12.2.0 and qwen-vl-utils 0.0.10, because Pillow 13 resizes the demo page to other pixels.

  • The image modes live in dots_mocr_images.py, which the reference script loads by its path. Both files stay under 600 lines, and python3 -I runs the script from any directory. Every command's --help and the stages output are byte-identical to the single-file script, plain and under -I.

  • Projection check (zig/tests/cuda/dots_projections.zig, tools/zig/dots_projection_check.py): pass.zig gains an optional tap on each projection's input and output rows, and the dots recipe and tower call it; served passes leave it null. tf-cuda-test dots-projections encodes one image and prefills the image prompt's first chunk with the taps set. The Python check computes FP64 products and Torch's layers as Transformers calls them, and fails a class past one BF16 step plus the FP32 sum's error, worse than Torch's worst column, with a fused part off its own GEMM, or missing.

  • Model licence: n/a in this piece; the tools read the publisher's checkpoint as piece e states.

  • 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: serve dots.mocr's images on CUDA with --vision #2771 (piece 5, 731f8a72e). This PR's commits: c58fe7671 feat(tools): dots oracle on CUDA with an SDPA tower and stages; bcbfd05e2 test(cuda): FP64 projection checks for dots.mocr on GB10; 1e685c118 fix(tools): the tower follows --attention, and an SDPA backend flag; 6ae6e07fd style(cuda): move a long trailing comment in dots_projections; 5e04a9beb docs(tools): the oracle's help names its tower's attention choice. Piece 6 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: 5e04a9beb
  • 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 e. 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 e).
  • 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: 24/24 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; python3 -I -m py_compile on dots_mocr_reference.py, dots_mocr_images.py, dots_projection_check.py: 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.

The oracle split, run from a directory outside the repository: --help and each mode's --help (oracle, sources, processor, text, score, compare, stages), plain and with python3 -I, are byte-identical to the single-file script; stages on synthetic taps is byte-identical in both modes; pyflakes is clean.

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; Torch 2.14.1+cu130, Transformers 4.57.6.
  • The served path: the tap is null when served; the served exactness and speed are piece e's receipt, measured on the stack's head with this piece in it.

Projections against FP64 (dots-projections, our receipt page)

receipt.png (piece e describes how it is made; grid 92×52, 1,024 prompt rows): PASS dots projections: 24 of 24 classes. The 24 classes are the tower's patch (K 592), qkv, proj, fc1|fc3 and fc2 at blocks 0, 20 and 41, and the merger's two linears; the decoder's q|k|v (FP32 sums), o, gate|up and down at layers 0 and 27, and the head. The FP64 comparison covers 256 evenly spaced rows of each call; Torch's BF16 matmul runs on every input row.

Classes Native's worst column, as a fraction of the bound (one BF16 step plus the FP32 sum's error)
equal to Torch's worst column 22 about 0.49 (the merger's mlp2: 0.425, as Torch)
better than Torch's 2 the decoder's q|k|v at layers 0 and 27, kept in FP32 for the rotary: 0.005 and 0.006, against Torch's 0.490 and 0.481

Every fused part equals its separate GEMM or stays within the bound.

Planted control: the same output with one value of tower-qkv-0.y raised by two BF16 steps (0xbe37 to 0xbe39) gives FAIL native past the bound tower qkv layer 0 ... 2.310 of the bound and FAIL dots projections: 23 of 24 classes; failed: tower-qkv-0, exit status 1.

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.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • No precision traded for speed. If the bits change, the description says which sums change and why: the served bits do not change.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney, the SDPA tower and the FP64 check are clear, and the split keeps every command intact. A few small things:

  1. oracle now puts the tower on SDPA on every GPU, HIP included (before, it followed --attention), and it now requires Pillow 12.2.0. HIP image references made from this head will differ in the tower from the ones behind the HIP numbers. Could you keep --attention deciding the tower when flash-attn is installed, or say so in fixtures/README.md, whose HIP oracle command is unchanged?
  2. zig/tests/cuda/dots_projections.zig:69 is 122 columns with its trailing comment; please move the comment above the line.
  3. Could you post one planted-control run of dots_projection_check.py, for example one .y value nudged by two BF16 steps, showing the class fails?
  4. The FP64 comparison covers 256 evenly spaced rows of each call (Torch sees every input row); worth saying so in the description.
  • Synthena (Ash's Agent)

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

laudney commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, all four:

  1. 1e685c118: the tower follows --attention again when flash-attn is installed, and falls back to SDPA only without it. Only an SDPA tower refuses blocks that are not VisionSdpaAttention, so HIP references made with flash are as before. oracle and score also gain --sdpa-backend auto|math (default auto, unchanged), recorded in their output. 5e04a9beb updates the help.
  2. 6ae6e07fd: the comment at dots_projections.zig:69 sits above its line.
  3. Planted control on the GB10: in a copy of the receipt page's output, I raised one value of tower-qkv-0.y by two BF16 steps (0xbe37 to 0xbe39). The check gives FAIL native past the bound tower qkv layer 0 ... 2.310 of the bound and FAIL dots projections: 23 of 24 classes; failed: tower-qkv-0, exit status 1. The unmodified output passes 24 of 24.
  4. The description now says that the FP64 comparison covers 256 evenly spaced rows of each call, and that Torch's matmul runs on every input row.

@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney, all four are in. HIP references made with flash-attn now get the same tower as on main, and the new flag defaults to the old behaviour. Thanks for the planted-control run too. 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 rebase preserves the requested attention implementation, SDPA fallback and recorded backend choice. Served projection taps remain null by default. The independent projection check still requires all 24 classes, reports its 256-row sampling scope and worst-column errors, and returns failure for a bad comparison; your two-BF16-step control is retained as evidence. No new author changes requested; ready after #2771 once current-head CI is green.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @laudney. The attention choice, SDPA fallback and recorded backend are as reviewed, with the planted control retained. Nothing further is needed from you here.

We will rebase on current main and get CI green, then land this in order after #2771.

  • 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
ashhart force-pushed the pr-dots-f branch 2 times, most recently from 272c60a to bf44380 Compare November 19, 2026 19:34
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.
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
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.
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
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.
laudney and others added 15 commits November 20, 2026 08:47
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.
The recipe now declares the tower, so the dense engine's tower
variant serves dots.mocr: --vision opens it, the host reads its
limits, marks and words, and its weight and open bytes join the
vision bytes. The tower counts its encodes, and the dots module
exports its config for the GB10 runner, whose new dots-invariants
serves the engine with --vision and runs a small image, the full
image (the oracle's prompt ids when given) and two images, each
under cuts that the run proves landed off the 1,024-row grid,
against the uncut run: the KV rows, the last-row logits, the greedy
ids and one encode an image must all be equal. Host tests pin the
recipe's tower, the vision decls and bytes, and the engine's words.
--
2.43.0
ashhart#2732's runner gains dots-text, so a decoder drift fails without the
Python oracle: three chat-templated prompts of our own (18, 578 and
2,537 ids, committed as fixtures/own-prompts.json) each generate up
to 64 greedy reply ids through the served dense engine (EOS can end
one sooner), and the sha256 of those ids as little-endian u32 must
equal its pinned constant. The constants wait for the GB10 run, so
the command prints each measured hash and fails until they are
filled in. A host test pins the fixture's prompt lengths, its
vocabulary range and its turn marks.
--
2.43.0
The description claims the text path with and without --vision, but
dots-text served the engine only with --vision. It now serves the
three own prompts twice, with --vision and without it, against the
same pins, and like dots-image it names another SM instead of
comparing GB10 pins there.
--
2.43.0
The fixture's ids could not be regenerated from the tree. The
fixtures README now names their source text, our own ownprompts.py,
and how each prompt became ids: one user turn rendered with the
checkpoint's chat template and tokenized by the pinned oracle.
--
2.43.0
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
The GB10 has no flash-attn, so oracle, score and text install a
stand-in for the tower's import, put the tower on SDPA and refuse
a block that is not VisionSdpaAttention; oracle and score record
the SDPA backend Torch picks, score teacher-forces image prompts
with the reference's pixel_values and image_grid_thw, oracle saves
BF16 tower taps (with the patch embed before its norm), the tower
rotary inv_freq fixture text and cos/sin, and decides once or
twice rounding of the patch bias, and a stages mode compares
native taps by max abs and BF16-ulp histogram; image references
now require pillow 12.2.0 and qwen-vl-utils 0.0.10, because
Pillow 13.0.0 changes the demo pixels from the fixture's hash. The
image modes (oracle, stages and score's pixels) move to
dots_mocr_images.py, which the reference script loads by its path,
so python -I runs it from any directory, and each file keeps room
under the 600-line limit.
Gate 2 asks each changed reduction order to be no worse than Torch's
BF16 matmul against FP64 on the same device inputs, so the dense
pass and the dots tower gain an optional tap on each projection's
input and output rows. Served passes leave the tap null. The new
dots-projections runner command encodes one image and prefills the
image prompt's first chunk with the taps set. It writes every input
row, sampled output rows and each fused class's separate GEMMs for
the tower's patch, blocks 0, 20 and 41 and merger, and for the
decoder's first and last layers and head. tools/zig/
dots_projection_check.py computes FP64 products and Torch's layers
as Transformers calls them, and fails a class past one BF16 step
plus the FP32 sum's error, worse than Torch's worst column, or with
a fused part off its own GEMM; a missing class also fails.
The oracle put the tower on SDPA on every GPU, so HIP image
references made with flash-attn would differ in the tower from the
ones behind the HIP numbers. The tower now follows --attention when
flash-attn is installed and falls back to SDPA only without it, and
only an SDPA tower refuses blocks that are not VisionSdpaAttention.
oracle and score gain --sdpa-backend auto|math: math turns flash,
memory-efficient and cuDNN SDPA off, as the math-backend reference
needs, and both record the choice in their output.
A trailing comment ran past 120 columns; it now sits above its line.
The oracle's help and the image module's docstring still promised an
SDPA tower, though the tower now follows --attention when flash-attn
is installed; both now say so, with SDPA as the fallback.
@AIFlowML

Copy link
Copy Markdown
Contributor

@laudney @ashhart I independently checked the rebased 408a4534d head. On Linux x86-64 with Zig 0.17.0, zig build test-cuda-dense-host test-dots-mocr-cuda-host check-native-cuda-host -Dfixed-cpu -j6 --summary all passed all 18 steps and 61 tests. The head test-merged cleanly into 1ece6e6db.

The first detail I'd add to the description is the rebased head beside this smaller host command. I also ran python3 -I /path/to/tools/zig/dots_mocr_reference.py oracle --help from outside the checkout. It matched normal invocation byte for byte and listed both --attention choices. The checkpoint and FP64 GPU comparisons remain the device receipt.

Igor Lessio - AIFLOW LABS

@AIFlowML

Copy link
Copy Markdown
Contributor

All eight paths changed by 408a4534d are now byte-identical on main 25586070b. The SDPA oracle and recorded backend changes are reachable through 103e5a070 and 8642b2650, and the FP64 projection check is reachable through b37612280. Thanks, @laudney. The reference and test work is already upstream, so this PR can close as covered.

I reran the main tree on M5 Max with Zig 0.17.0. All 61 host tests passed and the Linux ARM64 CUDA native target compiled:

zig build test-cuda-dense-host test-dots-mocr-cuda-host check-native-cuda-host -Dcpu=apple_m1 -j3 --summary all

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney. All eight files in this PR now match main exactly: the SDPA tower, the oracle's image references and the FP64 projection checks are on main in your own commits (103e5a0, 8642b26, 04d3510). Nothing is left to merge, so we're closing this one.

  • Synthena

@ashhart ashhart closed this Nov 22, 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