Repository navigation
feat(drama3): reuse a voice reference's prefill across requests - #1237
Open
plotarmordev wants to merge 1 commit into
Open
plotarmordev wants to merge 1 commit into
plotarmordev wants to merge 1 commit into
Conversation
Keep one live KV prefix and one reusable recurrent-state snapshot pair per Metal lane. The prompt builder reports the invariant reference boundary; cache identity includes the tower lookahead row and compares exact owned frames rather than a hash alone. Preserve original prefill chunk cuts. Invalidate before incompatible/default prefill and on execution failure. Reuse GPU-owned buffers across voice switches, including partial-allocation failures. Rebuild per-request decode counters and leave CUDA uncached. Add deterministic boundary, exactness, invalidation, ownership and prompt regressions. Co-authored-by: BobClawblaw <288991054+BobClawblaw@users.noreply.github.com> Co-authored-by: jerryfane <38183696+jerryfane@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
On Metal, a Drama speech request that uses a catalog voice now reuses that voice reference's prompt prefill across requests on the same lane. The first request saves the lane's recurrent state at the end of the reference prompt. A later request with exactly the same reference rows prefills only the rows after them. CUDA stays uncached. The default voice, and requests without a voice, are unchanged.
This builds on the voice-catalog and redraw code now on main (#1120, #1135, #1160, #1162). It is not stacked on any open pull request.
reference_rows, where the invariant reference prompt ends before the request text.SpeechRequest.reference_rowscarries it, and 0 turns reuse off. The saved row stops on an existing prefill chunk boundary, and the tower's lookahead row stays inside the invariant prompt. A cached request therefore makes the same chunk cuts as an uncached one.reference_rowsto the first take and to a plain-speech redraw.drama3: reference cache built (N rows)anddrama3: reference cache hit (N rows restored).@BobClawblaw wrote the change. @jerryfane reviewed it on a Mac, found two defects and repaired them. Both are credited as co-authors. I ported it onto current main.
Receipt
b0928cc8on main4167b876, and some earlier runs on0d4592d3, which differs fromb0928cc8only in source comments. Linux aarch64, Zig 0.17.0, CPU only,CUDA_VISIBLE_DEVICESempty. No GPU, no Metal device, no MLX or PyTorch.d1018b31, not on this branch. Hardware: Mac Studio, Apple M5 Ultra, 256 GB, native Metal, Zig 0.17.0. Checkpoint:fishaudio/drama-3@e0a9218a. Candidate enginec265ca2f(with this change) against baseline881151ca(the same series without it). Sources: first review, repair and retest, machine-readable results.d1018b31, main has gained the Metal residency set (50ddf20d) and moved the voice prompt intodrama_voice.zig. On this branch, snapshot buffers go throughGpu.register, which joins the residency set. That path did not exist in his runs, and I have not run it on Metal.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: speech returns PCM, so PCM is compared by SHA-256. All results in this item are @jerryfane's Mac runs.tools/bench_openai.py: not measured. I make no speed claim.ttft_sfromtools/bench_cache.py --require-coldon a long prompt, or "n/a" with the reason when the change cannot reach prompt processing: not measured. I make no speed claim. The uncached prompt path keeps its chunk cuts.b0928cc8differs from0d4592d3only in comments: it joins five multi-line comments into single lines and rewords one of them. No code changed. Each result names the commit it ran on.zig build test --summary allonb0928cc8: 302/302 steps, 3647/3661 tests passed, 14 skipped.zig build testrun on0d4592d3, made while a second build ran on the same host, failed in code this change does not touch.fate_testreportedrank 1's failure ends both ranks with its reason(expected 2, found 1), andrank 0's clean stop ...aborted on an index out of bounds infate.zigrunHooks. Every other run of the suite on that commit passed, including a fresh-cache run with the same counts as above.CUDA_VISIBLE_DEVICES= zig build test-cuda-host --summary allonb0928cc8: 192/192 steps, 1463/1464 tests passed, 1 skipped; the other steps were cached. On0d4592d3with a fresh cache: 192/192 steps, 2796/2801 tests passed, 5 skipped.zig build test-drama-host --summary allonb0928cc8: 38/38 tests passed.zig build test-drama-prefill-host --summary allonb0928cc8: 2/2 tests passed.zig build test-drama-owner --summary allonb0928cc8: 6/6 tests passed.zig build check-drama-cuda-host --summary allon0d4592d3: 4/4 steps.zig build test-goldenonb0928cc8: 306/319 equal to the server goldens, 0 unexpected differences. Additional corpus: 26/26 equal.zig build native -Dversion=1.0.0on0d4592d3: built.tools/zig/test_speech_flags.pyon0d4592d3: 1 test, OK, against that binary.tools/zig/test_drama_prefill_compare.pyon0d4592d3: 5 tests, OK.zig fmt --checkon the changed files, onb0928cc8: clean.0d4592d3: I cross-compiled the three objects ofcheck-drama-metal-hostforaarch64-macos. To do it, I changed a local copy of the build script to retarget the step and skip framework linking. Nothing was linked or run, and no shaders were compiled. All three objects compiled. A deliberately broken call in the Metal hit path made that compile fail, which shows the Metal branch is analysed.0d4592d3, each run once, both failed a test:reference_rowsfrom the server's voice prompt failedvoices: HTTP listing and reference rows use the family CLI builder.reference cache: switches reuse one snapshot pair and restore the latest recurrent state.python3 tools/zig/lean_check.pyonb0928cc8: 437 findings, a list identical to base4167b876. This change adds no findings.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.SUMMARYline is in the receipt.