Skip to content

Upstream PR: long image renders give way to live speech on the GPU - #4650

Merged
ashhart merged 10 commits into
ashhart:mainfrom
plotarmordev:feat/107-upstream-pr-long-image-renders-give-way-
Nov 24, 2026
Merged

ashhart merged 10 commits into
ashhart:mainfrom
plotarmordev:feat/107-upstream-pr-long-image-renders-give-way-

Conversation

@plotarmordev

@plotarmordev plotarmordev commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before, a long H3 image render on a Mac kept the GPU for its whole run, so a live voice reply sent mid-render waited behind it: 72.854 s for one note during a large render. With this change the speech server holds /tmp/tensorfold-speech.lock shared while it speaks. The H3 tools (tf-h3-dit, tf-h3-image, the prompt encoder, the decoder and tf-h3-image-server) yield between blocks and stages while it is held, and each timed step prints timing_valid so a step that waited is marked. Under the same load the voice reply took 9.397-9.774 s, and the render bytes did not change.

  • Issue: n/a. I port this from my fork (Long image renders give way to Capri's live voice on the Mac's GPU plotarmordev/TensorFold#49 and v0.3.5 / v0.3.5.1 CUDA build fails: sm_90+ features (this_cluster, FP8 cvt/MMA) compiled for sm_80/sm_86 #56), cherry-picked with -x. It builds on h3: MiniMax-H3-Image's prompt encoder, transformer and decoder resident across pictures #3718, which is merged.
  • Stacked on: main at 11b815e376ce122026f3c4011029ada2a56da53c. This PR adds eight commits:
    • 3b0c3e4e h3, server: long image renders give way to live speech on the Mac's GPU
    • 1308131a docs: the live speech server must publish the lock; voice during a large render 72.9 s -> 9.4-9.8 s
    • 35889ed8 server, h3: speech frees the GPU turn before client writes; failures drain every committed buffer; the lock refuses planted paths
    • 7904411a server, h3: planted FIFOs, hard links and exclusive holds no longer stall or redirect the speech turn; speech arriving as the last blocks drain goes before the output heads
    • 4969f287 server, h3: one-line comments; speech voices and H3 speech-arrival tests in their own files
    • 1ee76e25 server: speech_voices_test reaches the byte tokenizer's encode
    • d842428b server: a timed step's stamp is read under the exclusive probe, so speech stamping between the read and the probe no longer certifies it
    • 5e689a34 server: the speech lock builds for Windows, which has no mode bits to widen or check
  • atc overlap --json: no overlaps reported, but the result was incomplete (complete: false; limits: pull files, other pull requests and time).

How to check

  • Base: 11b815e376ce122026f3c4011029ada2a56da53c (main under this branch). Head: 5e689a34f213b5c2cbb1bb059e1e9da830b112aa.

  • Machine: Apple M5 Ultra Mac Studio, 256 GiB, macOS 27.0, Zig 0.17.0 (.zig-version). No extra env vars or flags.

  • zig test zig/src/server/gpu_turn.zig: 6 passed, 0 failed, 0 skipped. The forced stamp-between-read-and-probe regression fails (5 passed, 1 failed) when I restore the previous read-then-probe ordering in a scratch copy at this head.

  • nice -n 10 zig build test test-golden --summary failures --cache-dir "$(mktemp -d)", uncached at the head: 17444 passed, 4 failed, 146 skipped of 17594, plus the _memcpy link-check step (977/984 steps; exit 1). Golden: no unexpected differences. Every failure is in code this PR does not touch, and all fail on the base too:

    • persistence_identity_test: tokenizer and template edits reuse only identical canonical token prefixes
    • net: an unknown host is refused, and a connect with no listener times out
    • vision and families.deepseek_v41.metal.vision: the release's vision_config parses to the defaults (the same test in two binaries)
    • the tensorfold-native _memcpy link check (nm -m … external _memcpy (from libSystem))

    serve_steps_test passed in this run. It is flaky: it failed in an earlier run at 7904411a, and it fails on the base. On base 11b815e3 the same command gave 17429 passed, 5 failed, 146 skipped of 17580, failing the same four tests plus serve_steps_test and the same link check.

  • nice -n 10 zig build test-h3-image-server --summary all --cache-dir "$(mktemp -d)", uncached at the head: 43/43 steps, 7/7 tests passed. These tests run the resident server on a synthetic checkpoint, with speech arriving during each stage.

  • Voice during a render: the procedure, workload and probes are in docs/recipes/minimax-h3-image-metal.md, "Large resident renders and a live speech server". The renderer was built with zig build tf-h3-image-server -Dcpu=apple_m1 -Doptimize=ReleaseFast and drew 5472x3072 at seed 2201 (183 prompt tokens, six steps). The voice request used model="fishaudio/drama-3" and the public sentence quoted in the recipe. Each request was sent after the render's drawn on line and timed to the complete audio response. While it ran, a separate process tried a nonblocking exclusive flock on /tmp/tensorfold-speech.lock every 20 ms, and I compared /tmp/tensorfold-speech.lock.stamp before and after.

Before / after (measured at 1308131a)

Same Mac, renderer executable (same SHA-256), workload and voice text on both sides.

Voice during a large resident render (complete reply)
Before: speech server without the lock 72.854 s (first PCM 18.856 s); 776 probes, no hold, stamp unchanged, all six steps waited zero
After: speech server with the lock 9.397, 9.538, 9.774, 9.769, 9.676 s (five notes, M4A, transport and encoding included); 76-93 of each 93-111 probes found a hold
  • Render output: the same server replayed 17 resident requests (eight 5472x3072, six 3072x5472, three 4096x4096), each with a streamed voice request at its start. 17/17 returned HTTP 200, first PCM in 1.061-2.224 s, full body in 5.484-9.421 s. All 17 final latents and PNGs matched the run without the lock by SHA-256. The image logs show 183.28 s of waits, and 25 of 102 steps reported timing_valid=false.
  • These timings were taken at 1308131a. 35889ed8 and 7904411a only change when speech hands back the GPU turn, how failures drain and how the lock file is opened. 4969f287 and 1ee76e25 only touch comments and move tests between files, d842428b only changes the probe/read ordering and adds its regression test, and 5e689a34 only lets the lock build on Windows. None changes the arithmetic, so I did not repeat the GPU run. These are contention numbers, not a speech-free throughput comparison.

Checks on this head

  • Head commit: 5e689a34f213b5c2cbb1bb059e1e9da830b112aa
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 165 and 165, 0 new.
  • Tests run, with the command and pass, fail and skip counts: see How to check above.
  • CI: pending on this head when I wrote this.
  • Not run, and why: no new GPU run, since the timings above stand for this head (see Before / after). No CUDA or HIP, because the speech lock and the H3 yields are Metal-only paths.

Receipt

  • Main against branch: before and after above, same machine, renderer and workload.
  • Boxes it reaches: an Apple Silicon Mac running the speech server and H3 image tools on one GPU.
  • New switch? None. The lock path is fixed at /tmp/tensorfold-speech.lock, and with no speech server holding it the render never waits.
  • Environment: TensorFold base 11b815e3, head 5e689a34 (timings at 1308131a), Zig 0.17.0, Metal, Apple M5 Ultra, 256 GiB, macOS 27.0, MiniMax H3 image checkpoint per the recipe.
  • Paths and platforms the change reaches, which I ran and which I could not: the H3 Metal forward, prompt encoder and decoder, tf-h3-image-server, and the speech server's synthesis turn. I ran these on M5 Ultra only; M1-M4 are not run.
  • Exactness: render bytes are unchanged, with 17/17 latents and PNGs equal by SHA-256 to the run without the lock. This PR does not touch token decoding.
  • Main against this branch, same machine and checkpoint: in the table above.
  • Decode speed before and after: n/a. This PR does not change LLM decode. It only lets speech go first on a shared GPU.
  • Prompt speed before and after: n/a, because this PR cannot reach LLM prompt processing.
  • Licence of any new weights or drafter: 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. (Pass at this head; I did not rerun them against the base for this description.)
  • 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.

For a change that reaches inference:

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (The speech turn is taken around the existing synthesis call; LLM lanes are untouched.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (n/a: this PR touches no drafting, prompt resume or LLM batching. For the H3 tools, output with speech arriving mid-stage equals output without it, in test-h3-image-server and in the 17/17 SHA-256 replay above.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (No bits change: yields only wait between committed passes.)
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled. (n/a: LLM decode and prompt processing are not reached. With no speech server holding the lock, each yield between blocks and stages is one open of the lock file and one nonblocking flock.)

Before (voice-during-render)

https://raw.githubusercontent.com/plotarmordev/TensorFold/15270ce92983f6911d72dc56dd259152d4675411/media/before-0.mp4

After (voice-during-render)

https://raw.githubusercontent.com/plotarmordev/TensorFold/15270ce92983f6911d72dc56dd259152d4675411/media/after-0.mp4

How to check

  • Base commit (main): 11b815e376ce122026f3c4011029ada2a56da53c
  • Head commit: ced40693b6b48e8fdff6221357320f6127eeae73
  • Machine: a Mac Studio (Apple M5 Ultra) · macOS 27.0 · Zig 0.17.0

Test results:

  • nice -n 10 zig build test test-golden --summary failures at 1308131aeef5 (older head): 1905 passed, 4 failed, 30 skipped
  • nice -n 10 zig build test test-golden at 35889ed80bad (older head): 3791 passed, 4 failed, 45 skipped
  • zig build test test-golden --cache-dir <fresh empty dir> --summary failures at 7904411a50d0 (older head): 17440 passed, 5 failed, 146 skipped
  • zig build test test-golden --summary failures at 11b815e376ce (older head): 17429 passed, 5 failed, 146 skipped
  • nice -n 10 zig build test test-golden --cache-dir <empty dir> at 7904411a50d0 (older head): 17441 passed, 4 failed, 146 skipped
  • nice -n 10 zig build test-h3-image-server --summary all --cache-dir <empty dir> at 7904411a50d0 (older head): 6 passed, 0 failed, 0 skipped
  • nice -n 10 zig build test test-golden --summary line --cache-dir .zig-cache/b2-fresh2 at 1ee76e250722 (older head): 17441 passed, 5 failed, 146 skipped
  • zig test zig/src/server/gpu_turn.zig at ced40693b6b4: 6 passed, 0 failed, 0 skipped
  • nice -n 10 zig build test test-golden --cache-dir "$(mktemp -d)" at d842428b1439 (older head): 17444 passed, 4 failed, 146 skipped
  • nice -n 10 zig build test-h3-image-server --summary all --cache-dir "$(mktemp -d)" at ced40693b6b4: 7 passed, 0 failed, 0 skipped
  • nice -n 10 zig build test-server-cpu --summary all at 5e689a34f213 (older head): 1850 passed, 0 failed, 15 skipped
  • nice -n 10 zig build test-h3-image-server --summary all at 5e689a34f213 (older head): 7 passed, 0 failed, 0 skipped
  • nice -n 10 zig build test test-golden --summary failures --cache-dir "$(mktemp -d)" at 5e689a34f213 (older head): 17444 passed, 4 failed, 146 skipped
  • nice -n 10 zig build test test-golden --summary all at ced40693b6b4: 17443 passed, 5 failed, 146 skipped

@plotarmordev

Copy link
Copy Markdown
Contributor Author

Fixed zig-b in 5e689a3: the Windows cross-compile failed at gpu_turn.zig:64 because Windows File.Permissions has no fromMode. The lock and stamp now only widen and check mode bits where the platform has them (@hasDecl(std.Io.File.Permissions, "fromMode"), same as compact_mem.zig). I checked it locally with zig build compile-native-cuda-windows, zig build test-server-cpu (1850 passed, 15 skipped) and zig build test-h3-image-server (43/43 steps).

plotarmordev and others added 10 commits November 24, 2026 00:36
The speech server holds /tmp/tensorfold-speech.lock shared while it
synthesizes; the H3 tools (tf-h3-dit, tf-h3-image, the prompt encoder,
the decoder and tf-h3-image-server) wait between blocks and stages while
it is held, and every timed step prints timing_valid.

(cherry picked from commit 980b5d5)
…rge render 72.9 s -> 9.4-9.8 s

(cherry picked from commit f84c1dd)
…drain every committed buffer; the lock refuses planted paths

The speech server's turn now ends with its output lane, when the engine's work ends, so a slow client
no longer holds a render back. H3's forward and prompt passes keep committed command buffers in
gpu_turn.Queue, which returns a failure only after every buffer committed with it has completed. The
lock is opened without following symlinks and created only when absent, and speech waits at most a
second behind an exclusive hold before it synthesizes without the turn.
…tall or redirect the speech turn; speech arriving as the last blocks drain goes before the output heads

gpu_turn opens an existing lock or stamp nonblocking and without following links, and uses it only when it is one regular file with a single name: a FIFO no longer blocks speak() or yield(), and a hard link no longer receives the stamp's bytes. Speech only shares the lock, so a hold that also refuses a shared probe is not waited for. H3's forward yields once more after draining the last blocks, before the final norm and output heads are committed.
…eech stamping between the read and the probe no longer certifies it
…d buffer completes

The yield after the output heads were waited deferred no GPU work; it only held a finished render for a whole speech request. Speech arriving then now only marks the step's timing invalid.
@ashhart
ashhart force-pushed the feat/107-upstream-pr-long-image-renders-give-way- branch from ced4069 to 13ee02d Compare November 24, 2026 00:36
@ashhart
ashhart merged commit 8e4f778 into ashhart:main Nov 24, 2026
11 of 12 checks passed
@ashhart

ashhart commented Nov 24, 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.

ashhart added a commit to AbrahamCete/TensorFold that referenced this pull request Nov 24, 2026
ashhart added a commit that referenced this pull request Nov 24, 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.

2 participants