Repository navigation
zonos3: ZONOS3 Mini text to speech on Metal (stacked on #3720) - #3732
BobClawblaw wants to merge 57 commits into
Conversation
|
/atc depends 3720 |
…, the speech plan: two runs, 3 of 4 cases before cloning was on Metal (a6820a735), then 4 of 4 with cloning (d6f616ec4, the tree of zonos3-metal 796b1565e, draft ashhart/TensorFold#3732): 16.7-19.1 times real time, the clone in 1.31 s; stats
… status, logs, command, say, page, validate, launchd; serve.sh and run.sh go The pin moves to zonos3-metal's head 52228c3dd (draft ashhart/TensorFold#3732), fetched from the fork when a clone lacks it. The speech run repeated on the binary mac build makes: all four replies byte-identical to the earlier run's, memory the same to the byte; figures and evidence from the new run.
…metal 52228c3dd, draft ashhart/TensorFold#3732): 4 of 4, replies byte-identical to the d6f616ec4 run, 16.7-18.9 times real time; target comment current; stats
52228c3 to
ef38d37
Compare
|
Brought up to the top of the ZONOS3 stack (#3885, |
…shhart/TensorFold#3732, on the ZONOS3 stack) at four requests at once with steering, LACI and short texts: speech, speech-normalize, speech-controls, speech-concurrent, speech-steer, speech-laci and speech-edit all pass; 18 of 18 replies at once equal to alone; stats
|
Thanks @BobClawblaw for bringing the Metal work to the top of the ZONOS3 stack and posting the 139 reference checks and 41/41 kernel-contract result. The owned code opens the shared ZONOS3 host on Metal ( The remaining issue is application to current main. The supplied diff conflicts in 15 files across the contract registry, native families, server, Metal contract registry and serving pins. Please rebase the eight owned Metal commits after the lower stack lands, preserving the current Metal and CUDA parity evidence.
|
ef38d37 to
5e90182
Compare
…'s dumps fp32 rows over the published bf16 weights (model.pth read without Python), one row-kernel path for prompt and decode rows. zonos3-generate --check compares every sublayer with tools/dump_golden.py lm captures of Zyphra/ZONOS3-Mini.
…d against the reference's greedy frames
…nce's captures and audio Nested torch checkpoints (generator.pt, the decoder heads) read without Python; frames decode in any chunks to the same samples as one pass.
…, the output stage zonos3-generate --text matches the reference's prompt rows and greedy frames, and its audio matches the reference's CPU fp32 decode.
…'s default voices, its sampling defaults The torch checkpoint reader moves to core (Drama 3's codec and ZONOS3 share it). A release folder has no config.json: it is recognised by lm/zonos3_mini/params.json and its tokenizer loads from there. The speech request gains an optional speaker vector.
…es after each; host tests in test-cuda-host
…against the reference's fp32 run
…hecked against the reference's fp32 run
…at it gave) and the reference-dump tool
…nd: codes equal to the reference's fp32 run
… to the reference's fp32 run at one and four lanes
…he engine on first use Drama 3's WAV reader and resampler move to core for both families. The speech request gains reference_audio.
… codes for other models
Clients written for OpenAI's text to speech send alloy, nova and the like unless told otherwise. A name the release has stays that voice; any other unknown name is still refused.
response_format takes mp3, opus and aac where LAME, libopus and FDK AAC load (looked for on first use, like the image libraries; a missing one refuses its format with the line to act on) and flac, which the server writes itself. A whole or streamed pcm reply carries X-Audio-Sample-Rate. WAV stays the default and its bytes are unchanged.
A request that asks for it has its text rewritten into its spoken form before the tokenizer, as the reference servers do, by the publisher's own library loaded on first use (TENSORFOLD_LIBZYPHRA_TEXTNORM, or lib/ beside the installation). language picks the grammar (en_us by default, the reference's 44 codes). Only text_normalization: true normalizes; left out or false, the text is spoken as typed whether or not the library loads, so installing it changes no reply. true without the library is refused with the line that says how to build it. zonos_textnorm_test.zig checks the text step against every case of the reference's test_textnorm_wrapper.py, byte for byte, where the library loads.
condition_values and condition_buckets set the loudness, fmax and speaking-rate rows (a raw value through the edges in params.json); speaker_cfg_scale runs the reference's twin, the prompt without its voice, on a second set of caches and samples each frame from the two logits mixed on the host. Greedy frames equal the reference's for both, alone and together, on the reference-prefix and the speaker-row paths.
Each request has a lane of the backbone's caches and recurrent state and a lane of the decoder's; one worker gives every request in progress a turn, a frame each, through the single-stream passes already checked. A reply beside others is the reply alone, byte for byte. Each request at once past the first adds 1,236,862,976 device bytes, admitted with the load. Nothing is batched across requests: the total speed is one request's.
Engine.runLanes runs a row of each lane together: the launches that read no lane's state take every row at once, and the four that do run a lane at a time on that lane's state. A request's reply is still the reply alone, byte for byte. Four 17.8 s replies at once take 1.71 s where they took 2.42 s; a guided request's two passes a frame are one.
…odes in the stream's chunks The codec decoder's linear layers are cuBLAS's fp32 GEMM (a bias by a rank-one GEMM); the clip encoder and the quantizer keep zc_linear. cuBLAS rounds by the rows of a call, so whole replies decode in the chunks a stream uses and the two stay byte-equal. On the RTX 5090 a 17.8 s reply takes 0.48 s where it took 0.61 s, and four at once 1.17 s where they took 1.71 s. The load admits 33,556,480 bytes more (cuBLAS's workspace and a row of ones).
…en hold, controls guidance, embedding voices A request's controls name directions of the publisher's steering bundle. Hidden directions add dose times the vector to Full AttnRes bank sources on every generated frame (z3_combine as one fp32 add, checked by the kernel contract at that shape); speaker-embedding directions move an embedding voice's vector and keep its norm. speaker_mode "embedding" and speaker_embedding speak a voice by its speaker row. GET /v1/audio/controls lists the directions. Against the publisher's code with its bundle, five greedy requests: the host's deltas and moved embeddings are bit-identical, and the frames are identical at --max-rows 1, 7, 64 and 256.
…eme, start and pause tokens LACI reads a request's place in its text from the alignment heads' attention after every row, rolls a skip, a stall or an early end back to its onset and regenerates under ACI masks; the masked heads run through the same attention kernel over a closed-up cache. The release's 143 extra text rows load in fp32 and embed exactly; their markers tokenize as in the reference. A text of a word or two is generated with a pause and a filler sentence and cut where the filler starts. Against the publisher's code: its seven portable replay fixtures pass; on the model, thirteen greedy requests (four that retry eight times) give its readings, masks, rows and records; and the three token requests give its frames.
…forced aligner - The release's speech-edit adapter (zonos-accent-lora/3) on the backbone: its bf16 factors through z3_linear and z3_combine, its span-end and marker rows in fp32 on the host. An edit's fills run on it in a pass of their own; other requests never read it. - edit.zig, edit_plan.zig, difflib.zig: the release's edit prompts, fills, splice, word diff, windows and fill lengths. server/speech_edit.zig plans an edit and drives the engine's steps (a clip's codes, a fill's rows, the edited codes' audio, words placed in a clip): POST /v1/audio/edit and /v1/audio/edit/align. - speaker.zig: the release's MECT-B2 speaker encoder in fp32 on the host's cores: a clip's embedding for an edit's speaker row, and for speaker_mode "embedding" with ref_audio on /v1/audio/speech. - cuda/aligner.zig: FuseAlign and its Dia text encoder from the release's web/aligner export, on kernels the family already has and cuBLAS. - No new kernel; the shapes these launch existing kernels at joined the kernel contract's served lists. - tools/zig/zonos3_reference_edit.py: the reference dumps the checks compare with.
…_follow "reading") - span_follow.zig: the reference's span follower (a running median of readings, held monotone, a span ramped in and out by the reading's place against its tokens), decided once a frame and rolled back with LACI. - server/zonos_reading.zig: each span's characters as the text positions that spell them, through normalization and the release's markers. control_span_lead and control_span_lag. - The host reads a request's own passes with the language's LACI heads; under LACI the session feeds the follower. - zonos3-generate --follow-check against the reference's readings, weights and frames; the LACI replay runs the publisher's three follower fixtures.
…ention caches as rings - The decoder head by id (Decoder: keep2_plain, full_mr; their layer counts checked at load). A request names one with `decoder` (speech and edits; unknown: the reference's 400), the reply says which in X-Decoder, and GET /v1/audio/decoders lists them. --decoders restricts the set; the default loads with the model, another on its first request, admitted for its weights and a lane for every request at once. - zc_attn_prep and zc_attention take the ring size: a stage's K and V caches hold its window and a pass's rows (position p at row p % ring), not the whole request. Loop order and sums unchanged: keep2_plain replies are byte-identical to before; a request's decoder state falls from 1,236,862,976 to 495,527,936 bytes. - The kernel contract drives both kernels through rings that wrap. - zonos3-generate --codec-check takes --decoder; the host's sizes move to native/zonos_sizes.zig.
… on the page The page sends language and normalization, condition values, speaker guidance, the decoder, LACI, short texts, start immediately, the voice by its embedding, steering controls on the whole reply or on selected text (spans counted on the text sent), and any other field as JSON; pauses and pronunciations are typed as <0.5s> and [[phones]]. A second tab edits a file or a take by its new text or by seconds, and shows the aligner's word times. The pass-through adds the controls, decoders and edit routes and the X-Decoder and X-Finish-Reason headers.
A span counts code points of the text it was selected in. After the text changed, Speak still sent the old span: the server refused one past the end, and one inside a longer text steered other words. Each span now keeps the text it was selected in, and Speak compares it with the input sent (after the other request fields are merged) and asks for the words to be selected again. Spans given in the other request fields are left as written.
…nd aligner - An upload not at 44.1 kHz reaches the speaker encoder and the aligner resampled once, straight to 16 kHz, as the release does (torchaudio's default kernel: sinc_interp_hann, width 6, rolloff 0.99); the codec path keeps its 44.1 kHz copy. features.resampleFrom takes any rate; speaker.embed takes the clip's rate. - zonos_speech.Clip carries both copies; an edit's place step sends the clip as uploaded (`reference_rate`). - check_speaker and check_aligner read the dump's rate.json; zonos3_reference_edit.py speaker and aligner take --rate.
- laci_pace.zig: the reference's DurationTarget, RateBuckets and PaceMonitor. A take read too early or too late is retaken in the speaking-rate bucket its duration ratio asks for (at most twice), a truncation one bucket slower; the retake's speaking-rate row is rewritten from the checkpoint's table and the probe reads the text's keys again. - duration_seconds and duration_adjust_rate on /v1/audio/speech (with laci: true): TensorFold's field for what the reference servers offer their plug-ins; short texts are off for such a request, as in the reference's plan. - The LACI replay takes duration targets, null seeds, heads files and max_retries; --laci-check holds a dump's session to its target.
…tizer), cloning served The encoder's and the teacher's kernels follow zonos3_encoder.cu and zonos3_teacher.cu: the same per-row reduction orders, the teacher's attention folded through threadgroup memory in two halves. The two linear kernels stage their input row in K * 4 bytes of threadgroup memory set at dispatch, as CUDA's dynamic shared memory does, so the teacher's 4096-wide and the encoder's 5888-wide rows fit. Against the fp32 reference: features cosine 1.0000000; acoustic branch 101 captures at cosine 1.000000; teacher worst row 0.9999253; clip to codes 1,450 of 1,450 (one lane) and 7,100 of 7,100 (four lanes). The backbone, frames and codec checks are unchanged (frames identical at row chunks 1, 7, 64, 256; codec SNR 114.0 dB). Served, the clip encoder holds 5,643,511,296 bytes, its admitted figure on Metal.
All 40 of the family's Metal kernels are registered with the contract, 41 registrations with zc_add_scaled tested with and without its layer scale, each followed by a planted control. The tests are the CUDA family's (zig/tests/cuda/contract_zonos3*.zig) with Metal's launches, since the kernels are CUDA's kernel for kernel; the ranges use the Metal Shading Language's precise-math accuracy (exp, log, sin, cos 4 ulps, tanh 5, pow 16, division, sqrt and rsqrt correctly rounded), and codec.metal's own erf. The contract compiles the family's sources at run time from their text in kernel_sources with precise fp32 functions; z3_common.h now carries `#pragma METAL fp contract(off)`, so that compile makes the same steps the metallib's -ffp-contract=off does. Gate 5's records (zonos3_records.zig) were measured: threadgroup bytes from Metal's reflection on the M5, M1 and M2 limits from `tf-kernel-contract --offline`. The three attentions now reserve their launch size in the source ([[max_total_threads_per_threadgroup]]), without which the offline compile found no M1/M2 limit for the codec's and the teacher's. On the M5 Ultra, `tf-kernel-contract --only zonos3`: SUMMARY 41 kernels: 41 pass gates 1-4, 0 fail, 0 known findings; 41 controls: 41 red as planted, 0 missed; 0 limit problems After the reservations, zonos3-generate's checks give the same results as before: greedy frames identical at prompt chunks of 1 and 64, codec SNR 114.0 dB, teacher worst row 0.9999253, clip codes 1,450/1,450 and 7,100/7,100 equal.
…ilies' Metal build in speech_metal.zig metal_targets.zig stays under 600 lines: Drama 3's and ZONOS3's registrations in the Metal engines move to zig/build/speech_metal.zig. Comments only otherwise; zig fmt on metal/engine.zig.
… edits, the aligner, both decoders, ring caches)
…emory, the CUDA A/B)
5e90182 to
7ce2722
Compare
|
Rebased the whole stack onto main What changed to fit main:
Checks, every head: fmt, lean (0 new problems against main), The served checks below ran on the same stack one rebase earlier ( Checks at
Checks at
|
ZONOS3 Mini (
Zyphra/ZONOS3-Mini) text to speech on Metal, for #3615. It ports the CUDA family of #3720 and its follow-ups kernel for kernel, and serves it onPOST /v1/audio/speechand/v1/audio/edit, with all 40 Metal kernels under the kernel contract. Draft, because it is stacked (below).The Metal section of
docs/recipes/zonos3-mini.mdin this branch is the full account; this text is the summary.Stacked: review the last eight commits
This branch sits on the top of the ZONOS3 stack: #3720 and its follow-ups #3872 to #3885, ending at #3885 (
zonos3-duration,634715bfd). The Metal work is the eight commits after634715bfd:12a73187athe backbone and the codec decoder on Metal7e6a3b406served on Metal through/v1/audio/speech1e8ab1c05the clip encoder on Metal (acoustic branch, SSL teacher, quantizer), so cloning is serveded45fcbf1the Metal kernels under the kernel contract600533e79lean fixes, and the speech families' Metal build calls moved tozig/build/speech_metal.zig6a7e52546the Metal section ofdocs/recipes/zonos3-mini.md301d9a577new: the stack's features on Metal (requests at once, steering, LACI, edits, the aligner, both decoders, ring caches)ef38d3707new: the Metal section at the stack's featuresWhen the stack below lands or is reshaped, I rebase this onto it.
What it is
simd_shuffle_xorbutterfly. Everything is fp32. Where a CUDA kernel's shared memory exceeds Metal's 32 KiB, the sums fold in two halves through threadgroup memory, each value's terms still in thread order.-ffp-contract=off, matching CUDA's--fmad=false.native/zonos_device.zig, which names the CUDA or Metal call for each thing it asks: memory counts, the codec, the clip encoder, the aligner. There is no Metal copy of the host.--parallel), guidance and conditions, steering and spans that follow the reading, LACI with duration targets, short texts, the edit adapter, the speaker encoder, the aligner, the release's extra text rows, and both decoders with their attention caches as rings.native/metal.zigdispatcheszonos3tozonos_open.openMetal, which applies the same flags and refusals as on CUDA.Checks on an M5 Ultra (256 GB, macOS 27.2), release
2921b88The page's checks, with the same commands and the same reference dumps as on CUDA, from this head. All 139 runs pass:
--max-rows1, 7, 64, 256short_textoffkeep2_plainandfull_mrServed (
tensorfold-native serve RELEASE --parallel 4 --steer-bundle S --laci-heads H --short-text P):/v1/audio/edit/alignanswer.--parallel 4with the edit adapter, 5,643,511,296 more for the clip encoder, 7,116,380,416 forfull_mr. Metal has no cuBLAS workspace and rounds each buffer up to 256 bytes, sonative/zonos_sizes.zigandnative/zonos_decoders.zigcarry Metal's measured figures beside CUDA's (a--parallel 1load: 3,097,555,712 against 3,125,611,008).CUDA is unchanged
The new commits move the host's device calls behind
native/zonos_device.zigand add Metal's sizes, so I checked CUDA. On the RTX 5090, this branch and the stack below it (634715bfd) served the same 90 requests: the greedy ones whole and streamed, three sampled, the eleven edits, two clones and an alignment. Every reply is byte-identical between the two, and every admission is the same.Kernel contract
zig/tests/contract/metal_zonos3*.zigregister all 40 kernels: 41 registrations, as on CUDA, each with a planted control. The ranges use the Metal Shading Language's precise-math accuracy and codec.metal's own erf;z3_common.hcarries#pragma METAL fp contract(off)to match the metallib. Gate 5 records take threadgroup bytes from Metal's reflection on the M5, and M1 and M2 limits fromtf-kernel-contract --offline. The codec attention tests now use the ring cache layout. On the M5 Ultra, from this head:Gates 1 to 4 ran on the M5 only; M1 to M4 are covered by gate 5's records.
Shared code this touches
native/metal.zig: one family entry and one dispatch line.native/zonos_open.zig:openMetal.zig/build/speech_metal.zig(new): Drama 3's two Metal build calls move there frommetal_targets.zig, beside ZONOS3's, which keepsmetal_targets.zigunder the 600-line rule.kernels/metal/sources.zig,core/contract/registry_joins.zig,tests/contract/metal_main.zigandmetal_limits.zig.Drama 3 is the only other family these touch.
fishaudio/drama-3served on the M5 Ultra from the base and from this branch's earlier head: four requests each twice, all eight replies byte-identical, with the same times. The two new commits touch only ZONOS3 files.Checks
zig build test,test-host-ci-macos-native,test-goldenandtest-kernel-contractpass on this head, with no leaks on stderr.zig fmt --checkis clean, the lean check reports nothing new in the ZONOS3 files, and the diff has nogetenv.atc overlap: the overlaps are the usual registration-list lines inmetal_targets.zig,sources.zig,registry_joins.zig,metal_limitsandnative/metal.zig, from the earlier Metal commits.Not supported on Metal
A bf16 path, as on CUDA. No part is tuned for speed.