Skip to content

mtmd : add Nemotron 3 Nano Omni support (parakeet) - #22520

Merged
ngxson merged 42 commits into
ggml-org:masterfrom
danbev:nemotron-3-omni-mtmd-audio
Jul 28, 2026
Merged

ngxson merged 42 commits into
ggml-org:masterfrom
danbev:nemotron-3-omni-mtmd-audio

Conversation

@danbev

@danbev danbev commented Apr 29, 2026 •

Copy link
Copy Markdown
Member

Overview

This commit adds support for the subsampling and encoder part of Nemotron Nemo 3 omni model.

Additional information

The Parakeet subsampling/encoder were taken from parakeet.cpp which is currently a pull request against whisper.cpp. I've tried to copy the code as close as possible to hopefully enable easy patching between these two project later.

Refs: ggml-org/whisper.cpp#3735


For testing a converted model can be found here and can be run using the following command:

llama-mtmd-cli -hf danbev/Nemotron-3-Nano-Omni-30B-A3B-Reasoning-BF16-mtmd-GGUF --no-warmup --audio jfk.wav -p "Transcribe this audio clip, only the trancription and nothing else."

This commit adds support for the subsampling and encoder part of
Nemotron Nemo 3 omni model.

The Parakeet subsampling/encoder were taken from parakeet.cpp which
is currently a pull request against whisper.cpp. I've tried to copy the
code a close as possible to hopefully enable easy patching between the
these two project later.

Refs: ggml-org/whisper.cpp#3735

@ngxson ngxson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, I'm leaving some early-review comments

Comment thread convert_hf_to_gguf.py Resolved
Comment thread tools/mtmd/mtmd-audio.cpp Resolved
@github-actions github-actions Bot added examples python python script changes labels Apr 29, 2026
This commit removes the generation of the relative positional tensor in
the model conversion script and instead computes it in the encoder
graph. This is only done for the window of positions required for the
current audio sample.
Comment thread tools/mtmd/clip.h Resolved
Comment thread tools/mtmd/mtmd-audio.cpp Resolved
danbev added 2 commits April 30, 2026 14:50
This commit adds a function to get access to the clip_model. It also
removes the two functions clip_get_mel_filter_tensor, and
clip_get_window_tensor(const struct clip_ctx * ctx) which can now use
clip_get_model to access the model tensors that it needs.

@ngxson ngxson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good so far

Comment thread tools/mtmd/mtmd-audio.cpp Resolved
Comment thread tools/mtmd/clip.cpp Resolved
@danbev danbev self-assigned this Jun 2, 2026
danbev added 5 commits June 4, 2026 12:50
This commit updates the parakeet code in mtmd to reflect the latest
updates to parakeet.cpp in whisper.cpp.

A follow up commit will address the currently hardcoded dw_pad and see
if we can add n_conv_kernel as a model metadata field.
This commit updates the model conversion to read the conv_kernel_size
field from the sound_config section of the models config.json file.
It then uses this field instead of the hardcoded values in parakeet.cpp.
@github-actions github-actions Bot added mtmd Related to multimodal functionality (video/image/audio) conversion labels Jul 27, 2026
@ngxson

ngxson commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

/bot review

@ggml-gh-bot

ggml-gh-bot Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Automated code review

Code review: mtmd — add Nemotron 3 Nano Omni (parakeet) audio support

Checklists run: scope/quick-reject, security, general, new model (multimodal/tools/mtmd/), and approach/design (new end-to-end audio encoder + preprocessor).

Overall the diff is well-structured and follows existing mtmd conventions (tensor_mapping.py entries, projector enum wiring, clip_graph_* registration, preprocessor subclass). The main concern is a correctness bug in the attention mask path.

Blocking

(point 1) Hardcoded attention-mask token count (tools/mtmd/clip.cpp:4676).

const int n_tokens_real = (1101 + hparams.subsampling_factor-1) / hparams.subsampling_factor;

1101 is an input-length magic constant with no comment. It is only correct when the input mel produces exactly 1101/subsampling_factor real encoder tokens; an audio clip of any other length hits the wrong path:

  • For audio longer than that reference length, n_k == n_q full-attention branch will mask real keys (k >= n_tokens_real), silently truncating attention to the first n_tokens_real tokens and attending only to padding for the rest.
  • The preprocessor (mtmd_audio_preprocessor_parakeet::preprocess) computes n_len dynamically from n_samples_in; nothing pads/truncates to a fixed frame count. So this constant does not reflect reality.

n_tokens_real must be derived from the actual number of real frames (e.g. the preprocessor already computes valid_frames = n_samples_in / frame_step; expose it as n_len_org/a metadata field and map it through the conv subsampling), not from a constant. If there is a real reason the input is expected to be a fixed length, that invariant must be enforced (and a comment added), but right now it is neither enforced nor explained.

(point 2) subsampling_factor is used inconsistently with the conv stack. build() in models/parakeet.cpp hardcodes conv strides (layers 0/2/5 → total stride 8), while clip_n_output_tokens (clip.cpp:3754) reports n_patches = img->nx() / subsampling_factor and the mask uses 1101 / subsampling_factor. If the config subsampling_factor is ever != 8, the LLM is told a token count that does not match the encoder's actual output length and the mask logic is wrong. Either derive the subsampling factor from the conv configuration or assert/guard that it equals the real stride. Please document the relationship.

Will slow the review

(point 3) Dead fields. struct clip_layer::attn_pos_w (clip-model.h:265) and clip_model::mm_norm_w (clip-model.h:609) are declared but never assigned or read anywhere (grep confirms only the declaration). The parakeet build uses mm_norm_pre_w, not mm_norm_w. Remove both.

(point 4) Normalization degenerates on short input (mtmd-audio.cpp:1210-1232).

int valid_frames = n_samples_in / frame_step;          // 0 when < 160 samples
double mean = sum / valid_frames;                      // /0
double std_dev = std::sqrt(sq_diff_sum / (valid_frames - 1.0));  // sqrt(<0) when 1 frame

For audio shorter than one hop (or one hop+1 frame) this produces NaN/inf and corrupts the whole mel buffer. Guard valid_frames >= 2 (and ideally reuse the existing n_len <= 0 early-return pattern from other preprocessors).

(point 5) Unrelated, behavior-changing edit bundled in (conversion/nemotron.py, tensor_force_quant). The old code forced .position_embd. / pos_embed tensors to F32; that branch is deleted in this PR, so the RADIO vision pos-embed will now be quantized with the default ftype (F16/BF16). This affects the existing Nemotron-V2-VL/RADIO vision path, not the audio feature. If intentional, please confirm the C++ loader/build tolerates a non-F32 pos-embed; otherwise restore the F32 force. Keeping it as part of the audio PR also makes this a non-single-purpose change.

(point 6) Conversion ties vision+audio projector metadata to the audio branch (conversion/nemotron.py:42-66). if self.hparams_audio is not None: sets has_vision_encoder = True and emits add_clip_vision_projector_type(NEMOTRON_V2_VL). Vision-encoder presence should be gated on the vision config, not implied by the audio config. For an audio-only mmproj this writes misleading metadata. Confirm intent or gate each modality on its own config.

Nits

(point 7) models/parakeet.cpp:3-4 — alignment-by-extra-spaces (PARAKEET_LOCAL_ATTN_WINDOW = 128 padded) and the if (n_threads == 1) block in mtmd-audio.cpp:1160 are dead since n_threads = 4 is const. Drop the unused branch, or thread the thread count through like other preprocessors do.

(point 8) Magic constants without comments: 5.960464477539063e-08 in mtmd-audio.cpp and the 1101 (point 1). Name them or add a one-line rationale.

(point 9) models/parakeet.cpp — minor: cb(cur, "pre_conv_5_direct", -1) then cb(cur, "pre_conv_5", -1) on consecutive identical tensors; the first looks like leftover debug tagging. Trim if not needed.

(point 10) The per-mel-vector inner loop in the preprocessor (0..n_fb-3 step 4) hand-unrolls the mel-filter dot product; existing whisper/conformer preprocessors do the same style, so it is consistent, but a short comment explaining the 4-wide unroll would help future readers.

This review was generated automatically by pi coding agent using zai-org/GLM-5.2. It may contain mistakes. Maintainers make the final call.

@ngxson

ngxson commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

I think points 1-3 are worth addressing, the rest is optional

danbev and others added 5 commits July 28, 2026 14:04
This commit adds an assert of the parakeet subsampling factor to check
that it is 8.

The motivation for this is that this model currently has three
convolutions with a stride of 2. If the underlying model updates the
subsampling factor these convolution operations will need to be updated
and this will produce and error if this occurs.
This commit removes the single thread path which was a left over from
the original parakeet.cpp where n_threads is configurable.
@ngxson
ngxson merged commit 7e1e28c into ggml-org:master Jul 28, 2026
23 of 28 checks passed
@danbev
danbev deleted the nemotron-3-omni-mtmd-audio branch July 29, 2026 05:39
@Green-Sky

Copy link
Copy Markdown
Collaborator

@danbev https://huggingface.co/ggml-org/NVIDIA-Nemotron-3-Nano-Omni needs updating

@ggerganov

Copy link
Copy Markdown
Member

@danbev https://huggingface.co/ggml-org/NVIDIA-Nemotron-3-Nano-Omni needs updating

We can add it to https://github.com/ggml-org/convert

@danbev

danbev commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

We have updated the model now and it can be found here:
https://huggingface.co/ggml-org/NVIDIA-Nemotron-3-Nano-Omni-30B-A3B-GGUF

Note the change of the model repository and the model files which was done as I had not been consistent with them unfortunately.

huaxel pushed a commit to huaxel/strix-llama.cpp that referenced this pull request Aug 2, 2026
* mtmd : add Nemotron 3 Nano Omni support (parakeet)

This commit adds support for the subsampling and encoder part of
Nemotron Nemo 3 omni model.

The Parakeet subsampling/encoder were taken from parakeet.cpp which
is currently a pull request against whisper.cpp. I've tried to copy the
code a close as possible to hopefully enable easy patching between the
these two project later.

Refs: ggml-org/whisper.cpp#3735

* mtmd : generate rel pos tensor in graph instead of in conversion [no ci]

This commit removes the generation of the relative positional tensor in
the model conversion script and instead computes it in the encoder
graph. This is only done for the window of positions required for the
current audio sample.

* mtmd : add clip_get_model to clip API [no ci]

This commit adds a function to get access to the clip_model. It also
removes the two functions clip_get_mel_filter_tensor, and
clip_get_window_tensor(const struct clip_ctx * ctx) which can now use
clip_get_model to access the model tensors that it needs.

* mtmd : read mel_filters and window into hparams

* mtmd : use set_input_f32 lambda [no ci]

* mtmd : add better asserts for mel_filters and hann window [no ci]

* mtmd : add missing size_t cast

* mtmd : change type of pad to size_t

* mtmd : zero initialize samples_padded

* mtmd : remove unsued ctx member from parakeet preprocessor

* mtmd : make log_mel_spectrogram_parakeet_worker_thread private static

* mtmd : sync/update parakeeet impl with latest whisper.cpp

This commit updates the parakeet code in mtmd to reflect the latest
updates to parakeet.cpp in whisper.cpp.

A follow up commit will address the currently hardcoded dw_pad and see
if we can add n_conv_kernel as a model metadata field.

* mtmd : add audio_conv_kernel_size to model conversion

This commit updates the model conversion to read the conv_kernel_size
field from the sound_config section of the models config.json file.
It then uses this field instead of the hardcoded values in parakeet.cpp.

* mtmd : cleanup [no ci]

* conversion : call super().filter_tensors [no ci]

* do not discard result of super filter_tensors

* mtmd : use build_mm instead of ggml_mul_mat

* mtmd : use build_ffn

* mtmd : move and reuse get_vector lambda

* mtmd : use build_inp_raw for parakeet

* mtmd : throw exception in get_scalar instead of assert

* mtmd : fix std::min call

* mtmt : use .c_str in throw clause in get_vector

* mtmd : check for F32 type and non-empty tensor in get_vector

The get_vector lambda is used by get_scalar but also standalone to read
in the mel_filters and the window data. Therefor we are not checking
for 1D tensors but allowing multiple dimensions. We do have a check in
get_scalar to verify the size of the vector.

* mtmd : replace hardcoded 1101 for n_tokens_real

* mtmd : assert subsampling_factor is 8

This commit adds an assert of the parakeet subsampling factor to check
that it is 8.

The motivation for this is that this model currently has three
convolutions with a stride of 2. If the underlying model updates the
subsampling factor these convolution operations will need to be updated
and this will produce and error if this occurs.

* mtmd : remove unused ggml_tensors attn_pos_w and mm_norm_w

* mtmd : remove single thread path

This commit removes the single thread path which was a left over from
the original parakeet.cpp where n_threads is configurable.

* fix some security issues

---------

Co-authored-by: Sigbjørn Skjæret <[email protected]>
Co-authored-by: Xuan Son Nguyen <[email protected]>
satindergrewal pushed a commit to satindergrewal/llama.cpp that referenced this pull request Aug 12, 2026
* mtmd : add Nemotron 3 Nano Omni support (parakeet)

This commit adds support for the subsampling and encoder part of
Nemotron Nemo 3 omni model.

The Parakeet subsampling/encoder were taken from parakeet.cpp which
is currently a pull request against whisper.cpp. I've tried to copy the
code a close as possible to hopefully enable easy patching between the
these two project later.

Refs: ggml-org/whisper.cpp#3735

* mtmd : generate rel pos tensor in graph instead of in conversion [no ci]

This commit removes the generation of the relative positional tensor in
the model conversion script and instead computes it in the encoder
graph. This is only done for the window of positions required for the
current audio sample.

* mtmd : add clip_get_model to clip API [no ci]

This commit adds a function to get access to the clip_model. It also
removes the two functions clip_get_mel_filter_tensor, and
clip_get_window_tensor(const struct clip_ctx * ctx) which can now use
clip_get_model to access the model tensors that it needs.

* mtmd : read mel_filters and window into hparams

* mtmd : use set_input_f32 lambda [no ci]

* mtmd : add better asserts for mel_filters and hann window [no ci]

* mtmd : add missing size_t cast

* mtmd : change type of pad to size_t

* mtmd : zero initialize samples_padded

* mtmd : remove unsued ctx member from parakeet preprocessor

* mtmd : make log_mel_spectrogram_parakeet_worker_thread private static

* mtmd : sync/update parakeeet impl with latest whisper.cpp

This commit updates the parakeet code in mtmd to reflect the latest
updates to parakeet.cpp in whisper.cpp.

A follow up commit will address the currently hardcoded dw_pad and see
if we can add n_conv_kernel as a model metadata field.

* mtmd : add audio_conv_kernel_size to model conversion

This commit updates the model conversion to read the conv_kernel_size
field from the sound_config section of the models config.json file.
It then uses this field instead of the hardcoded values in parakeet.cpp.

* mtmd : cleanup [no ci]

* conversion : call super().filter_tensors [no ci]

* do not discard result of super filter_tensors

* mtmd : use build_mm instead of ggml_mul_mat

* mtmd : use build_ffn

* mtmd : move and reuse get_vector lambda

* mtmd : use build_inp_raw for parakeet

* mtmd : throw exception in get_scalar instead of assert

* mtmd : fix std::min call

* mtmt : use .c_str in throw clause in get_vector

* mtmd : check for F32 type and non-empty tensor in get_vector

The get_vector lambda is used by get_scalar but also standalone to read
in the mel_filters and the window data. Therefor we are not checking
for 1D tensors but allowing multiple dimensions. We do have a check in
get_scalar to verify the size of the vector.

* mtmd : replace hardcoded 1101 for n_tokens_real

* mtmd : assert subsampling_factor is 8

This commit adds an assert of the parakeet subsampling factor to check
that it is 8.

The motivation for this is that this model currently has three
convolutions with a stride of 2. If the underlying model updates the
subsampling factor these convolution operations will need to be updated
and this will produce and error if this occurs.

* mtmd : remove unused ggml_tensors attn_pos_w and mm_norm_w

* mtmd : remove single thread path

This commit removes the single thread path which was a left over from
the original parakeet.cpp where n_threads is configurable.

* fix some security issues

---------

Co-authored-by: Sigbjørn Skjæret <[email protected]>
Co-authored-by: Xuan Son Nguyen <[email protected]>
thecodacus pushed a commit to thecodacus/llama.cpp that referenced this pull request Sep 7, 2026
* mtmd : add Nemotron 3 Nano Omni support (parakeet)

This commit adds support for the subsampling and encoder part of
Nemotron Nemo 3 omni model.

The Parakeet subsampling/encoder were taken from parakeet.cpp which
is currently a pull request against whisper.cpp. I've tried to copy the
code a close as possible to hopefully enable easy patching between the
these two project later.

Refs: ggml-org/whisper.cpp#3735

* mtmd : generate rel pos tensor in graph instead of in conversion [no ci]

This commit removes the generation of the relative positional tensor in
the model conversion script and instead computes it in the encoder
graph. This is only done for the window of positions required for the
current audio sample.

* mtmd : add clip_get_model to clip API [no ci]

This commit adds a function to get access to the clip_model. It also
removes the two functions clip_get_mel_filter_tensor, and
clip_get_window_tensor(const struct clip_ctx * ctx) which can now use
clip_get_model to access the model tensors that it needs.

* mtmd : read mel_filters and window into hparams

* mtmd : use set_input_f32 lambda [no ci]

* mtmd : add better asserts for mel_filters and hann window [no ci]

* mtmd : add missing size_t cast

* mtmd : change type of pad to size_t

* mtmd : zero initialize samples_padded

* mtmd : remove unsued ctx member from parakeet preprocessor

* mtmd : make log_mel_spectrogram_parakeet_worker_thread private static

* mtmd : sync/update parakeeet impl with latest whisper.cpp

This commit updates the parakeet code in mtmd to reflect the latest
updates to parakeet.cpp in whisper.cpp.

A follow up commit will address the currently hardcoded dw_pad and see
if we can add n_conv_kernel as a model metadata field.

* mtmd : add audio_conv_kernel_size to model conversion

This commit updates the model conversion to read the conv_kernel_size
field from the sound_config section of the models config.json file.
It then uses this field instead of the hardcoded values in parakeet.cpp.

* mtmd : cleanup [no ci]

* conversion : call super().filter_tensors [no ci]

* do not discard result of super filter_tensors

* mtmd : use build_mm instead of ggml_mul_mat

* mtmd : use build_ffn

* mtmd : move and reuse get_vector lambda

* mtmd : use build_inp_raw for parakeet

* mtmd : throw exception in get_scalar instead of assert

* mtmd : fix std::min call

* mtmt : use .c_str in throw clause in get_vector

* mtmd : check for F32 type and non-empty tensor in get_vector

The get_vector lambda is used by get_scalar but also standalone to read
in the mel_filters and the window data. Therefor we are not checking
for 1D tensors but allowing multiple dimensions. We do have a check in
get_scalar to verify the size of the vector.

* mtmd : replace hardcoded 1101 for n_tokens_real

* mtmd : assert subsampling_factor is 8

This commit adds an assert of the parakeet subsampling factor to check
that it is 8.

The motivation for this is that this model currently has three
convolutions with a stride of 2. If the underlying model updates the
subsampling factor these convolution operations will need to be updated
and this will produce and error if this occurs.

* mtmd : remove unused ggml_tensors attn_pos_w and mm_norm_w

* mtmd : remove single thread path

This commit removes the single thread path which was a left over from
the original parakeet.cpp where n_threads is configurable.

* fix some security issues

---------

Co-authored-by: Sigbjørn Skjæret <[email protected]>
Co-authored-by: Xuan Son Nguyen <[email protected]>
zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Sep 10, 2026
* mtmd : add Nemotron 3 Nano Omni support (parakeet)

This commit adds support for the subsampling and encoder part of
Nemotron Nemo 3 omni model.

The Parakeet subsampling/encoder were taken from parakeet.cpp which
is currently a pull request against whisper.cpp. I've tried to copy the
code a close as possible to hopefully enable easy patching between the
these two project later.

Refs: ggml-org/whisper.cpp#3735

* mtmd : generate rel pos tensor in graph instead of in conversion [no ci]

This commit removes the generation of the relative positional tensor in
the model conversion script and instead computes it in the encoder
graph. This is only done for the window of positions required for the
current audio sample.

* mtmd : add clip_get_model to clip API [no ci]

This commit adds a function to get access to the clip_model. It also
removes the two functions clip_get_mel_filter_tensor, and
clip_get_window_tensor(const struct clip_ctx * ctx) which can now use
clip_get_model to access the model tensors that it needs.

* mtmd : read mel_filters and window into hparams

* mtmd : use set_input_f32 lambda [no ci]

* mtmd : add better asserts for mel_filters and hann window [no ci]

* mtmd : add missing size_t cast

* mtmd : change type of pad to size_t

* mtmd : zero initialize samples_padded

* mtmd : remove unsued ctx member from parakeet preprocessor

* mtmd : make log_mel_spectrogram_parakeet_worker_thread private static

* mtmd : sync/update parakeeet impl with latest whisper.cpp

This commit updates the parakeet code in mtmd to reflect the latest
updates to parakeet.cpp in whisper.cpp.

A follow up commit will address the currently hardcoded dw_pad and see
if we can add n_conv_kernel as a model metadata field.

* mtmd : add audio_conv_kernel_size to model conversion

This commit updates the model conversion to read the conv_kernel_size
field from the sound_config section of the models config.json file.
It then uses this field instead of the hardcoded values in parakeet.cpp.

* mtmd : cleanup [no ci]

* conversion : call super().filter_tensors [no ci]

* do not discard result of super filter_tensors

* mtmd : use build_mm instead of ggml_mul_mat

* mtmd : use build_ffn

* mtmd : move and reuse get_vector lambda

* mtmd : use build_inp_raw for parakeet

* mtmd : throw exception in get_scalar instead of assert

* mtmd : fix std::min call

* mtmt : use .c_str in throw clause in get_vector

* mtmd : check for F32 type and non-empty tensor in get_vector

The get_vector lambda is used by get_scalar but also standalone to read
in the mel_filters and the window data. Therefor we are not checking
for 1D tensors but allowing multiple dimensions. We do have a check in
get_scalar to verify the size of the vector.

* mtmd : replace hardcoded 1101 for n_tokens_real

* mtmd : assert subsampling_factor is 8

This commit adds an assert of the parakeet subsampling factor to check
that it is 8.

The motivation for this is that this model currently has three
convolutions with a stride of 2. If the underlying model updates the
subsampling factor these convolution operations will need to be updated
and this will produce and error if this occurs.

* mtmd : remove unused ggml_tensors attn_pos_w and mm_norm_w

* mtmd : remove single thread path

This commit removes the single thread path which was a left over from
the original parakeet.cpp where n_threads is configurable.

* fix some security issues

---------

Co-authored-by: Sigbjørn Skjæret <[email protected]>
Co-authored-by: Xuan Son Nguyen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conversion examples mtmd Related to multimodal functionality (video/image/audio) python python script changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants