koboldcpp/src
Pedro Cuenca 62bf73d25c
model: Muse Glimmer Support (#26841)
* Get started with Onyx

* Add architecture

* Skip keys handled in super()

* Loading tensors

* Shorten

* Graph

* Apply suggestion from @pcuenca

* Remove norm now embedding in transformers weights

* Add eot

* Explicit output_multiplier

* Handle post_norm_eps

* No super call; unhardcode eot.

The pattern `self._set_vocab_gpt2()` seems preferred throughout the
codebase, and it allows `set_vocab()` to be called from a different part
of the Python class hierarchy: the drafter model converter that we may
need eventually.

* Register for drafting

* DFlash: inherit rope type from the linked target.

Another option would be to store it in the gguf file itself.

* mmproj conversion

Note: some fields to be renamed after the implementation works. We are
keeping compatibility with the reference Meta gguf for testing purposes.

* "clip" header declarations

* Load mmproj

* Pre-processing

* Graph

* Go back to using delimiters.

Otherwise our generations are worse.

Transformers does not use them. We need to trace inputs to verify
whether they are equivalent.

* downsample_factor -> merge_size

* Add vision graph

lol, forgot from a previous commit

* Additional renames, align with llama.cpp / transformers

* Prefer _size instead of independent _h and _w

* Fix token layout

Co-authored-by: Young Han <younghan@fb.com>

* onyx: bring the chat parser onto the onyx branch

common/chat.cpp on this branch has no Onyx handling, so a converted model
serves malformed chat: the assistant preamble leaks into content
("to=self<|message|>...") and tool calls fail with

    HTTP 500 "The model produced output that does not match the expected
              peg-native format"

common_chat_params_init_onyx exists on onyx-fair-patch, added there by
8bb73dd3d. It was never on this branch, so this is not a regression --
the two lines developed independently.

The code here is taken verbatim from that commit. It is the clean side of
`git merge origin/onyx-fair-patch`: chat.cpp is one of the files that
merges without conflict. The full merge is not viable -- it produces 13
conflicts, including add/add on conversion/onyx.py and src/models/onyx.cpp
where the q_norm-folding and metadata-scale approaches contradict each
other, and #4/#7 are stacked on this branch's side of that.

Verified on this branch: builds with 0 errors, converts an Onyx checkpoint,
and serving it gives "4" for "What is 2+2?" plus a correct
get_weather {"city":"Paris"} tool call, where the unported branch gives the
two failures above.

No converter or runtime changes are included, so this should not interact
with the q_norm work.

Co-authored-by: Beto de Paola <betodepaola@meta.com>

* Less params, bilinear pos-emb interpolation as a graph op instead of CPU

* Map to symbolic V_MMPROJ instead of strings

* Make a couple params explicit

* Patchify via build_inp()

* No param for rope_theta

* Small cleanup

* Restore blank line

* Unpermute, to adapt to the latest transformers checkpoint

* Apply norm after token embeddings

This follows the latest transformers approach.

* Remove duplicated function

* build_vit

* onyx: use the model rope theta on sliding-window layers

* DFlash: conversion from transformers drafter

* Revert rope_type derivation from target

NOTE: this breaks compatibility with Meta's distributed DFlash GGUFs, as
the Q/K are stored in "NEOX" (rotated half) format, like in
transformers.

* Apply suggestion from @pcuenca

* Set model type

* Remove comment that will become obsolete

* Hardcode post_norm_rms_eps instead of new param

* Derive SWA+RoPE pattern from gguf array or scalar

* Fix model type <-> number of layers

* Reorder

* Rename

* Fix typo

* DFlash: seed the draft KV cache from multimodal embedding batches

`common_speculative_impl_draft_dflash::process()` returned early on any batch carrying embeddings, so an image prefill never had its target-layer features fused through the DFlash encoder and injected into the draft's KV cache. That left a hole spanning the image's positions, and the next injection at a post-image position failed to initialize its batch:

```
decoding image batch 1/1, n_tokens_batch = 256
decode: failed to initialize batch
llama_decode: failed to decode, ret = -1
process: llama_decode(ctx_dft) failed rc=-1 (n_tokens=17, offset=0)
srv decode: failed to process speculative batch
```

Every image request with `--spec-type draft-dflash` failed with HTTP 500. Text-only was unaffected, since those batches carry token ids and were let through.

Restore the earlier condition, which admits a batch that is either tokens or embeddings and skips only the degenerate neither/both cases. The rest of `process()` is already layout-agnostic -- it gathers features via `llama_get_embeddings_layer_inp()` and indexes `batch_in.pos[]` / `batch_in.seq_id[]`, none of which assume token ids -- so this is the whole fix.

Validated against `muse-glimmer-30B-bf16.gguf` + `mmproj-muse-glimmer-30B-bf16.gguf` + a DFlash draft head, on an image describe-the-shapes request:

- before: HTTP 500, `failed to process speculative batch`
- after: HTTP 200, draft acceptance 0.34012 (167 accepted / 491 generated), mean len 3.04

Output equivalence holds, which is the property that matters: at temperature 0 the drafted response is byte-identical to the same request served with no draft attached (1213/1213 chars), so the draft is drafting correctly through the image context rather than merely not crashing.

* Conversion: prefer rewrite to mapping

* Revert "Conversion: prefer rewrite to mapping"

This reverts commit a92d0ac584d315e876741e85b6dad3dbc8b23bf7.

* fix lint

* sliding_window metadata is not optional

* disable state save/load

* Apply suggestion from @pcuenca

---------

Co-authored-by: Young Han <younghan@fb.com>
Co-authored-by: Beto de Paola <betodepaola@meta.com>
Co-authored-by: Daniel Han <michaelhan2050@gmail.com>
Co-authored-by: ruanrms <ruanslv@gmail.com>
Co-authored-by: Xuan Son Nguyen <son@huggingface.co>
Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
2026-08-10 13:07:27 +02:00
..
models model: Muse Glimmer Support (#26841) 2026-08-10 13:07:27 +02:00
CMakeLists.txt model: M3: Move MSA into a new memory implementation (#26338) 2026-08-03 16:30:08 +03:00
llama-adapter.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
llama-adapter.h llama : re-enable manual LoRA adapter free (#19983) 2026-03-18 12:03:26 +02:00
llama-arch.cpp model: Muse Glimmer Support (#26841) 2026-08-10 13:07:27 +02:00
llama-arch.h model: Muse Glimmer Support (#26841) 2026-08-10 13:07:27 +02:00
llama-batch.cpp llama-batch: fix allowed decreasing pos in a seq (#25449) 2026-07-08 19:24:34 +03:00
llama-batch.h llama-batch: add n_keep_tail in split_equal for recurrent models (#25278) 2026-07-08 15:55:19 +08:00
llama-chat.cpp chat : add Granite 4.1 chat template (#23518) 2026-05-28 13:13:33 +02:00
llama-chat.h chat : add Granite 4.1 chat template (#23518) 2026-05-28 13:13:33 +02:00
llama-context.cpp model : Granite-Switch Architecture (#25107) 2026-08-10 09:53:46 +02:00
llama-context.h llama: refactor fused ops (#24646) 2026-07-08 18:18:09 +08:00
llama-cparams.cpp cparams : rename LLAMA_MAX_PARALLEL_SEQUENCES to LLAMA_MAX_SEQ (#14188) 2025-06-15 10:08:58 +03:00
llama-cparams.h DeepseekV4: Add fused hyper-connection ops (#25585) 2026-07-17 00:33:33 +08:00
llama-ext.h mtmd: support Qwen3-TTS (note: breaking change to llama-tts binary) (#26254) 2026-08-04 17:26:15 +02:00
llama-grammar.cpp grammar : degrade max repetition >= 2000 to unbounded (#26613) 2026-08-05 07:39:10 -05:00
llama-grammar.h common/grammar : replace problematic backtracking regex [\s\S]* (#18342) 2026-01-03 16:02:43 -06:00
llama-graph.cpp llama : move n_vocab from llama_sampler_data to penalty_sampler (#26520) 2026-08-04 09:02:49 +03:00
llama-graph.h graph : fix unused input tensors in minimax m3 graph (#26519) 2026-08-03 17:32:01 +03:00
llama-hparams.cpp model : Granite-Switch Architecture (#25107) 2026-08-10 09:53:46 +02:00
llama-hparams.h model : Granite-Switch Architecture (#25107) 2026-08-10 09:53:46 +02:00
llama-impl.cpp llama : correct platform-independent loading of BOOL metadata (#21428) 2026-04-06 01:40:38 +02:00
llama-impl.h llama: refactor fused ops (#24646) 2026-07-08 18:18:09 +08:00
llama-io.cpp server : avoid checkpoint data host copies (#22558) 2026-05-02 18:03:25 +03:00
llama-io.h llama : add option to save memory in device buffers (#22679) 2026-05-05 06:35:07 +03:00
llama-kv-cache-dsa.cpp llama : allocate indexer cache only in "full" indexer layers (#26474) 2026-08-03 14:56:30 +02:00
llama-kv-cache-dsa.h llama : allocate indexer cache only in "full" indexer layers (#26474) 2026-08-03 14:56:30 +02:00
llama-kv-cache-dsv4.cpp DeepseekV4 MTP + DSpark (#25784) 2026-08-02 20:55:34 +08:00
llama-kv-cache-dsv4.h DeepseekV4 MTP + DSpark (#25784) 2026-08-02 20:55:34 +08:00
llama-kv-cache-iswa.cpp llama-batch: add n_keep_tail in split_equal for recurrent models (#25278) 2026-07-08 15:55:19 +08:00
llama-kv-cache-iswa.h DeepSeek V4 (#24162) 2026-06-29 16:58:51 +08:00
llama-kv-cache-msa.cpp model: M3: Move MSA into a new memory implementation (#26338) 2026-08-03 16:30:08 +03:00
llama-kv-cache-msa.h model: M3: Move MSA into a new memory implementation (#26338) 2026-08-03 16:30:08 +03:00
llama-kv-cache.cpp model : Granite-Switch Architecture (#25107) 2026-08-10 09:53:46 +02:00
llama-kv-cache.h model: M3: Move MSA into a new memory implementation (#26338) 2026-08-03 16:30:08 +03:00
llama-kv-cells.h kv-cache : avoid kv cells copies (#24277) 2026-06-07 21:42:54 +03:00
llama-memory-hybrid-iswa.cpp llama-batch: add n_keep_tail in split_equal for recurrent models (#25278) 2026-07-08 15:55:19 +08:00
llama-memory-hybrid-iswa.h llama + spec: MTP Support (#22673) 2026-05-16 20:06:23 +08:00
llama-memory-hybrid.cpp llama-batch: add n_keep_tail in split_equal for recurrent models (#25278) 2026-07-08 15:55:19 +08:00
llama-memory-hybrid.h llama + spec: MTP Support (#22673) 2026-05-16 20:06:23 +08:00
llama-memory-recurrent.cpp llama: various bug fixes (#26051) 2026-07-24 18:56:42 +02:00
llama-memory-recurrent.h llama : MTP clean-up (#23269) 2026-05-19 15:32:58 +03:00
llama-memory.cpp memory : correctly handle failure in apply() (#14438) 2025-06-30 18:03:03 +03:00
llama-memory.h llama : add Gemma4 MTP (#23398) 2026-06-07 20:50:54 +08:00
llama-mmap.cpp Update llama-mmap to use ftello/fseeko (#22497) 2026-04-30 14:17:52 -07:00
llama-mmap.h llama: fix llama-model-saver (#20503) 2026-03-25 12:53:16 +02:00
llama-model-loader.cpp model : Granite-Switch Architecture (#25107) 2026-08-10 09:53:46 +02:00
llama-model-loader.h model : allow reshape of tensors during load (#26531) 2026-08-04 09:06:44 +03:00
llama-model-saver.cpp model: Muse Glimmer Support (#26841) 2026-08-10 13:07:27 +02:00
llama-model-saver.h llama: fix llama-model-saver (#20503) 2026-03-25 12:53:16 +02:00
llama-model.cpp model: Muse Glimmer Support (#26841) 2026-08-10 13:07:27 +02:00
llama-model.h model : Granite-Switch Architecture (#25107) 2026-08-10 09:53:46 +02:00
llama-quant.cpp llama : load MTP tensors only if they are really used (#26296) 2026-07-31 14:57:02 +02:00
llama-quant.h llama : refactor src/llama.cpp (#10902) 2025-01-03 10:18:53 +02:00
llama-sampler.cpp sampler : remove "full-context windows" from history-based samplers (#26524) 2026-08-04 21:28:55 +03:00
llama-sampler.h sampler : remove "full-context windows" from history-based samplers (#26524) 2026-08-04 21:28:55 +03:00
llama-vocab.cpp vocab : validate plamo2 byte tokens (#26511) 2026-08-04 11:40:02 +03:00
llama-vocab.h Add support for Laguna XS.2 & M.1 (#25165) 2026-07-22 09:54:08 +08:00
llama.cpp llama : load MTP tensors only if they are really used (#26296) 2026-07-31 14:57:02 +02:00
unicode-data.cpp server : better security control for public deployments (#9776) 2024-10-08 13:27:04 +02:00
unicode-data.h llama : reduce compile time and binary size (#9712) 2024-10-02 15:49:55 +02:00
unicode.cpp unicode,test: add Qwen3.5 non-backtracking tokenizer handler and regr… (#22110) 2026-05-14 11:03:40 +02:00
unicode.h vocab: fix Gemma4 tokenizer (#21343) 2026-04-03 10:33:03 +02:00