Skip to content

mtmd: enforce no_realloc - #33377

Open
ngxson wants to merge 12 commits into
masterfrom
xsn/mtmd_no_realloc
Open

ngxson wants to merge 12 commits into
masterfrom
xsn/mtmd_no_realloc

Conversation

@ngxson

@ngxson ngxson commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Important

Side effect of this change: max image size will be set to a lower value by default, user need to explicitly raise the limit via CLI argument

Enforce no_realloc in mtmd

Mtmd was initially designed to take very arbitrary input: vision (dynamic image size), audio, and most recently many inner-stages embeddings shapes for TTS pipeline

This makes it hard to keep track of memory usage, and now it's a good time to finally refactor it.

Related: ngxson/wllama#319 --> copy device-to-host make the wasm run out of memory

Follow-up:

  • Run real warmup pass
  • Allow fit to raise the max tokens limit if we still have free memory
  • Remove D2H copy on mtmd output

Requirements

@ngxson
ngxson requested review from a team and ggerganov as code owners November 30, 2026 13:25
@github-actions github-actions Bot added documentation Improvements or additions to documentation testing Everything test related devops improvements to build systems and github actions server mtmd Related to multimodal functionality (video/image/audio) labels Nov 30, 2026
@CISC

CISC commented Nov 30, 2026

Copy link
Copy Markdown
Member

Real failure:
https://github.com/ggml-org/llama.cpp/actions/runs/46428273990/job/141880851628#step:6:538

… tensors

A ggml_new_tensor scaled by 0 is not zero: the buffer is never written,
so a NaN left by a previous graph comes out as NaN.
Use ggml_pad_ext for the paddings and ggml_repeat_4d for img_break.
The pulse train turns a small F0 difference between backends
into a phase drift, CUDA vs CPU gave NMSE 5.7e-2.
Only the F0 bias is set so that F0 clamps the same everywhere,
voicing and energy stay random.

@ServeurpersoCom ServeurpersoCom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested on RTX PRO 6000 (CUDA) and Vulkan on the same card: with the two commits I pushed (uninitialized padding / img_break tensors, tiny_voca F0), every case not marked TODO passes on CUDA, and real-weights e2e on Qwen3.8-27B, Mistral Small 4 and Nemotron-3.5-Super-VL with a 4000x4000 image reads the text correctly under the new default cap.

Nits / improvements:

  • test-mtmd-model is labeled "behavior backend" without "main", so no CI job runs it (GPU jobs use ctest -L main, behavior-check excludes backend): you could use "main behavior backend" like test-llama-archs, and since the branch is upstream the self-hosted runners would show the backends nobody ran yet before the merge.
  • Forcing the TODO cases on CUDA (-t): deepseekocr, kimik25, kimik31, nemotron_omni and granite4_vision still grow the compute buffer after the warmup (kimik25 2122 -> 2255 MiB), so a NO_REALLOC build would abort on them.
  • nemotron_omni is a one-liner: replacing warmup_image_size = image_size with set_default_max_patches() removes the realloc (checked on CPU, CUDA and the real Nemotron-3.5-Super-VL), but it also caps the model from 3328 to 2116 image tokens by default; warming up at the model max instead would keep the master output with a bigger buffer, your call.
  • voxtral aborts on a 30 s clip (graph 188 tokens, n_output_tokens() 187), and master has the same count: avgpool then stack-by-4 on 1500 frames gives 188. The current HF VoxtralEncoder also defines avg_pooler without calling it, could you double check the pooling against the real weights?
  • On Vulkan, dots3note_v is just over the threshold (NMSE 1.022e-4 vs 1e-4) with coopmat F16 matmuls, it passes with GGML_VK_DISABLE_COOPMAT=1 or GGML_VK_DISABLE_F16=1: you could give that case a precise TODO or a looser threshold.
  • mimo_audio also fails on CUDA (NMSE 1e-3, RVQ argmax flips), its TODO only mentions Metal.
  • The drama3 tower attention now always reads the 4096 slot rows: llama-tts goes from 5.88x to 5.44x realtime (146 -> 136 frames/s) on the Q8_0, you could bucket n_kv if that matters.

This branch has not been deployed

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

Labels

devops improvements to build systems and github actions documentation Improvements or additions to documentation mtmd Related to multimodal functionality (video/image/audio) server testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants