Skip to content

core: Drama 3's torch.save reader and WAV code move to core (torch_pth, torch_zip, wav) - #3719

Merged
ashhart merged 3 commits into
ashhart:mainfrom
BobClawblaw:torch-reader-core
Nov 20, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
BobClawblaw:torch-reader-core

Conversation

@BobClawblaw

@BobClawblaw BobClawblaw commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

The reader extraction asked for on #3615, as its own change. Two commits on main 0900b484e: the move, and host regressions for the reader's new paths (asked for in review).

What it does

  • Drama 3's torch.save reader moves from families/drama3/codec_pth.zig to core/torch_pth.zig, and its WAV code from families/drama3/wav.zig to core/wav.zig (a pure move). Drama reads its codec through core.torch_pth as before.
  • It is not a pure move of the reader: the zip container is split into core/torch_zip.zig, and the reader also takes nested state dicts, named by their keys (openNested, readRaw). ZONOS3's checkpoints need both; Drama uses neither.
  • core/torch_pth_test.zig (new): host regressions for openNested and readRaw on archives built in the test: nested names and metadata, flat-mode refusal, offset slices, and malformed and CRC cases. Each check fails with its guard taken out of the reader.
  • On Metal, Drama's core is a generated shim over the engine facade, so zig/src/tensorfold.zig exposes the two files and the three shims (drama3_metal.zig, residency_host.zig, slide_host.zig) pass them through. Without that the Metal native server does not compile; Linux CI does not see it.

Drama 3 before and after, on real hardware

fishaudio/drama-3 on an M5 Ultra (Metal), main 6d0a128b0 against the move, same arguments, builds alternating:

Run Compared Result
drama3-generate: greedy; seeded; --encode of a reference clip; a cloned voice from that clip; the same streamed with --pcm-out; frames with --out each output file's sha256, three rounds a build identical for every file
/v1/audio/speech from tensorfold-native serve: seeded whole WAV; seeded streamed PCM; a default request; one with temperature, top_p and top_k each reply's sha256, two requests from each of two server starts a build identical for every request, all 200

Speeds agree. Frames a second over the three rounds, main then this commit: greedy 72.1 to 72.3 and 71.9 to 72.2; seeded 74.0 to 74.4 and 74.0 to 74.2; cloned 73.21 to 73.55 and 73.34 to 73.45; streamed 76.2 and 76.0 to 76.3; frames only 86.0 to 86.1 and 85.9 to 86.1. The served whole reply took 4.66 to 4.68 s on main and 4.66 to 4.69 s here. The reference clip was the model's own greedy output.

After the rebase onto 0900b484e, with the tests added, the same runs on the M5 Ultra: main 0900b484e and this head (5a8524d30) give the same sha256 for every drama3-generate output (seven files, three rounds each) and every served reply (four requests, two from each of two server starts, all 200). Cloned run 72.35 to 73.30 frames a second on main and 72.58 to 73.37 here; served whole reply 4.68 to 4.71 s on main and 4.67 to 4.71 s here.

The reader alone, on the host: codec.pth (sha256 74fc41c5…bb2f as on the hub, revision 78e5ab79) read by main's reader and by this one gives 541 tensors with identical names, dtypes and shapes, and the 535 fp32 tensors byte-identical (1,565,722,120 bytes).

Not run: Drama on CUDA. Its load peaks at 48 GB on the device and I have no free CUDA machine that holds it; the CUDA side of this change is the same import rename, compiled by check-drama-cuda-host and test-cuda-host.

Checks (on this head, 5a8524d30, main 0900b484e)

  • The no-GPU workflow's steps on Linux, as the workflow runs them (-Dfixed-cpu, its timeouts): test-host-a, test-host-b, test-kernel-contract, test-golden, test-gradient-serving test-qwen-serving-host, test-server-security test-pull-security, fuzz-cortheon, test, check-release-paths, test-drama-host test-cuda-host: all pass.
  • zig fmt --check build.zig zig; the lean check against the base: 221 problems on both, 0 new; the CUDA common and fragment checks.
  • On macOS (M5 Ultra): zig build, zig build native and zig build test pass on this head.
  • No new GPU kernel, so nothing new for the kernel contract.

atc overlap --json: came back incomplete (its PR, file and time limits). Of what it checked: textual conflicts with #1850 (2 files) and #2522 (1 file); clean with #1434 and #1766; #1767, #2826 and #2648 share a file, merge not determined.

For #3615.

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @BobClawblaw. The extraction and Drama import wiring look sound. Before landing, please add host regressions for openNested and readRaw: nested names and metadata, flat-mode refusal, offset slices, and malformed/CRC cases. The retained tests all use the old flat/readF32 paths, so they do not cover those new APIs.

  • Synthena

@BobClawblaw

Copy link
Copy Markdown
Contributor Author

Thanks. Added in 5a8524d30: zig/src/core/torch_pth_test.zig, run by zig build test through core/root.zig. Each test builds its torch.save archive in the test (stored zip members, a protocol-2 pickle written opcode by opcode), so there are no binary fixtures.

  • openNested, nested names and metadata: tensors are named by their keys joined with /, through state dicts that carry torch's _metadata (BUILD). Plain values (ints, strings, floats, lists) and the metadata do not become tensors.
  • readRaw, offset slices: offset views of one shared storage give their own bytes at fp32 and bf16. A view past its storage, a strided view, a storage member of the wrong size, a missing storage and the wrong dtype are refused.
  • Flat-mode refusal: open refuses a nested root. openNested also refuses a name reached twice and a root nested past eight levels.
  • Malformed and CRC cases: a storage byte changed after its CRC was written (the open succeeds, the read refuses), a pickle with a bad CRC, a missing end record, a file too short to hold one, no data.pkl or two, a big-endian byteorder, a pickle without STOP, and a member whose local header lies past the end of the file.

Each check fails with its guard taken out of the reader: I removed 14 guards one at a time, and each removal fails at least one test.

The branch is also rebased onto main 0900b484e. The no-GPU workflow's steps on Linux pass on this head, the new tests among them (zig build test), as do test-drama-host test-cuda-host. Drama 3 on the M5 Ultra, main against this head: every output and served reply byte-identical, speeds the same. Lean: 221 and 221, 0 new.

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @BobClawblaw. The regressions you added cover all four groups we asked for: nested names and metadata, flat-mode refusal, offset slices, and the malformed and CRC cases. They run through zig build test, and we found nothing to add. Nothing further is needed from you on this PR.

  • Synthena

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @BobClawblaw. As we said on 19 November, the regressions you added cover all four groups we asked for and nothing further is needed from you. The head applies cleanly to today's main and the byte-identical Drama 3 receipts stand.

  • Synthena

BobClawblaw and others added 3 commits November 20, 2026 08:47
…h, torch_zip, wav)

The reader also takes nested state dicts, named by their keys, and its zip container is its own file. Drama 3 reads
its codec through core.torch_pth as before.
The retained tests cover the flat readF32 path only. torch_pth_test.zig builds
torch.save archives in the test (stored zip members, a protocol-2 pickle written
opcode by opcode) and checks:

- openNested: tensors named by their keys joined with '/', through state dicts
  that carry a _metadata BUILD; plain values (ints, strings, floats, lists) and
  the metadata are not tensors.
- readRaw: offset views of one shared storage at fp32 and bf16 widths, and the
  refusals of a view past its storage, a strided view, a storage member of the
  wrong size, a missing storage and the wrong dtype.
- Flat-mode refusal of a nested root; a name reached twice and a root nested
  past eight levels are refused.
- Damage: a storage byte changed after its CRC, a pickle with a bad CRC, a
  missing end record, a file too short, no or two data.pkl, a big-endian
  byteorder, a pickle without STOP, a member whose header lies past the end.

Each check fails when its guard is removed from the reader.
@ashhart
ashhart merged commit 6ddba17 into ashhart:main Nov 20, 2026
11 checks passed
@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

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

BobClawblaw added a commit to BobClawblaw/TensorFold that referenced this pull request Nov 23, 2026
…eply options, reruns, the Drama 3 A/B, the shared code left

Main's reply options (24-bit and float WAV, FLAC, sample_rate, stereo) apply to ZONOS3's whole replies.
The port-side checks, the repo checks and the Drama 3 A/B were run again on main 281d81b; the reader
and WAV moves left the shared-code list with ashhart#3719, and the voices holder and parseFrom with ashhart#4609.
BobClawblaw added a commit to BobClawblaw/TensorFold that referenced this pull request Nov 24, 2026
…eply options, reruns, the Drama 3 A/B, the shared code left

Main's reply options (24-bit and float WAV, FLAC, sample_rate, stereo) apply to ZONOS3's whole replies.
The port-side checks, the repo checks and the Drama 3 A/B were run again on main 281d81b; the reader
and WAV moves left the shared-code list with ashhart#3719, and the voices holder and parseFrom with ashhart#4609.
ashhart pushed a commit to BobClawblaw/TensorFold that referenced this pull request Nov 24, 2026
…eply options, reruns, the Drama 3 A/B, the shared code left

Main's reply options (24-bit and float WAV, FLAC, sample_rate, stereo) apply to ZONOS3's whole replies.
The port-side checks, the repo checks and the Drama 3 A/B were run again on main 281d81b; the reader
and WAV moves left the shared-code list with ashhart#3719, and the voices holder and parseFrom with ashhart#4609.
ashhart pushed a commit to BobClawblaw/TensorFold that referenced this pull request Nov 24, 2026
…eply options, reruns, the Drama 3 A/B, the shared code left

Main's reply options (24-bit and float WAV, FLAC, sample_rate, stereo) apply to ZONOS3's whole replies.
The port-side checks, the repo checks and the Drama 3 A/B were run again on main 281d81b; the reader
and WAV moves left the shared-code list with ashhart#3719, and the voices holder and parseFrom with ashhart#4609.
ashhart pushed a commit that referenced this pull request Nov 25, 2026
…tions, reruns, the Drama 3 A/B, the shared code left

Main's reply options (24-bit and float WAV, FLAC, sample_rate, stereo) apply to ZONOS3's whole replies.
The port-side checks, the repo checks and the Drama 3 A/B were run again on main 281d81b; the reader
and WAV moves left the shared-code list with #3719, and the voices holder and parseFrom with #4609.
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