koboldcpp/tools/mtmd
Maphist0 7775ffb7e4
model: Add support for SenseNova U1 model (#28919)
* model : add SenseNova U1 understanding support

Add support for the dense SenseNova U1 understanding branch, including
the U1.5-8B-MoT model.

- Add HF-to-GGUF conversion for NEOChatModel, excluding MoT generation
  tensors and concatenating temporal and spatial Q/K normalization
  weights.
- Register the sensenova_u1 GGUF architecture and custom spatial RoPE
  metadata.
- Implement temporal/spatial Q/K normalization with 4-axis RoPE.
- Keep U1-specific text position handling in the model implementation.
- Add synthetic architecture coverage for sensenova_u1.

Only the dense understanding branch is supported; generation
branches are intentionally rejected during conversion.

* conversion : treat one-expert SenseNova U1 configs as dense

* mtmd : add SenseNova U1 vision support

Add conversion support for the SenseNova U1 vision encoder and implement
its CPU mtmd projector graph.

The graph applies patch embedding, GELU, adjacent-pair 2D RoPE, spatial
downsampling, and dense projection for dynamic-resolution image inputs.

* mtmd : fix SenseNova U1 vision token layout

* model : clean up SenseNova U1 RoPE metadata

Replace the hard-coded spatial RoPE key with shared GGUF and LLM_KV
definitions used by conversion, model loading, and architecture tests.

Clarify why SenseNova U1 retains its custom text-position input: U1 uses
[t, 0, 0, 0], while the generic M-RoPE input uses [t, t, t, 0].

* mtmd : simplify SenseNova U1 projector integration

Map the SenseNova U1 dense projection to the standard mm.0 weight and
bias tensors and reuse the shared projector fields in the loader and graph.

Read vision parameters from the checkpoint configuration and remove the
U1-specific tensor names and model fields while preserving its strided
projection, bias, and row-major token layout.

* mtmd : fix SenseNova U1 image positions and attention

* fix spacing

* mtmd : restore generic test input chunks

* mtmd : restore SenseNova U1 integration after upstream merge

* Update conversion/sensenova_u1.py

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>

* Update src/models/sensenova-u1.cpp

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>

* model : remove SenseNova U1 BF16 activation casts

Use standard backend precision handling for QKV, FFN, and output
projections instead of casting inputs based on the output tensor type.

Assisted-by: Codex

* Update src/models/sensenova-u1.cpp

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>

---------

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
2026-10-21 21:54:16 +02:00
..
debug mtmd: add --mmproj-device argument (#23255) 2026-08-20 18:45:37 +02:00
legacy-models chore : correct typos [no ci] (#20041) 2026-03-05 08:50:21 +01:00
models model: Add support for SenseNova U1 model (#28919) 2026-10-21 21:54:16 +02:00
tests sampler : remove "full-context windows" from history-based samplers (#26524) 2026-08-04 21:28:55 +03:00
clip-graph.h model : support MiniCPM-V 4.7 (#29416) 2026-10-10 20:41:59 +02:00
clip-impl.h model: Add support for SenseNova U1 model (#28919) 2026-10-21 21:54:16 +02:00
clip-model.h model : support Nemotron-3(.5)-Embed (#30877) 2026-10-20 22:48:45 +02:00
clip.cpp model: Add support for SenseNova U1 model (#28919) 2026-10-21 21:54:16 +02:00
clip.h mtmd: add state object for mtmd_gen (#30902) 2026-10-21 12:59:54 +02:00
CMakeLists.txt model: Add support for SenseNova U1 model (#28919) 2026-10-21 21:54:16 +02:00
deprecation-warning.cpp llama : add missing headers (#28566) 2026-09-08 12:59:53 +02:00
mtmd-audio.cpp mtmd: add mtmd_audio_stream + support voxtral-realtime (#30629) 2026-10-16 01:46:42 +02:00
mtmd-audio.h mtmd: add mtmd_audio_stream + support voxtral-realtime (#30629) 2026-10-16 01:46:42 +02:00
mtmd-cli.cpp mtmd: add mtmd_audio_stream + support voxtral-realtime (#30629) 2026-10-16 01:46:42 +02:00
mtmd-helper-common.h mtmd: fix GCC 15 stringop-overflow in decode_embd_batch (#29607) 2026-09-29 01:21:37 +02:00
mtmd-helper-gen.cpp mtmd: add state object for mtmd_gen (#30902) 2026-10-21 12:59:54 +02:00
mtmd-helper.cpp mtmd : fix deprecated strdup warning on Windows (#29863) 2026-10-03 19:47:54 +02:00
mtmd-helper.h server : add POST /tts endpoint for TTS models (#26603) 2026-10-21 01:19:42 +02:00
mtmd-image.cpp model : support Nemotron-3(.5)-Embed (#30877) 2026-10-20 22:48:45 +02:00
mtmd-image.h mtmd : lfm2 tiles and layout match transformers (#30261) 2026-10-20 18:54:46 +02:00
mtmd-internal.h mtmd: add mtmd_tokenize_from_parts() (#28250) 2026-09-02 21:20:10 +02:00
mtmd.cpp model: Add support for SenseNova U1 model (#28919) 2026-10-21 21:54:16 +02:00
mtmd.h mtmd: add state object for mtmd_gen (#30902) 2026-10-21 12:59:54 +02:00
README-dev.md mtmd: add state object for mtmd_gen (#30902) 2026-10-21 12:59:54 +02:00
README.md mtmd : support MiniCPM-V 4.6 (#22529) 2026-05-06 21:54:09 +02:00
requirements.txt requirements: use stable torch packages on s390x (#26864) 2026-08-11 21:58:53 +08:00
test-1.jpeg mtmd : rename llava directory to mtmd (#13311) 2025-05-05 16:02:55 +02:00
test-2.mp3 mtmd : support Qwen 2.5 Omni (input audio+vision, no audio output) (#13784) 2025-05-27 14:06:10 +02:00
test-3.mp4 mtmd : add video input support (#24269) 2026-06-08 14:40:12 +03:00
tests.sh mtmd: add batching for mtmd-cli, add video tests (#24778) 2026-06-18 21:55:04 +02:00

Multimodal Support in llama.cpp

This directory provides multimodal capabilities for llama.cpp. Initially intended as a showcase for running LLaVA models, its scope has expanded significantly over time to include various other vision-capable models. As a result, LLaVA is no longer the only multimodal architecture supported.

Important

Multimodal support can be viewed as a sub-project within llama.cpp. It is under very heavy development, and breaking changes are expected.

The naming and structure related to multimodal support have evolved, which might cause some confusion. Here's a brief timeline to clarify:

  • #3436: Initial support for LLaVA 1.5 was added, introducing llava.cpp and clip.cpp. The llava-cli binary was created for model interaction.
  • #4954: Support for MobileVLM was added, becoming the second vision model supported. This built upon the existing llava.cpp, clip.cpp, and llava-cli infrastructure.
  • Expansion & Fragmentation: Many new models were subsequently added (e.g., #7599, #10361, #12344, and others). However, llava-cli lacked support for the increasingly complex chat templates required by these models. This led to the creation of model-specific binaries like qwen2vl-cli, minicpmv-cli, and gemma3-cli. While functional, this proliferation of command-line tools became confusing for users.
  • #12849: libmtmd was introduced as a replacement for llava.cpp. Its goals include providing a single, unified command-line interface, improving the user/developer experience (UX/DX), and supporting both audio and image inputs.
  • #13012: mtmd-cli was added, consolidating the various model-specific CLIs into a single tool powered by libmtmd.

Pre-quantized models

See the list of pre-quantized model here

How it works and what is mmproj?

Multimodal support in llama.cpp works by encoding images into embeddings using a separate model component, and then feeding these embeddings into the language model.

This approach keeps the multimodal components distinct from the core libllama library. Separating these allows for faster, independent development cycles. While many modern vision models are based on Vision Transformers (ViTs), their specific pre-processing and projection steps can vary significantly. Integrating this diverse complexity directly into libllama is currently challenging.

Consequently, running a multimodal model typically requires two GGUF files:

  1. The standard language model file.
  2. A corresponding multimodal projector (mmproj) file, which handles the image encoding and projection.

What is libmtmd?

As outlined in the history, libmtmd is the modern library designed to replace the original llava.cpp implementation for handling multimodal inputs.

Built upon clip.cpp (similar to llava.cpp), libmtmd offers several advantages:

  • Unified Interface: Aims to consolidate interaction for various multimodal models.
  • Improved UX/DX: Features a more intuitive API, inspired by the Processor class in the Hugging Face transformers library.
  • Flexibility: Designed to support multiple input types (text, audio, images) while respecting the wide variety of chat templates used by different models.

How to obtain mmproj

Multimodal projector (mmproj) files are specific to each model architecture.

For the following models, you can use convert_hf_to_gguf.py with --mmproj flag to get the mmproj file:

  • Gemma 3 ; See the guide here - Note: 1B variant does not have vision support
  • SmolVLM (from HuggingFaceTB)
  • SmolVLM2 (from HuggingFaceTB)
  • Pixtral 12B - only works with transformers-compatible checkpoint
  • Qwen 2 VL and Qwen 2.5 VL (from Qwen)
  • Mistral Small 3.1 24B
  • InternVL 2.5 and InternVL 3 from OpenGVLab (note: we don't support conversion of InternVL3-*-hf model, only non-HF version is supported ; InternLM2Model text model is not supported)
  • MiniCPM-V 4.6 ; See the guide here - requires the standard transformers v5.7.0+ checkpoint

For older models, please refer to the relevant guide for instructions on how to obtain or create them:

NOTE: conversion scripts are located under tools/mtmd/legacy-models