Skip to content

perf: reuse lfm3_audio backbone head and prefill block graphs - #1136

Merged
0xShug0 merged 1 commit into
0xShug0:mainfrom
Liquid4All:lfm3-backbone-graph-reuse
Oct 29, 2026
Merged

0xShug0 merged 1 commit into
0xShug0:mainfrom
Liquid4All:lfm3-backbone-graph-reuse

Conversation

@ykhrustalev

Copy link
Copy Markdown
Contributor

Problem
The lfm3_audio backbone built, planned and freed a new graph for the text head and for every prefill block (up to 256 rows) on each call. That host work costs 0.46-0.65 ms per block on an H100 and 0.26-0.32 ms on an M3 Ultra, even when the prompt length repeats.

Solution

  • Keeps the text-head graph and its 0.5 MiB buffer from first use; TTS never builds it
  • Keeps a prefill block's graph once the block runs twice in a row with the same rows at one cache capacity; other blocks build, run and drop theirs as before
  • Kept block graphs live in the existing prefill allocator and add no device memory; a buffer growth or a capacity change drops them
  • Logs lfm3_audio.backbone.prefill.built_blocks, the block graphs each prefill built

Testing

  • lfm3_audio_backbone_test on CUDA, Metal and CPU: a second logits() call, and 15 prefills of 100, 300 and 512 rows across a capacity change, match fresh runtimes bit for bit, and the timing log shows the block graphs each prefill builds. Clean under ASan (CPU); breaking any of the keep, reuse or drop rules fails it.
  • test_lfm3_audio_{parity,asr,tts,s2s} in F32 and Q8_0 on both hosts: stdout byte-identical to main's.
  • 3 identical requests per workload with LFM3_AUDIO_DUMP_DIR: the 3rd builds no block graph, and every dumped array, text and WAV is byte-identical to main's.

lfm3_audio.backbone.prefill.ms, Q8_0, main → this PR. Medians over 16 requests per side, 8 per size when alternating, and 4 (H100) or 6 (M3 Ultra) for the 418 s file:

Workload Block graphs built per request H100 M3 Ultra
ASR 7.5 s, same clip 1 → 0 10.17 → 9.68 31.38 → 31.02
ASR 90 s, same clip 5 → 0 59.74 → 58.28 226.69 → 225.20
S2S turn 1, same question 1 → 0 10.99 → 10.44 31.65 → 31.25
S2S turn 2, same history 2 → 0 22.66 → 21.91 76.76 → 76.17
ASR 418 s, fixed 30 s chunks, sum of 14 prefills 28 → 1 312.21 → 302.32 1149.15 → 1140.35
TTS, 8 different sentences 1 → 1 7.58 → 7.28 23.14 → 23.10
ASR 90 s, alternating with 7.5 s 5 → 5 62.60 → 61.48 229.44 → 229.66
S2S turn 2, alternating with turn 1 2 → 2 24.74 → 24.48 78.82 → 78.69
  • Request walls stay within noise. Streaming time to first audio for repeated S2S turns 1 and 2 drops 0.6 and 1.1 ms on the H100 (its server runs differ by up to 1.2 ms) and 0.4 and 0.5 ms on the M3 Ultra.
  • Over 60 requests with alternating sizes, memory stops growing by the 23rd request on both builds. This PR adds the head's 0.5 MiB of device memory, plus 4.2-4.7 MiB of peak footprint on the M3 Ultra where 5 block graphs are kept.
  • There is no gain where the cache capacity changes between requests, as it usually does between real S2S turns, or where block lengths rarely repeat.
build/bin/lfm3_audio_backbone_test --backend best
build/bin/audiocpp_cli --family lfm3_audio --model LFM3-Audio-2B-GGUF/LFM3-Audio-2B-Q8_0.gguf \
  --task asr --batch-audio-dir clips --log-file run.log   # prefill.ms and prefill.built_blocks per request

Refs #1119

The text head and every prefill block graph were built and allocated
on each call. The runtime now keeps the head graph, and a block's graph
once the block repeats its row count at one cache capacity, so prompts
of a repeated length save 0.3-0.5 ms per block; outputs do not change.
@0xShug0 0xShug0 added the ready label Oct 29, 2026
@0xShug0
0xShug0 merged commit aeb7bcf into 0xShug0:main Oct 29, 2026
7 checks passed
@0xShug0

0xShug0 commented Oct 29, 2026

Copy link
Copy Markdown
Owner

@ykhrustalev Thanks! All 3 PRs merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants