Skip to content

feat(nemotron_voicechat): cache-aware online session with frame events - #2039

Merged
inureyes merged 4 commits into
mainfrom
feature/issue-1378-voicechat-streaming
Sep 29, 2026
Merged

inureyes merged 4 commits into
mainfrom
feature/issue-1378-voicechat-streaming

Conversation

@inureyes

@inureyes inureyes commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds the cache-aware online Nemotron VoiceChat session. VoiceChatStreamingSession accepts PCM chunks of any size and buffers them into 1280-sample (80 ms) frames. Each frame advances every network exactly once from persistent state, and the session emits frame-aligned events. mlxcel generate --audio ... --stream [--profile] drives it from the CLI. This session is also the library surface the /v1/realtime endpoint (#1376) builds on.

What changed

  • Streaming perception: StreamingLogMel (bounded sample tail, frames emitted once they trail the input by 1280 samples) and ConformerStreamingState. The Conformer state keeps per-layer attention (70) and conv (8) caches plus a 16-frame mel cache for incremental causal subsampling, adds stream entry points on the attention and block types, and provides RnntStreamState for transcript deltas. None of this changes the offline numerics.
  • Session: models::nemotron_voicechat::streaming.
    • create_streaming_session(StreamingOptions) seeds the RNG, warms EAR-TTS, and prefills the system prompt without emitting events.
    • push_audio / flush(pad_partial) / cancel follow the issue's semantics, and max_streaming_seconds raises ContextLimit.
    • Events: AssistantTextDelta, FunctionDelta, UserTranscriptDelta, Audio (exactly 1764 samples plus the 31 codes), Done, Cancelled. The text delta rule is the reference's.
    • Codec streaming uses the feat(nemotron_voicechat): load the VoiceChat checkpoint and run offline duplex inference (FastConformer+RNNT, Nemotron-H dual-head, EAR-TTS, codec) #1374 decode_step with CausalConv1dCache.
    • Language and perception caches can be disabled for diagnostics.
    • Each session owns fresh Nemotron-H caches, so two sessions created back to back on one model do not share state.
  • Profiler: per-frame perception, rnnt, language, tts, codec, total timings, each taken after forcing evaluation. summary(drop_first) gives mean/p50/p95/max, frames per second, and the real-time factor.
  • CLI: --stream, --max-streaming-seconds, and --profile (prints the summary JSON after dropping 5 cold frames).
  • Docs: an online-session section in docs/nemotron-voicechat.md covering cache families, events, switches, profiler and CLI. The performance table keeps its marked placeholder.

Validation

All checks ran on the real 4-bit checkpoint.

  • Offline vs streaming (tests/nemotron_voicechat_streaming_real.rs):
    • The first audio frame's text id, function id, and 31 codes equal the offline path.
    • All 61 streamed frames have identical text ids and identical codes. The offline run has 62 frames because its centered mel adds one tail frame.
    • The streamed assistant text equals the offline text ("The capital of France is Paris.").
    • Pushing in 777-sample chunks gives identical events to 1280-sample chunks.
    • Every audio event is 1764 samples with contiguous frame indices, and a closed session rejects pushes.
  • Streaming perception vs the Python reference's streaming path (tests/nemotron_voicechat_stream_real.rs):
    • Encoder max abs 1.1e-6.
    • The transcript deltas match frame for frame.
  • CLI: --stream writes 61 x 1764 samples, and two seeded runs are byte-identical. --max-streaming-seconds 1 stops with the context-limit error.
  • Unit tests: chunk-boundary buffering (300/1000/1280/2000 samples give 0/1/1/1 frames, and flush-with-pad gives one more), flush without padding, the token delta rule including a revised multibyte token, profiler percentiles, streaming mel vs offline, 8 mel frames giving one encoder frame, and the RNNT stream delta rule.
  • Local gate: fmt, clippy (lib+tests), the unit tests above, cli_help_consistency, dead_doc_pointers, llama_compat_manifest. GitHub CI was not awaited (the self-hosted runner is down).

The profiler runs and prints finite numbers, but no latency or real-time-factor figures were recorded, because the GPU was shared with other jobs during this run. The measured real-time factor for the 4-bit and 8-bit checkpoints is deferred to the orchestrator and goes into the marked placeholder table in docs/nemotron-voicechat.md.

Deviations from the issue body (the reference wins)

  • Streamed vs offline encoder frames: they match for the first frames and then drift slightly (max 0.33). The reference's cache-aware subsampling window is not the offline full-utterance convolution, and the Python reference shows the same gap. The port keeps the reference rule, so "streamed encoder matches offline within 1e-3" holds only for the leading frames. The tokens and codes downstream still match offline exactly on the test input.
  • Streamed transcript: it has no trailing "?", same as the reference streaming path.
  • Streaming log-mel push: returns an MLX array. push_values gives the host Vec<f32> form.
  • LLM state: each session owns fresh Nemotron-H caches instead of taking a SequenceId in ModelOwnedSequenceState. This gives the same isolation without touching the scheduler state.

Changes during review

  • push_audio now releases one frame at a time, so frames behind a failing frame (context limit, inference error) stay buffered as in the reference; the buffer is linear in the chunk size. The push/flush/cancel contract moved into a model-free InputLifecycle with always-on unit tests for chunk boundaries (0/1/1/1 then one padded frame), closed-session rejection, idempotent close, and the failing-frame case.
  • Not changed: RelPositionMultiHeadAttention::stream shares its body with forward only by duplication; a later refactor can fold both into one helper without changing numerics.

Closes #1378

@inureyes inureyes added status:review Under review type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:models Model architectures, weights, loading, metadata area:inference Generation, sampling, decoding (incl. speculative, DRY) area:docs User and developer documentation labels Sep 29, 2026
Port the reference streaming front end so a session can advance speech perception one 80 ms frame at a time with bounded state (issue #1378).

StreamingLogMel (audio/nemotron_mel_stream.rs) ports StreamingLogMelSpectrogram: hop-aligned frames are emitted once their centers trail the input by lookahead_samples, only two hops of look-behind stay buffered, and each frame reuses NemotronMelFrontend::frame_into, so joined outputs equal the offline log-mel.

ConformerStreamingState (audio/fastconformer/streaming.rs) ports the reference ConformerStreamingState and _stream_block: per-layer attention caches (last left_context inputs) and causal-conv caches (last kernel-1 GLU frames), incremental subsampling over a 16-frame mel cache, and materialize() to evaluate outputs and caches each step. RelPositionMultiHeadAttention::stream and ConformerBlock::stream are new methods; the offline forward is unchanged.

RnntStreamState (audio/rnnt/stream.rs) ports _RNNTState with the reference delta rule.

Validated with unit tests on random weights and tests/nemotron_voicechat_stream_real.rs against a reference streaming dump: encoder rms diff 4.6e-8, identical streamed transcript and per-frame deltas.

Refs #1378
Add VoiceChatStreamingSession: PCM chunks of any size are buffered into 1280-sample frames and each frame advances the streaming log-mel, the cache-aware FastConformer, the RNNT state, the Nemotron-H caches, EAR-TTS and the codec decode_step exactly once, emitting frame-aligned text, function, transcript and 1764-sample audio events. The system prompt is prefilled at creation without events; flush pads the partial frame and emits Done, cancel emits Cancelled, and max_streaming_seconds bounds a session. Language and perception caches can be disabled for diagnostics, and an optional profiler records per-stage timings with p50/p95 and the real-time factor.

mlxcel generate --stream drives the session in 80 ms frames, prints deltas as they arrive, and with --profile prints the summary; --max-streaming-seconds maps to the session limit.

Refs #1378
…fails

push_audio drained every complete frame before running any, so a context-limit or inference error on one frame dropped the frames behind it; the reference pops one frame per iteration. The frame buffer now releases one frame at a time with a read offset (linear in the chunk size), and the push/flush/cancel contract lives in a model-free InputLifecycle so chunk boundaries, closed-session rejection, idempotent close, and the failing-frame case are unit tested without a checkpoint.

Refs #1378
@inureyes
inureyes force-pushed the feature/issue-1378-voicechat-streaming branch from 3a9f747 to 812a357 Compare September 29, 2026 12:17
@inureyes inureyes added status:done Completed and removed status:review Under review labels Sep 29, 2026
@inureyes
inureyes merged commit 802102f into main Sep 29, 2026
10 of 11 checks passed
@inureyes
inureyes deleted the feature/issue-1378-voicechat-streaming branch September 29, 2026 12:18
inureyes added a commit that referenced this pull request Sep 29, 2026
#2044)

## Summary

Fills the Performance table in `docs/nemotron-voicechat.md`, which PRs #2037, #2039 and #2041 left as TBD because their measurements ran while other units shared the GPU. Epic #1372's definition of done asks for the measured real-time factor for the 4-bit and 8-bit checkpoints.

## Measurement

- Machine: Apple M1 Ultra (128 GB), Metal, otherwise idle (no builds, servers or other model runs).
- Command: `mlxcel generate -m <ckpt> --audio question.wav --stream --profile --seed 0` on main `38eaaee6`, with the "What is the capital of France?" prompt and 3 s of extra decoding (56 frames, first 5 dropped as cold).
- One warm-up run, then three measured runs per checkpoint.

| Checkpoint | Real-time factor (3 runs) | Frame time p50 | Frame time p95 |
|---|---|---|---|
| 4-bit | 1.039, 1.039, 1.037 | 82.7 to 82.8 ms | 83.8 to 84.0 ms |
| 8-bit | 1.119, 1.122, 1.119 | 89.3 to 89.4 ms | 90.4 to 91.0 ms |

`realtime_factor` is mean per-frame processing time divided by the 80 ms frame, so values above 1.0 mean slower than real time. Neither checkpoint keeps up on this machine. The doc states that plainly and gives the per-stage breakdown (TTS 36 ms is the largest stage).

## Changes

- `docs/nemotron-voicechat.md`: replace the TBD rows with the measured values, the method, and the per-stage breakdown.

Documentation only.
@inureyes inureyes added this to the 0.8 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs User and developer documentation area:inference Generation, sampling, decoding (incl. speculative, DRY) area:models Model architectures, weights, loading, metadata priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(nemotron_voicechat): cache-aware online session (80 ms frame clock, persistent caches, aligned events, profiler)

1 participant