Skip to content

dsv41 metal: image prompts - #3926

Merged
ashhart merged 7 commits into
ashhart:mainfrom
gilby:dsv41-metal-pr/18-images-clean
Nov 20, 2026
Merged

ashhart merged 7 commits into
ashhart:mainfrom
gilby:dsv41-metal-pr/18-images-clean

Conversation

@gilby

@gilby gilby commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Clean replacement for #1722 on current main (6db2561b18, head f3cf1a5b9 — four commits matching the reviewed #1722 commits plus the updated #3926 changelog line), as agreed in #1722 (comment). (git range-diff against #1722 shows only the two adjacent build/test import neighbor lines in zig/build/dsv41_metal.zig and zig/tests/dsv41_metal/layer_test.zig, with the image-prompt patches and notices unchanged.) Replaces #1722 for #1676 now that #1720 and #1721 have merged onto main:

  • ViT and aligner on Metal (--vision), bias_vl routing for image rows, Engram skipped on image tokens, image spans prefilled in one chunk, prompt cache keyed by image hash, and the server's image token rendered with template provenance.
  • Thin-image fix in contain() (@max(1, roundEven(...))) so 1xN / Nx1 inputs under small budgets do not divide by zero in resample.into, plus check() refusals for num_attention_heads: 0, max_wh_ratio: 0, downsample_ratio < 2, and explicit budget 1–4 error wording.
  • THIRD_PARTY_NOTICES.md attribution for DeepSeek's inference/image_processor.py (08c8657f02291e11b6f6b63e0e16014f8e748518) and the CHANGELOG.md entry under Unreleased.

Receipt

  • Environment: TensorFold clean replacement on main 6db2561b18 (native Zig 0.17.0); Apple M5 Ultra (macOS) for current head kernel contract, device suites, host tests, and goldens; full-model and release-weight receipts below carried forward unchanged from dsv41 metal: image prompts #1722 / dsv41 metal: the lane target, the prompt cache and the native server over Metal #1720 per #1722 (comment) (Apple M3 Ultra 80-core GPU 512 GB and Apple M5 Ultra 512 GB, checkpoint deepseek-ai/DeepSeek-V4.1-Flash-1017).
  • Kernel contract on current head (./zig-out/bin/tf-kernel-contract --only dsv41, Apple M5 Ultra):
    SUMMARY 107 kernels: 107 pass gates 1-4, 0 fail, 0 known findings; 205 controls: 205 red as planted, 0 missed; 0 limit problems; gates 128076 ms, limits 404 ms
  • Tests run on current head (-Dcpu=apple_m1, Apple M5 Ultra):
    • zig build test-dsv41-metal-all test-dsv41-metal-prepare test-dsv41-serve-host test-dsv41-shared test-dsv41-draft: exit 0 (test-dsv41-metal 38/38 + 28/28, test-dsv41-metal-vision 5/5, test-dsv41-metal-serve, test-dsv41-metal-prepare, test-dsv41-serve-host, test-dsv41-shared, test-dsv41-draft all pass).
    • zig build test test-golden dev-tools: exit 0 (55/55 auth goldens and 322/335 server goldens with 0 unexpected differences; 328 fixtures, 234 DeepSeek chat golden cases).
    • zig fmt --check build.zig zig & git diff --check: clean; tools/pr_check.py: 0 error(s), 0 warning(s), 0 new lean findings (191 vs 191).
  • Carried-forward unchanged receipts from dsv41 metal: image prompts #1722 / dsv41 metal: the lane target, the prompt cache and the native server over Metal #1720:
    • TF_DSV41_REAL (layers 2 and 21 vs float64, 4/4 tests each, mapped == copied bit-for-bit at 4 rows) and TF_DSV41_REAL_VISION (14/14 vs float64 on 32/32 blocks and 6x9 grid, image_start/image_end/image_newline, prompt chunk/cache checks with 0 differing logits/taps/state bytes).
    • Full-model concurrent & cold 32K prompt receipts on deepseek-ai/DeepSeek-V4.1-Flash-1017 (bench_concurrent.py --alone --serial equal token_sha256 across 1/2/3/4 streams and T=0/1; --require-cold --require-reuse 32,768 tokens).
  • Not run, and why: CUDA (no NVIDIA device here); Metal on M1, M2, and M4; release-weight steps not re-run at this head since dsv41 metal: image prompts #1722's image-prompt code is unchanged on top of dsv41 metal: the lane target, the prompt cache and the native server over Metal #1720/dsv41 metal: the vision tower's kernels under the kernel contract #1721.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • A new or changed GPU kernel is registered with the kernel contract (docs/kernel-contract.md); each backend's SUMMARY line is in the receipt.
  • Prompt processing is no slower than the last release.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • 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. No AI attribution lines.

gilby added a commit to gilby/TensorFold that referenced this pull request Nov 19, 2026
@gilby gilby mentioned this pull request Nov 19, 2026
6 of 9 tasks
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby for the clean replacement of #1722. We reviewed it as a first review here and have nothing to change in the code:

  • Without --vision and images the text path is unchanged: the chunk end, the image flags and the id checks are as before.
  • The thin-image fix and the new config refusals match the description.
  • The notice for DeepSeek's release image_processor.py is in place.
  • Today's main differs only in CHANGELOG.md, which we settle when it lands.

CI is green at this head. One check is ours before it lands: since the image path follows DeepSeek's released image_processor.py, we run our usual comparison against that source to confirm it is an adaptation rather than a copy. Nothing is needed from you unless that turns something up.

  • Synthena

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby for the clean replacement of #1722. We reviewed it as a first review here and have nothing to change in the code:

  • Without --vision and images the text path is unchanged: the chunk end, the image flags and the id checks are as before.
  • The thin-image fix and the new config refusals match the description.
  • THIRD_PARTY_NOTICES.md credits DeepSeek's release image_processor.py. That is the model's own release code, so it can land with that notice.
  • CI is green at f3cf1a5b9, and your M5 Ultra and M3 Ultra results cover the Metal paths we hold no checkpoint for.

Today's main differs only in CHANGELOG.md, which we settle as it lands. It is in the landing queue now.

  • Synthena

@joshuaswarren

Copy link
Copy Markdown
Contributor

[Joshua's agent] Reporting the comparison the 08:38Z review kept as ours before landing: we fetched DeepSeek's released image_processor.py at the revision the notice pins (08c8657f, deepseek-ai/DeepSeek-V4.1-Flash-1017) and set it against vision_prep.zig and vision_prepare.zig. It is an adaptation, not a copy. The geometry matches formula for formula: span tokens lh * (lw + 1) + 2, the aligner grid as ceil over the downsample ratio, the resize solve including both degenerate branches ((max_n - 2) // 2 * cell tall, (max_n - 3) * cell wide) and floor(height * beta / patch_size) * patch_size, the min-pixels grow and max-wh-ratio clamp, the wide-image direct resize, pad to gray 127, (v / 255 - 0.5) / 0.5 to bf16, and the reading-order span layout with one newline per row. The code around it is restructured for the engine, with pieces the Python does not have: error unions and the TooFewTokens refusal, the thin-image @max(1, roundEven) guard in the Zig contain, and the hash-keyed virtual ids. The notice credits the source with the exact revision. This confirms the 08:52Z ruling; nothing needed from the author side.

ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 19, 2026
@ashhart
ashhart force-pushed the dsv41-metal-pr/18-images-clean branch from f3cf1a5 to c479345 Compare November 19, 2026 19:00
@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. Nothing is left from your side: the comparison we owed came back an adaptation, not a copy, formula for formula as your notice pins it, and the checks were green at the reviewed head.

Main has moved in the two dsv41 Metal files, so we take the short rebase with the queue as planned; the changelog entry rides with it.

  • Synthena

ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 20, 2026
@ashhart
ashhart force-pushed the dsv41-metal-pr/18-images-clean branch from c479345 to f36d416 Compare November 20, 2026 01:46
@AIFlowML

Copy link
Copy Markdown
Contributor

I hit a compile blocker on the current f36d416d head with Zig 0.17.0 on M5 Max. zig build test-dsv41-metal-all -Dcpu=apple_m1 stops at metal/target.zig:279: Rows.build takes a u32 prompt length, while ids.len is usize.

In a scratch copy I passed @intCast(ids.len) to Rows.build. startPrompt already checks the length against the u32 limit, and the virtual-ID copy keeps that length. With the one-line change, the following passed 355 tests with six skips on the head and 356 with six skips on the clean trial merge into 124052c97:

zig build test-dsv41-metal-all test-dsv41-metal-prepare test-dsv41-serve-host \
  test-dsv41-shared test-dsv41-draft -Dcpu=apple_m1 -j5 --summary all

The synthetic PNG request matched the direct target and resumed from 77 cached rows. The two-image resume matched a fresh run, and the tower and aligner passed the float64 checks. The release-weight vision check was outside this run.

Igor Lessio - AIFLOW LABS

gilby and others added 7 commits November 20, 2026 15:05
The ViT and aligner on Metal (--vision), bias_vl routing for image rows, Engram shut on image tokens, an image
span prefilled in one chunk, and the prompt cache keyed by the image's hash. The server writes the template's
image token for an image part when the engine reads images, and refuses the reserved mark in request text.
@ashhart
ashhart force-pushed the dsv41-metal-pr/18-images-clean branch from f36d416 to 1787b42 Compare November 20, 2026 15:05
@ashhart
ashhart merged commit a7adbf7 into ashhart:main Nov 20, 2026
2 of 11 checks passed
ashhart pushed a commit that referenced this pull request Nov 20, 2026
@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thank you @gilby. 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 supernovae/TensorFold that referenced this pull request Nov 20, 2026
@AIFlowML

Copy link
Copy Markdown
Contributor

I reran this after the merge at d26d5b06b. On M5 Max with Zig 0.17.0, test-dsv41-metal-all still stops at zig/src/families/deepseek_v41/metal/target.zig:279 with expected type 'u32', found 'usize'. It is the same argument to vrows.Rows.build as in the pre-merge check.

In a scratch checkout of current main, changing just that argument from ids.len to @intCast(ids.len) let this pass:

zig build test-dsv41-metal-vision test-dsv41-metal-prepare -Dcpu=apple_m1 -j4 --summary all

The synthetic tower checks passed, and resuming past two images matched a fresh run. The cast fits the existing guard: ids_in.len is checked against a u32 limit before withVids makes its same-length copy.

Igor Lessio - AIFLOW LABS

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.

4 participants