Skip to content

feat(lfm2_audio): text_temperature and text_top_k for S2S - #827

Merged
0xShug0 merged 3 commits into
0xShug0:mainfrom
Liquid4All:lfm2-audio-s2s-text-sampling
Oct 7, 2026
Merged

0xShug0 merged 3 commits into
0xShug0:mainfrom
Liquid4All:lfm2-audio-s2s-text-sampling

Conversation

@ykhrustalev

Copy link
Copy Markdown
Contributor

Optional S2S text sampling for lfm2_audio, as in liquid-audio. The default stays greedy.

Problem

  • S2S text is always greedy. liquid-audio's generate_interleaved takes text_temperature and text_top_k; the session refused them, though both server runtimes forward them from the live route's query
  • With Q4_0 a few S2S replies repeat text until max_tokens, which the docs said only in Validation, not where a user picks a package

What this PR changes

  • S2S request options text_temperature and text_top_k, default 0, with liquid-audio's _sample_text_token rule: greedy when the temperature is at most 0 or top_k is 1; otherwise divide by the temperature, keep the logits at or above the k-th (ties kept), softmax and draw. top_k 0 keeps all. Without the options, lfm2_greedy runs as before
  • Text draws use their own stream, from a fixed splitmix64 mix of the request seed, and the audio stream is unchanged: with one seed, a sampled reply is step for step the greedy one, audio codes included, until a text token differs. liquid-audio shares one stream, but a seed here does not reproduce its draws anyway
  • Sampled text rejects NaN and infinite logits, as greedy text does
  • Negative values are refused with the session's error. ASR and TTS refuse both options
  • Spec entries and docs. The Run section recommends Q8_0 (the default) or F16 for S2S
  • The last commit only rebuilds the WebUI page for the specs. Main's committed page predates Reduce Qwen3-TTS, IndexTTS, and BreezeTTS memory allocations #821, which changed three TTS specs (breeze_tts, index_tts2, qwen3_tts) without a rebuild, so those come in too; built from the sources before Reduce Qwen3-TTS, IndexTTS, and BreezeTTS memory allocations #821, main's page comes out byte for byte as committed

What changes for users

  • Nothing without the options
  • Sampled text changes the wording, sometimes the content. On Q4_0, round-trip ASR WER medians were 0.057 to 0.083 against 0.040 greedy, so the docs make no quality claim. With text_top_k 0 even control tokens can be drawn
  • On Q4_0, sampling made loops rarer but not gone, so the docs recommend a package, not a setting. Replies to c.wav that ran to max_tokens (1024) repeating text, seeds 1 to 100 unless shown:
Backend Greedy 0.7, top-k 50 0.7, top-k 40
CUDA 4 0 0 of 30
x86 CPU, 4 threads 2 0
M3 Ultra CPU, 4 threads 6 0 of 30 1
M3 Ultra CPU, 16 threads 0 of 30 1 of 30
Metal 0 0 of 30 0

Q8_0 and F16 on CUDA: none in 30, greedy or at 0.7, top-k 50.

Testing
The checks ran on main a08c7af. The branch is now on a1c24b2: #821 and #822 do not touch lfm2_audio, and #821's spec changes reach only the rebuilt page.
On this branch:

  • New checks in lfm2_audio_tts_test and lfm2_audio_session_test. On main the first does not build and the second fails. The non-finite check fails on an earlier version of these commits
  • The lfm2_audio unit tests and model_spec_system_test pass on Linux (CPU and CUDA builds) and an M3 Ultra (Metal). The S2S model test passes (F16 and Q4_0 on CUDA and Metal, F16 on both CPUs), and the TTS model test with F16 on CUDA and Metal
  • CLI, several requests per process, EN F16 and Q4_0 on CUDA and Metal, EN Q4_0 on the Linux CPU: 59 of 59 offline replies and 10 of 10 streams, default and sampled, are byte-identical to the earlier version. The default ones match main (21 replies, 5 streams). Sampled replies repeat, stream their offline text, and text_top_k=1 gives the default reply. 4 of 4 seeded TTS WAVs on CUDA match main
  • Live route on CUDA, both runtimes: text.done equals the CLI's text, default and sampled, and negative values return the session's error. With a full-length upload a client may get a connection reset instead, as for any early error on this route (4 to 7 of 10 got the event on the Mac)

On that earlier version, which lacked only the non-finite check:

  • Default S2S matched main in 340 offline replies and 37 streams (EN and JP; CUDA, Metal and both CPUs) and 8 live-route requests on Metal
  • In 253 sampled replies, the first difference from the greedy reply of the same seed was always a text step. All 65 JP replies among them shared at least one full audio block first

Build and run

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DENGINE_BUILD_TESTS=ON \
  -DAUDIOCPP_MODEL_SET=custom -DAUDIOCPP_MODELS=lfm2_audio
ninja -C build audiocpp_cli lfm2_audio_tts_test && ./build/bin/lfm2_audio_tts_test
./build/bin/audiocpp_cli --task s2s --family lfm2_audio --model models/LFM2.5-Audio-1.5B-GGUF \
  --audio question.wav --out reply.wav --request-option seed=1 \
  --request-option text_temperature=0.7 --request-option text_top_k=50

With the Q4_0 package, a few S2S replies repeat a sentence until
max_tokens: 2 of 30 replies to one English question on CUDA and 2 of 30
on the M3 Ultra CPU, 2 of 60 on the x86 CPU and none on Metal, while F16
and Q8_0 had none. The Validation section has these numbers, but the
Run section, where a user picks a package, did not say so. Point S2S
users at the Q8_0 package, the default, or F16 there.
S2S text was always greedy. liquid-audio's generate_interleaved takes
text_temperature and text_top_k next to the audio sampling arguments,
and its _sample_text_token is greedy when the temperature is at most 0
or top_k is 1; otherwise it divides the logits by the temperature, keeps
those at or above the k-th, applies softmax and draws. Add the two S2S
request options with that rule, through the sampler the audio codes
already use. Both default to 0, so text stays greedy as in
liquid-audio's README and demo, and a request without them goes through
the same lfm2_greedy call as before. Sampled text first checks its
logits for NaN and infinity, as lfm2_greedy does, since the sampler
would leave them out and draw from the rest.

Text draws take a stream of their own, seeded from a fixed splitmix64
mix of the request seed, and the audio stream is the one it was. So with
the same seed, a reply with sampled text is step for step the
greedy-text reply, audio codes included, until a text token differs.
liquid-audio draws both from torch's one stream, but a seed here does
not reproduce its draws anyway.

ASR and TTS reject the options. The spec lists them, and the docs add
the option rows and the seed contract and say that the live route takes
them in the query, which both server runtimes already forward.

The TTS unit test checks the greedy rule on random logits, a tie at the
k-th logit, the temperature on two logits, that sampled text rejects
non-finite logits, and the separate streams; the session unit test
checks that ASR rejects the options. On main the first does not build
and the second fails. The S2S model test checks the step-for-step
contract at three seeds, that text_top_k=1 gives the greedy reply and
the rejections; the TTS model test checks the rejection.

The lfm2_audio unit tests and model_spec_system pass on Linux CPU and
CUDA builds (gcc 12) and a macOS Metal build. The S2S model test passes
with the F16 and Q4_0 packages on CUDA and Metal and with F16 on the
CPU, and the TTS model test with F16 on CUDA and Metal. Without the
options, S2S replies through the CLI are byte for byte main's, text and
WAV: 21 offline replies and 5 streams over the EN F16 and Q4_0 packages
on CUDA and Metal and EN Q4_0 on the CPU, several requests per process.
With text_temperature=0.7 and text_top_k=50, a seeded reply repeats in
the same process and streams the text it gives offline, and text_top_k=1
gives the default reply. On the server's live route on CUDA, both
runtimes pass the options on: the sampled reply's text is the CLI's for
the same seed, and a negative value comes back as the session's error.
The page audiocpp_server serves embeds model_specs, so it is rebuilt
with npm ci and npm run build in webui/native for the two new lfm2_audio
request options and the longer seed description. Main's committed page
predates 0xShug0#821, which changed the breeze_tts, index_tts2 and qwen3_tts
specs without rebuilding it, so those changes come in too: built from
the sources before 0xShug0#821, main's page comes out byte for byte as
committed. Built from this commit's sources, the page differs from a
build of main's sources only in those lfm2_audio spec entries and in the
bundle file name its imports use.
@0xShug0
0xShug0 merged commit af88bd1 into 0xShug0:main Oct 7, 2026
6 checks passed
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