Skip to content

Upstream PR: H3 prompt and decoder weights read ahead - #4909

Merged
ashhart merged 10 commits into
ashhart:mainfrom
plotarmordev:feat/106-upstream-pr-h3-prompt-and-decoder-weight
Nov 25, 2026
Merged

ashhart merged 10 commits into
ashhart:mainfrom
plotarmordev:feat/106-upstream-pr-h3-prompt-and-decoder-weight

Conversation

@plotarmordev

@plotarmordev plotarmordev commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor
  • h3: read the prompt and decoder weights ahead of their mappings
  • h3: keep the read-ahead doc comments on one line within 120 columns
  • h3: test that the decoder's load reads ahead only the tensors it converts to bf16
  • h3: test that the prompt path's load reads ahead only the tensors it accepts
  • h3: read ahead only the refiner tensors the front end takes

No visible change: nothing this PR changes shows on screen.

How to check

  • Base commit (main): e3c6f79bacef0a50bdc8ca9a9c1e9abf300f7a27
  • Head commit: 2b60fd231ed25c40531af0ea4761d284f20fdee0
  • Machine: an Apple Silicon Mac (M-series) · macOS 27.0 · Zig 0.17.0

Test results:

  • zig build test-h3-read-ahead test-h3-image-prompt --summary all at 6eeff192a5d5 (older head): 2 passed, 0 failed, 0 skipped
  • zig build test test-golden at ed4c881de456 (older head): 5763 passed, 2 failed, 82 skipped
  • zig build test-golden test-h3-read-ahead test-h3-image-prompt compile-h3-image-prompt compile-h3-image-decoder-host compile-h3-host --summary all at 6eeff192a5d5 (older head): 2 passed, 0 failed, 0 skipped
  • zig build test test-golden --summary all at 6eeff192a5d5 (older head): 550 passed, 1 failed, 15 skipped
  • nice -n 10 zig build test test-golden --summary all at e66ef310c9d2 (older head): 16362 passed, 2 failed, 131 skipped
  • nice -n 10 zig build test-h3-read-ahead compile-h3-host dev-tools --summary all at e66ef310c9d2 (older head): 2 passed, 0 failed, 0 skipped
  • nice -n 10 zig build test test-golden --summary line at 3942d6865ce9 (older head): 17430 passed, 4 failed, 130 skipped
  • zig build test-h3-image-decoder-load test-h3-read-ahead --summary all at a58ebbc1080b (older head): 4 passed, 0 failed, 0 skipped
  • python3 tools/zig/lean_new.py lean-base.txt lean-head.txt at eb34328af8b1 (older head): 1 passed, 0 failed, 0 skipped
  • zig build test-h3-image-decoder-load at ed4c881de456 (older head): 1 passed, 0 failed, 0 skipped
  • zig build test-h3-read-ahead at ed4c881de456 (older head): 1 passed, 0 failed, 0 skipped
  • zig build test-h3-image-prompt-weights at ed4c881de456 (older head): 4 passed, 0 failed, 0 skipped
  • zig build test-h3-image-prompt compile-h3-image-prompt at eb34328af8b1 (older head): 12 passed, 0 failed, 0 skipped
  • zig build test-h3-read-ahead --summary all at ed4c881de456 (older head): 2 passed, 0 failed, 0 skipped
  • zig build test-h3-image-prompt-weights --summary all at ed4c881de456 (older head): 4 passed, 0 failed, 0 skipped
  • zig build test-h3-image-decoder-load --summary all at ed4c881de456 (older head): 2 passed, 0 failed, 0 skipped
  • nice -n 10 zig build test-h3-read-ahead test-h3-image-decoder-load test-h3-image-prompt-weights test-h3-image-prompt compile-h3-image-prompt compile-h3-image-decoder-host compile-h3-host --summary all at 2b60fd231ed2: 8 passed, 0 failed, 0 skipped
  • python3 tools/zig/lean_new.py ../lean-base.txt ../lean-head.txt at 2b60fd231ed2: 1 passed, 0 failed, 0 skipped
  • zig fmt --check build.zig zig at 2b60fd231ed2: 1 passed, 0 failed, 0 skipped

@plotarmordev

Copy link
Copy Markdown
Contributor Author

I merged main (3942d68) to clear the conflict, no rebase. Main's own span read-ahead (read_ahead.zig, Checkpoint.readAhead) is kept as is; the decoder's load now builds its spans from host.weights' items and start, then host.read, so main's split stays whole. I also narrowed the refiner's filter to the eight tensors a block takes (2b60fd2), with a fixture tensor that proves it. test-h3-read-ahead, test-h3-image-decoder-load, test-h3-image-prompt-weights and the lean gate (0 new) pass; zig build test test-golden fails the same 4 tests here as on main 3942d68 (net DNS, managed log, info pricing, qwen27 mtp_pick's missing bf16_topk module).

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks @plotarmordev. The prompt path keeps its mapped BF16 bytes, and the decoder keeps the existing conversion after reading only its selected tensor ranges. The narrowed refiner filter and the enabled/disabled read-ahead fixtures cover the intended boundaries. Your focused current-head results are useful, and the branch merges cleanly.

This is ready to land through the normal final-tree checks. The existing transformer timing table does not establish a speed benefit for the newly covered prompt and decoder paths, so the change notes should not claim a speedup there.

  • Synthena

@plotarmordev

Copy link
Copy Markdown
Contributor Author

Thanks. Agreed on the notes: the change itself claims no prompt or decoder speedup — the timing table is the transformer's and already reports no net cold-start win there, and the notes only say the same reader now serves the prompt path's accepted tensors and the decoder's converted ones. Re-ran the focused checks at this head: test-h3-read-ahead, test-h3-image-decoder-load and test-h3-image-prompt-weights pass (4/4), and the lean gate shows 0 new problems.

@AIFlowML

Copy link
Copy Markdown
Contributor

I ran the broader focused set on a clean trial merge of 2b60fd231ed25c40531af0ea4761d284f20fdee0 onto main 4c79cfe346d3c239ff7dfd7aa694df799755bafa (Apple silicon, Zig 0.17.0):

zig build test-h3-read-ahead test-h3-image-prompt test-h3-image-prompt-weights \
  test-h3-image-decoder-load compile-h3-image-prompt compile-h3-image-decoder-host \
  -Dcpu=apple_m1 --summary all

All 21 tests passed: 2 read-ahead, 13 prompt, 4 prompt-weight and 2 decoder-load cases. Both compile targets also passed. This is host and compile coverage for the present head. I did not repeat the checkpoint load or measure cold-start speed.

Igor Lessio - AIFLOW LABS

ashhart and others added 10 commits November 25, 2026 10:02
`tf-h3-image-prompt` and `tf-h3-image-decoder` now read the tensor bytes they use
into the page cache through the same 16 x 8 MiB reader the transformer's shards
use, instead of faulting them in one page at a time. `read_ahead.read` takes byte
ranges, so the prompt path reads only its accepted tensors and the decoder only
the tensors it converts; the transformer still passes whole shards.

(cherry picked from commit 8addc4f)
(cherry picked from commit 6eeff19)
The lean checker counts a comment past 120 columns and a comment over two lines alike, so the two doc comments the read-ahead change lengthened are shortened in place. Comments only.

(cherry picked from commit e66ef31)
FrontNames accepted every token_refiner.* tensor, so open also read ahead
blocks above g.blocks and their shards. Restrict it to condition_proj's
weight and bias, the final norm and the first g.blocks blocks, and cover
it with a fixture that parks an extra block's tensors in an opened shard
and a second shard.
FrontNames accepted any tensor under a refiner block below g.blocks, so a
block tensor loadRefiner never takes was still read ahead. It now accepts
a block tensor only by blockTensors' names; the fixture gains one such
tensor, which the read-ahead count leaves out.
@ashhart
ashhart force-pushed the feat/106-upstream-pr-h3-prompt-and-decoder-weight branch from 7362058 to ee3d526 Compare November 25, 2026 10:02
@ashhart
ashhart merged commit f44deb9 into ashhart:main Nov 25, 2026
1 check failed
ashhart added a commit that referenced this pull request Nov 25, 2026
@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you @plotarmordev. 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.

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