Skip to content

nemotron_3_diar: write speaker probabilities as safetensors - #686

Merged
0xShug0 merged 2 commits into
0xShug0:mainfrom
LysanderdeJong:feature/nemotron-3-diar-safetensors
Sep 25, 2026
Merged

0xShug0 merged 2 commits into
0xShug0:mainfrom
LysanderdeJong:feature/nemotron-3-diar-safetensors

Conversation

@LysanderdeJong

@LysanderdeJong LysanderdeJong commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • return_frame_probabilities writes speaker_probabilities.safetensors instead of raw .f32, with the diarizer's streaming geometry as metadata
  • add asr_la0/asr_la3/asr_la6/asr_la13 latency profiles that match Nemotron ASR's chunking at that lookahead
  • add engine::io::encode_safetensors() (in-memory, with __metadata__ support); it shares the header builder with write_safetensors_file(), which still streams to disk

Second of three stacked PRs split from #681; #685 (the first) is merged.

Why

The next PR runs NeMo's masked multitalker ASR from this file. That needs the diarizer's geometry: NeMo diarizes in ASR-sized chunks (chunk = lookahead + 1, no right context), and a mask from another geometry is not what the model was trained with. Raw .f32 carries no metadata.

Changes

  • The file holds one F32 tensor speaker_probabilities [frames, 8] and string metadata: format_version, source_family, frames, speakers, frame_hop_samples, sample_rate, latency_profile, spkcache_len, fifo_len, chunk_len, chunk_right_context, spkcache_update_period.
  • asr_laN sets spkcache 264, FIFO 264, chunk N + 1, right context 0, update period 222, as NeMo's configure_diar_streaming does.
  • Docs and spec list the new profiles and file format.

Maintainer notes

Validation

  • the tensor is bit-identical to the old .f32 for the same run
  • nemotron_3_diar_streaming_test covers the asr_laN geometry and reads the bytes back through load_safetensors_index; the Hugging Face safetensors package reads the file
  • existing write_safetensors_file() callers produce identical files

@0xShug0

0xShug0 commented Sep 25, 2026

Copy link
Copy Markdown
Owner

@LysanderdeJong Could you elaborate on why you changed the direct-to-disk behavior of write_safetensors_file()? Routing it through the in-memory encoder adds unnecessary full-file buffering and copies.

return_frame_probabilities now writes speaker_probabilities.safetensors:
one F32 [frames, 8] tensor plus string metadata recording the source
family, frame hop, sample rate, latency profile and streaming geometry.
The framework gains encode_safetensors() with __metadata__ support;
write_safetensors_file() now uses it.

Add asr_la0/3/6/13 latency profiles (chunk_len = N + 1, no right
context), which match the chunking of Nemotron ASR at lookahead N so a
downstream ASR can reproduce NeMo's multitalker speaker masks.
Share only the header builder with encode_safetensors(); the file writer
again writes the header and tensor data straight to the stream instead of
buffering the whole file in memory first. encode_safetensors() now builds
its vector in one reserved allocation.
@LysanderdeJong

Copy link
Copy Markdown
Contributor Author

Good catch, that was an unintended regression from a refactor. I only wanted to share the header code. Fixed in 3431e1a: write_safetensors_file() writes directly to disk again, and only the header builder is shared. The in-memory encode_safetensors() is used only for the diarizer artifact, which has to be in memory anyway, and it now builds its buffer in one allocation. Output files are byte-identical.

@LysanderdeJong
LysanderdeJong force-pushed the feature/nemotron-3-diar-safetensors branch from 50e8732 to 3431e1a Compare September 25, 2026 17:57
@0xShug0
0xShug0 merged commit e79205f into 0xShug0:main Sep 25, 2026
6 checks passed
@LysanderdeJong
LysanderdeJong deleted the feature/nemotron-3-diar-safetensors branch September 25, 2026 20:35
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