😉[v0.3.41] Release Note: Template-Driven MTMD, Broader Multimodal Inputs, and Smarter N-Gram Drafting #148
Replies: 2 comments
-
|
When using |
Beta Was this translation helpful? Give feedback.
-
|
The multimodal video functionality has not yet been fully implemented; currently, only the input linking is complete. The upstream |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Release Note: v0.3.41
Template-Driven MTMD, Broader Multimodal Inputs, and Smarter N-Gram Drafting
This release is mainly focused on improving the multimodal architecture, making MTMD chat handling cleaner, more flexible, and easier to extend for future image, audio, and video workflows. I also continued syncing with the latest llama.cpp APIs and improved several developer-facing diagnostics around model templates, shared library loading, and Windows OpenMP runtime discovery.
Highlights
1. Cleaner MTMD Prompt Rendering Pipeline
In this release, I refactored the MTMD prompt processing path by separating prompt rendering, media placeholder normalization, and MTMD tokenization into dedicated helper stages.
The new helpers include:
_render_mtmd_prompt()for pure chat template rendering_replace_media_placeholders()for normalizing rendered media tags and URLs into MTMD runtime markers_render_and_replace_media()for the combined render-and-normalize stage_mtmd_tokenize()for encapsulating the llama.cppmtmd_tokenizebindingThis removes inline render-and-replace logic from
_process_mtmd_prompt()and makes the overall pipeline easier to reason about. Prompt construction, media marker validation, and C++ tokenization are now more clearly separated.Strict media marker validation is still preserved after normalization to ensure token and bitmap alignment remains correct.
2. Better Generic MTMD Chat Template Support
GenericMTMDChatHandlerhas been improved to better support model-provided chat templates.The generic handler can now:
llama_model_chat_template()CHAT_FORMATwhen no model template is availableI also added
extra_template_argumentssupport to MTMD chat handlers and pass these arguments into the Jinja chat template render call. This makes it possible for generic templates to receive render-time options such as:enable_thinkingadd_vision_idThis is an important step toward making the generic MTMD path more template-driven, instead of requiring every new multimodal GGUF model to immediately have a dedicated Python chat handler.
3. Broader Multimodal Media Extraction
MTMD media extraction now supports more common multimodal content shapes used by different model chat templates.
In addition to OpenAI-style chunks such as:
image_urlaudio_urlvideo_urlthe handler now also accepts typed chunks and direct media keys such as:
{"image": "..."}{"audio": "..."}{"video": "..."}A shared media extraction helper was added to support URLs, local paths, existing data URIs, and inline base64 payloads.
Capability checks are still preserved, including strict
input_audioformat validation and explicit errors for missing or ambiguous media payloads.4. Video Input Support for MTMD
MTMDChatHandlernow supportsvideo_urlinput.The implementation detects whether the loaded
libmtmdbuild supports video helpers and rejects video input early whenMTMD_VIDEOis unavailable.Media loading and bitmap creation were updated for the newer helper wrapper API. The decoded bitmap and optional video helper context are now kept alive until
mtmd_tokenizecompletes, then released afterward.I also consolidated duplicated audio and video byte-loading logic into a shared
_load_bytes()helper and reused it for image loading. Remote media requests now also include richer default HTTP headers.5. Multimodal Handlers Moved to
llama_multimodalThe multimodal chat handler code has been moved out of
llama_chat_format.pyand into a dedicatedllama_multimodal.pymodule.This includes:
MTMDChatHandlerGenericMTMDChatHandlerllama_chat_format.pyhad become too large as multimodal support expanded beyond image-only use cases. Moving the MTMD path into its own module makes the codebase easier to maintain and prepares it for future image batch evaluation, video frame processing, and broader multimodal workflows.Backward-compatible re-exports are kept in
llama_chat_format.py, so existing imports should continue to work.clip_model_pathis also kept as a deprecated initialization alias formmproj_pathin the base MTMD handler.6. README Updates for Generic MTMD Usage
The README now includes a new
GenericMTMDChatHandlerusage guide.The old Llava-style multimodal loading example has been replaced with a template-driven generic MTMD example for modern multimodal GGUF models.
The documentation now explains:
mmprojthroughLlamaextra_template_argumentsmmproj_pathnamingllama_multimodalThe Generic MTMD Chat Handler directory index has also been updated.
7. Smarter N-Gram Map Speculative Drafting
The speculative decoding path also received several improvements.
The n-gram map draft logic now:
min_hitsk4vcontinuations by frequency instead of latest occurrencek4vdrafts when the top continuation is not dominantk4vcontinuations so frequency statistics remain comparableThis should make draft selection more stable and less likely to over-draft in ambiguous continuation cases.
8. Safer Model Chat Template Handling
LlamaModel.model_chat_template()now returnsOptional[str]and acceptsname=Nonefor the default model chat template.This fixes a case where
llama_model_chat_template()may returnnullptrwhen no chat template is available. Instead of decoding a null pointer, the wrapper now returnsNone, allowing callers to apply their own fallback logic safely.I also updated
LlamaModel.vocab_typeto useself.vocaband added additionalNonechecks.9. Better Developer Diagnostics
This release includes several improvements for debugging build and runtime issues.
Shared library loading errors now include a listing of the searched directory contents. This makes it easier to diagnose missing, misplaced, or incorrectly named library files.
A new
_format_library_dir_contents()helper was added, and the extra diagnostic work is only performed on the failure path, so successful imports do not pay any additional overhead.For Windows builds, CMake now improves LLVM OpenMP runtime discovery for
libomp140.x86_64.dll. The search prefers the VS 2022 VC143 OpenMP redistributable and keepsSystem32as the final fallback. Diagnostics now report the selected runtime source and path, warn when an explicit override points to a missing file, and keep a clear warning when no OpenMP DLL is found.10. Upstream llama.cpp Sync
This release updates the bundled llama.cpp source to:
ggml-org/llama.cpp@3899b39ce2acc2e019f149b7107f24b6ca297390It also syncs the llama.cpp
llama,mtmd, andggmlAPI bindings as of 2026-07-07.Community Contributions
Thanks to the contributors included in this release:
Summary
Overall, v0.3.41 is a structural release for multimodal support.
The main goal is to make MTMD handling cleaner, more generic, and more extensible. The codebase now has a clearer separation between text-only chat formatting and multimodal processing, better support for model-provided templates, broader media input compatibility, early video support, and improved diagnostics for developers building or loading the package.
More information:
12861b9...b9b5859
— JamePeng
Beta Was this translation helpful? Give feedback.
All reactions