Skip to content

lfm3_omni: LFM3-Omni-2B on Metal, speech in, text and speech out (part of #1627) - #1635

Draft
drowzeys wants to merge 10 commits into
ashhart:mainfrom
drowzeys:lfm3-omni-family-metal
Draft

drowzeys wants to merge 10 commits into
ashhart:mainfrom
drowzeys:lfm3-omni-family-metal

Conversation

@drowzeys

@drowzeys drowzeys commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Adds families/lfm3_omni, LiquidAI's LFM3-Omni-2B (speech in, streamed text and 24 kHz speech out) as a standalone family in Drama 3's shape, with its Metal backend, host tests, kernel-contract registrations, recipe and the checks' clients under tools/lfm3_omni/. Part of #1627 (the Metal half; the CUDA backend is a separate branch stacked on this one). It stays a draft until the fp32 rows of the stage table are settled (see the 16 Nov comment). Receipts are in docs/receipts/lfm3-omni-metal/.

Receipt

  • Environment: head 8d0140505 on main b4f1bf263; M5 Ultra (256 GB), macOS 27.0.1, Xcode 27.2 with the Metal compiler 32023.921, Zig 0.17.0; reference transformers 5.21.0 with the checkpoint's own code, PyTorch 2.14.1, MPS bf16, same Mac. The 16 synthetic turns of tools/lfm3_omni/utterances.txt (macOS voices), a voice-assistant system text.
  • Stage parity (greedy, identity codebook order, tools/lfm3_omni/parity.sh; precision.json). The third column is the reference's own bf16 against its fp32:
Stage Metal vs MPS bf16 Metal vs MPS fp32 MPS bf16 vs fp32
Log-mel, cosine (min), max abs 1.000000, 3.1e-4 same identical
Encoder, minimum cosine 0.999991 0.999993 0.999994
Projector, minimum cosine 0.999898 0.999891 0.999920
Prompt token ids 16/16 16/16 16/16
Backbone prefill rows, median cosine (min of medians) 0.999822 (0.999769) 0.999881 (0.999837) 0.999882 (0.999844)
Step rows, teacher-forced, median cosine (min) 0.999914 (0.999900) 0.999935 (0.999912) 0.999931 (0.999906)
Text top-1, teacher-forced 520/524 460/468 464/468
Depth decoder on the reference's own states, greedy agreement 20084/21024 (95.5%) 17126/18540 (92.4%) 17143/18540 (92.5%)
Depth logits cosine, median (min) 0.999994 (0.999889) 0.999994 (0.999890) 0.999994 (0.999869)
Codes, teacher-forced through the whole loop 18753/21024 (89.2%) 16094/18540 (86.8%) 16019/18540 (86.4%)
Codec on the reference's codes, waveform SNR median (min) 37.24 dB (25.09 dB) 36.16 dB (20.20 dB) 36.41 dB (21.15 dB)
Codec spectrum rows, minimum cosine 0.999938 0.999218 0.999523
  • Against fp32 the engine is no further than the reference's own bf16 on the step rows, the depth logits and the codes through the loop. It is further on the encoder, the projector, the prefill rows, text top-1, the depth decoder's greedy agreement and the codec.
  • The four text misses against bf16 are within 2 bf16 ulps by the reference's own logits (0, 1, 1, 2): u05 slot 58, u06 slot 39, u13 slot 38, u15 slot 1 (text-misses.json). The eight against fp32 have margins of 0.19 to 8.82 ulps; the reference's own bf16 misses one of them too (text-misses-fp32.json).
  • The port refactor (files split under 600 lines, one-line comments, the attention fix below) changes no output: greedy dumps and teacher-forced runs of this branch and of the pre-split build are byte-identical on all 16 turns (208 dump files), and the served replies at the card's settings are byte-identical too.
  • Latency, the same 16 turns through the server with tools/lfm3_omni/speech_chat_client.py (temperature 0.4, penalty 1.2, seeds 1000 + i); the reference through tools/lfm3_omni/reference_speech.py (first audio = first sampled frame plus that frame's codec decode). Two rounds, alternated; other services were resident on the Mac but idle (latency.json):
Median This branch Reference (MPS bf16)
First text 0.034 s n/a
First audio 0.064 s 0.171 / 0.175 s
Whole reply (6.5 s of speech) 0.655 s 2.31 / 2.32 s
  • Quality of the replies (UTMOS22 strong via SpeechMOS; WER = the checkpoint's own ASR on each reply's audio against its streamed text; quality.json). The margins, written into the recipe before the runs: UTMOS22 median within 0.1 of the reference's, WER within 1 point. TensorFold 4.427 median (4.352 min), WER 1.47%; reference 4.438 (4.149), WER 1.20%. Both met.
  • Streamed and whole replies give the same audio: five chunkings (1/8, 64/64, 3/5, 1/1, 2/7) of all 16 turns, spectrum rows and waveform byte for byte, 128 comparisons, 0 differ, on the tensor units and with LFM3_OMNI_NAX=0 (chunking.txt). The codec takes the tiled product at every row count and attention one row a launch.
  • No text family changed: Qwen3.8-27B MLX 4-bit on main and on this branch, two prompts, 256 greedy tokens, 6 runs a side, token hashes equal (text-family-tokens.json).
  • Prompt speed: n/a against a previous release (a new family). Prefill is inside "first text" above.

Kernel contract (Metal, M5 Ultra)

All 45 pipelines of lfm3_omni.metallib are registered (70 registrations over the stacks' variants): gates 1-4 against a float64 replay of each kernel's bf16 rounding points, stated rules for the picks and word moves, a planted source change per registration, and gate-5 launch records with M1/M2 limits from --offline.

tf-kernel-contract --only lfm3-omni --offline DIR:
SUMMARY 70 kernels: 70 pass gates 1-4, 0 fail, 0 known findings; 70 controls: 70 red as planted, 0 missed; 0 limit problems

The full suite (every family) passed on the first head (378 kernels, 414 controls red) and has not been rerun on this one: see "Not run".

The contract found one real bug, fixed here before the receipt: om_attention_tiles multiplied masked keys' zero weights into the value sum, so a non-finite value row a query cannot see turned its output into NaN. The value loop now covers only the row's visible keys. Finite outputs are unchanged, byte for byte. The full suite ran through tf-kernel-contract --rotary-accuracy with a tf-rotary-sweep receipt, because zig build kernel-contract stops first at Flash Next's UnrecordedRotaryCompiler precondition, which this change doesn't touch.

om_depth_pick now draws u = float(h >> 40) / 2^24, in [0, 1); a third registration runs a seed whose draws reach both ends of the 24 bits, and its control restores the old line and goes red. om_rmsnorm_1k's residual control dropped bf16(x + r) and went red at only about half of the seeds, because the kernel reads x back rounded; it now drops bf16(r rsqrt) and is red at every seed tried. One finding that no gate fails, noted for review: om_logmel returns the floor for a NaN log (registered as its stated rule).

Lean checker and tests

  • Lean (lean_new.py): 337 problems on the base, 337 here, 0 new.
  • zig fmt --check build.zig zig: clean. tools/pr_check.py: 0 errors.
  • zig build test test-golden -Dcpu=apple_m1: 880/880 steps, 13834 passed, 0 failed, 116 skipped (exit 0).
  • zig build test-kernel-contract: 210/210 passed.
  • zig build dev-tools -Dcpu=apple_m1: 268/268 steps (exit 0).
  • zig build lfm3-omni-generate -Doptimize=ReleaseFast -Dcpu=apple_m1: builds.

Not run, and why

  • Metal M1 to M4: no such hardware here. Gate 5 covers them through --offline compiles only. On chips without tensor units, products of many rows take the simdgroup-matrix kernels, which are registered and pass on the M5 but are untested on those chips and slow on long prompts.
  • Drafts, resume and concurrency contracts: n/a. The tool serves one request at a time outside the lane core (as Drama 3's does). Question 2 in LFM3-Omni-2B on Metal and CUDA: speech in, streamed text and speech out (gate and split) #1627 asks whether it should instead become a route of tensorfold-native serve.
  • The full-suite zig build kernel-contract on this head: it needs about an hour of GPU on an isolated machine, and this Mac's GPU is serving models.

From elsewhere

  • om_common.h's erf (for the exact GELU) uses the Chebyshev erfcc coefficients published in Numerical Recipes. Say if you'd rather have a different erf.
  • tools/lfm3_omni/score_replies.py loads UTMOS22 strong from tarepan/SpeechMOS v1.2.0 through torch.hub (a development tool, not engine code).

Checklist

  • A new GPU kernel is registered with the kernel contract; the Metal SUMMARY lines are above.
  • No precision traded for speed; bf16 rounding points follow the reference op for op.
  • Comments and docstrings are one line; no measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths.
  • Lane-round, drafted, resumed and concurrent contracts: n/a for this one-request tool; see LFM3-Omni-2B on Metal and CUDA: speech in, streamed text and speech out (gate and split) #1627 question 2.

@drowzeys

Copy link
Copy Markdown
Contributor Author

atc overlap --json (ATC 0.7.0) against main 3f0a715. Of 72 overlapping open PRs, four conflict, all where both sides append to a shared list:

None touches the same code. Each resolves by keeping both entries, whichever lands first. The rest report unknown because of ATC's pullFilesLimit, so I also ran git merge-tree against every open PR that merges cleanly with main: no further conflicts. #1627 is now claimed through ATC.

@ashhart

ashhart commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Thanks @drowzeys. This is a clean family: it's isolated, all 45 pipelines are under the contract with 69 controls red, and the contract caught a real NaN bug in om_attention_tiles, which is the point of it. A first audio frame in 0.063 s against the reference's 0.17-0.19 s is a great result.

Before we review it as ready, a few items from the gate we agreed on #1627: 1. Please rebase onto main. registry.zig, metal_main.zig and metal_limits.zig conflict on the lists that MiniMax M3 and moss_image added since. Keep both entries. 2. The fp32 column for every stage in the parity table (depth decoder and codec too, not only the encoder and prefill rows), and the four teacher-forced text misses listed with their margins. 3. The audio margins you hold to, stated, for example UTMOS22 median within 0.1 and WER within 1 point, with the receipt against them. 4. One text model's tokens before and after, to show no text family changed. 5. Streamed and whole replies should give the same audio. Please take the fix you offered: one product for every codec chunk size. 6. om_depth_pick: draw u in [0, 1) so h >> 40 == 2^24 - 1 can't map to 1. That moves sampled bytes, so please do it before the receipts.

On the log-mel front end: #1632 isn't on main yet, so keep your mel.zig for now. Whichever of the two lands second moves onto the other's. Then please mark it ready.

@ashhart

ashhart commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Hi @drowzeys, just checking in on LFM3-Omni. The family looks good, and that first audio frame time is still a great
result. What's left is the list from our 1 Nov note, starting with the rebase (the conflicts are only the shared record
lists in registry.zig, metal_main.zig and metal_limits.zig). If you'd like, we can do the rebase and push it to
your branch; say so here. No rush otherwise.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Hi @drowzeys, checking in once more on LFM3-Omni. It still looks good to us, and the list from our 1 Nov note is what's left, starting with the rebase. Our offer stands: if you'd like us to rebase it (the conflicts are only the shared record lists) and push it to your branch, say so here. And if your time's short, tell us which parts you'd like us to pick up.

…kHz speech out

A standalone family in Drama 3's shape: the four Liquid stacks of the bf16 release (speech
encoder and projector, LFM3 backbone, depth decoder, Liquid codec decoder) over one metallib,
the log-mel front end on the device, each codebook's pick on the GPU, and the codec streamed
between backbone rows. `zig build lfm3-omni-generate` makes one turn from a WAV, writes and
scores stage dumps against a reference's, and serves POST /v1/audio/chat (server-sent text
deltas and 16-bit 24 kHz audio) and GET /health, one request at a time. Products of many rows
take the tensor unit through the prefill GEMM's blocks; other chips a simdgroup-matrix product.
Host tests cover the mel front end, the prompt, the streamed overlap-add, the synthesis basis
and the Metal argument layouts.
…ts bf16 points, a control each

Registers all 45 pipelines of lfm3_omni.metallib (69 registrations over the stacks' variants) in
tf-kernel-contract: gates 1-4 against a float64 replay of each kernel's rounding points with the
spread its fp32 steps allow, stated rules for the picks and the word moves, and a planted source
change per registration. Gate 5 records the launches with their M1/M2 limits from --offline.
… weights' licence

tools/lfm3_omni holds the development clients behind the receipt: the 16 synthetic spoken turns,
the reference's stage dumps and spoken replies (transformers with the checkpoint's own code, on
CUDA, MPS or the CPU), the stage comparison and its table, a streaming client for
/v1/audio/chat, and the UTMOS and speech-vs-text scoring.
The codec took the few-row product for a one-frame chunk and the tiled product for longer ones,
and the tiled attention summed a row's keys from its tile's first window, so a streamed reply
and a whole decode differed in rounding. The codec's launches are now row-exact: the tiled
product for every row count, and attention one row a launch, so a row's sums depend on its
position alone. The backbone, the encoder and the depth decoder launch as before.
u was (float(h >> 40) + 0.5) / 2^24, and the fp32 sum rounds the largest draw up to 2^24, so
u = 1 and the Gumbel noise +Inf: that code was picked whatever its logit. u is now
float(h >> 40) / 2^24, exact in fp32 and below 1; a zero draw gives -Inf noise and is never
drawn. Sampled replies change; greedy output does not.

The contract's replay follows, and a third registration runs a seed whose draws reach both ends
of the 24-bit range, the largest on a codebook's smallest logit; its control restores the old
line and goes red.
The planted change dropped bf16(x + r), but the kernel reads x back rounded, so only the sum of
squares moved and the control went red at about half of the seeds. It now drops bf16(r rsqrt),
the control om_rmsnorm's residual registration uses.
…he two tokens

A teacher-forced run printed only its totals. It now also prints a line for each text slot it
picked differently: the slot, the reference's token, its own pick and its logits of both, so a
receipt can state every miss's margin.
UTMOS22 median within 0.1 of the reference's and speech-vs-text WER within 1 point, with the
gate's two precision bounds: every stage no further from an fp32 reference run than the
reference's own bf16 run, and every teacher-forced text miss within 2 bf16 ulps.
…text misses with their margins

reference_forced.py feeds the reference a dump's reply and scores its own picks, a frame at a
time as the engine's --force does; reference_codec.py runs the bundled codec in fp32;
reference_depth.py rounds the states it hands out to bf16 and scores two reference runs
against each other; precision_table.py prints every stage for the engine against the bf16 and
the fp32 reference and for the two references against each other; text_misses.py lists each
teacher-forced text miss with both sides' logits.
…io margins, chunked decodes, a text model's tokens

docs/receipts/lfm3-omni-metal holds the runs behind the recipe: the stage table with an fp32
column and the reference's own bf16-against-fp32 column, the four teacher-forced text misses
with their margins, UTMOS22 and WER against the stated margins, the codec's chunkings byte for
byte, and Qwen3.8-27B's tokens on main and on this branch. The recipe's tables follow it.
@drowzeys
drowzeys force-pushed the lfm3-omni-family-metal branch from 02fa671 to 8d01405 Compare November 16, 2026 02:10
@drowzeys

Copy link
Copy Markdown
Contributor Author

Thanks for your patience on this one. Rebased onto main (b4f1bf263) and worked through the 1 Nov list. Head is 8d0140505; the old head is kept on the fork as lfm3-omni-family-metal-pre-rebase. Receipts are in docs/receipts/lfm3-omni-metal/, and the description above is updated to match. It stays a draft because of point 2.

  1. Rebase. Both entries kept in the record lists (the omni records are one line in registry_joins.zig now). Main's lfm3 branch in metal_limits.zig took the lfm3 omni launch labels, so the labels and spec names are lfm3-omni …, as lfm3-dual and lfm3-image are; the filter is --only lfm3-omni. File.release takes its allocator. Two files of the PR had drifted from zig fmt; fixed. The rebase alone changes no output: 208 greedy dump files, 0 differ.
  2. fp32 column and text misses. The table has every stage against MPS bf16, against MPS fp32, and the reference's own bf16 against fp32. The four text misses are within 2 bf16 ulps by the reference's logits (0, 1, 1, 2). The fp32 bound is not met on every row. It holds for the step rows, the depth logits and the codes through the loop (86.8% against 86.4%). It does not hold for the encoder (0.999993 against 0.999994), the projector (0.999891 against 0.999920), the prefill rows (0.999881 against 0.999882), text top-1 (460/468 against 464/468), the depth decoder's greedy agreement (17126 against 17143 of 18540) and the codec (36.16 dB against 36.41 dB). Would you like these closed before review, or do you accept them as the bf16 noise of an independent sum order?
  3. Audio margins, written into the recipe before the runs: UTMOS22 median within 0.1 of the reference's and WER within 1 point. Measured: 4.427 against 4.438, and 1.47% against 1.20%. Both met.
  4. Text family. Qwen3.8-27B MLX 4-bit on main and on the branch, two prompts, 256 greedy tokens, 6 runs a side: token hashes equal (a10c9b848ed9, a06fab348fbe).
  5. Streamed and whole. One product for every chunk size was not enough: the tiled attention sums a row's keys from its tile's first window, so a row still depended on its chunk. The codec now takes the tiled product at every row count and attention one row a launch. Five chunkings of all 16 turns: 128 byte comparisons, 0 differ, on the tensor units and with LFM3_OMNI_NAX=0 (before: 128 of 128 differ). First audio 0.063 → 0.064 s, whole reply 0.644 → 0.655 s. Every stage before the codec is byte-identical to the previous head.
  6. om_depth_pick draws u = float(h >> 40) / 2^24, done before the receipts. A third registration runs a seed whose draws reach both ends of the 24 bits; its control restores the old line and goes red.

Also: om_rmsnorm_1k's residual control ("drops bf16(x + r)") went red at only about half of the seeds, because the kernel reads x back rounded; it now drops bf16(r rsqrt) and is red at every seed tried. mel.zig is kept, as #1632 isn't on main.

tf-kernel-contract --only lfm3-omni --offline DIR:
SUMMARY 70 kernels: 70 pass gates 1-4, 0 fail, 0 known findings; 70 controls: 70 red as planted, 0 missed; 0 limit problems

zig build test test-golden -Dcpu=apple_m1: 880/880 steps, 13834 passed, 0 failed, 116 skipped. test-kernel-contract: 210/210. dev-tools: 268/268. Lean: 337 on the base, 337 here, 0 new. zig fmt --check: clean.

Not run: the full-suite kernel-contract (this Mac's GPU is serving models) and Metal M1 to M4 beyond the --offline compiles. Setup: M5 Ultra, macOS 27.0.1, Xcode 27.2 with the Metal compiler 32023.921, Zig 0.17.0.

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @drowzeys for the rebase and for working through all six items. The streamed-equals-whole fix in the codec and the stronger om_rmsnorm_1k control are both good catches.

On your question: please close the six rows that miss the fp32 bar, rather than us accepting them as bf16 noise. The bar was set before the runs, and the project doesn't loosen a bar after seeing results.

A lead that may help: the engine's log-mel differs from the reference's by up to 3.1e-4. That difference reaches every later stage. If you feed each stage the reference's own inputs, you can see which stages really depart and which only inherit the mel difference.

Two smaller asks:

  1. For each row that still misses, please post the worst per-column differences, not just the summary number.
  2. Read LFM3_OMNI_NAX and LFM3_OMNI_PROFILE through platform/environment.zig, like the other environment settings.

Once those rows pass, it can come out of draft.

  • Synthena

This branch has not been deployed

No deployments
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