koboldcpp/src/models
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
..
afmoe.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
apertus.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
arcee.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
arctic.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
arwkv7.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
baichuan.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
bailingmoe.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
bailingmoe2.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
bert.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
bitnet.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
bloom.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
chameleon.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
chatglm.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
clip.cpp llama: Restore quantization of mmprojs (#26818) 2026-08-10 11:58:32 +02:00
codeshell.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
cogvlm.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
cohere2.cpp Add arch support for cohere2-MoE (#24260) 2026-06-13 19:49:00 +02:00
cohere2moe.cpp llama : load MTP tensors only if they are really used (#26296) 2026-07-31 14:57:02 +02:00
command-r.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
dbrx.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
deci.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
deepseek.cpp model : NvFP4 quantized LM head support (#23046) 2026-05-16 11:09:27 +02:00
deepseek2.cpp model : support MTP in GLM-4.7-Flash (#24868) 2026-08-03 20:27:52 +02:00
deepseek2ocr.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
deepseek4.cpp model : allow reshape of tensors during load (#26531) 2026-08-04 09:06:44 +03:00
deepseek32.cpp llama : MTP support for DeepSeek V3.2 (#26457) 2026-08-03 08:25:01 +02:00
delta-net-base.cpp llama: refactor fused ops (#24646) 2026-07-08 18:18:09 +08:00
dflash.cpp models : fix dflash wo_a reshape on load (#26577) 2026-08-04 16:56:49 +03:00
dots1.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
dream.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
eagle3.cpp spec: add eagle3-v3 support for gpt-oss model (#25794) 2026-07-28 09:58:16 +03:00
ernie4-5-moe.cpp model : NvFP4 quantized LM head support (#23046) 2026-05-16 11:09:27 +02:00
ernie4-5.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
eurobert.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
exaone-moe.cpp minor : fix lint issues (#24165) 2026-06-05 11:17:54 +03:00
exaone.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
exaone4.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
falcon-h1.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
falcon.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
gemma-embedding.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
gemma.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
gemma2.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
gemma3.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
gemma3n.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
gemma4-assistant.cpp mtp: support for gemma-4 E2B and E4B assistants (#24282) 2026-06-08 13:48:52 -07:00
gemma4.cpp llama: move suppress_tokens handling to common/sampling (#26276) 2026-07-29 18:02:30 +02:00
glm-dsa.cpp llama : load MTP tensors only if they are really used (#26296) 2026-07-31 14:57:02 +02:00
glm4-moe.cpp minor : fix lint issues (#24165) 2026-06-05 11:17:54 +03:00
glm4.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
gpt2.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
gptneox.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
granite-hybrid.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
granite-moe.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
granite-switch.cpp model : Granite-Switch Architecture (#25107) 2026-08-10 09:53:46 +02:00
granite.cpp model, mtmd: Granite4 Vision (#23545) 2026-06-05 17:44:59 +02:00
grok.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
grovemoe.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
hunyuan-dense.cpp model: move load_hparams and load_tensors to per-model definition (#22004) 2026-05-04 12:36:59 +02:00
hunyuan-moe.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
hunyuan-vl.cpp model : NvFP4 quantized LM head support (#23046) 2026-05-16 11:09:27 +02:00
hy-v3.cpp llama : load MTP tensors only if they are really used (#26296) 2026-07-31 14:57:02 +02:00
internlm2.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
jais.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
jais2.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
jamba.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
jina-bert-v2.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
jina-bert-v3.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
kimi-linear.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
laguna.cpp model: Add Laguna-S-2.1 LLM_TYPE (#26233) 2026-07-28 21:02:33 +02:00
lfm2.cpp model : Add label for LFM2.5-230M (#25008) 2026-06-25 18:58:52 +02:00
lfm2moe.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
llada-moe.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
llada.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
llama-embed.cpp model: move load_hparams and load_tensors to per-model definition (#22004) 2026-05-04 12:36:59 +02:00
llama.cpp spec: add EAGLE3 speculative decoding support (#18039) 2026-06-12 10:21:06 +03:00
llama4.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
maincoder.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
mamba-base.cpp mamba2: remove hardcoded 2x expansion factor and invalid d_inner % d_state check (#23082) 2026-06-26 08:50:54 +03:00
mamba.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
mamba2.cpp mamba2: remove hardcoded 2x expansion factor and invalid d_inner % d_state check (#23082) 2026-06-26 08:50:54 +03:00
mellum.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
mimo2.cpp model : load MiMo V2 MTP tensors only if used (#26412) 2026-08-02 09:03:05 +02:00
minicpm.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
minicpm3.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
minimax-m2.cpp spec: add Minimax2 eagle3 support 2026-07-13 15:22:37 +02:00
minimax-m3.cpp graph : fix unused input tensors in minimax m3 graph (#26519) 2026-08-03 17:32:01 +03:00
mistral3.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
mistral4.cpp model: move load_hparams and load_tensors to per-model definition (#22004) 2026-05-04 12:36:59 +02:00
models.h model: Muse Glimmer Support (#26841) 2026-08-10 13:07:27 +02:00
modern-bert.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
mpt.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
muse-glimmer.cpp model: Muse Glimmer Support (#26841) 2026-08-10 13:07:27 +02:00
nanbeige.cpp model: Add support for Nanbeige4.2 (#25994) 2026-07-27 17:04:18 +02:00
nemotron-h-moe.cpp model: add MTP support for Nemotron model (#26725) 2026-08-10 11:25:24 +03:00
nemotron-h.cpp model: add MTP support for Nemotron model (#26725) 2026-08-10 11:25:24 +03:00
nemotron.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
neo-bert.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
nomic-bert-moe.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
nomic-bert.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
olmo.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
olmo2.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
olmoe.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
openai-moe.cpp spec: add eagle3-v3 support for gpt-oss model (#25794) 2026-07-28 09:58:16 +03:00
openelm.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
orion.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
paddleocr.cpp model : NvFP4 quantized LM head support (#23046) 2026-05-16 11:09:27 +02:00
pangu-embed.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
phi2.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
phi3.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
phimoe.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
plamo.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
plamo2.cpp models : fix plamo2 attention_key/value_length regression (#24317) 2026-06-09 10:26:44 +03:00
plamo3.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
plm.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
qwen.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
qwen2.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
qwen2moe.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
qwen2vl.cpp model : NvFP4 quantized LM head support (#23046) 2026-05-16 11:09:27 +02:00
qwen3.cpp spec: add EAGLE3 speculative decoding support (#18039) 2026-06-12 10:21:06 +03:00
qwen3moe.cpp spec: add EAGLE3 speculative decoding support (#18039) 2026-06-12 10:21:06 +03:00
qwen3next.cpp model: MTP support for Qwen3-Next (#25589) 2026-08-03 17:15:01 +09:00
qwen3tts.cpp mtmd: support Qwen3-TTS (note: breaking change to llama-tts binary) (#26254) 2026-08-04 17:26:15 +02:00
qwen3vl.cpp mtmd: support Qwen3-TTS (note: breaking change to llama-tts binary) (#26254) 2026-08-04 17:26:15 +02:00
qwen3vlmoe.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
qwen35.cpp llama : load MTP tensors only if they are really used (#26296) 2026-07-31 14:57:02 +02:00
qwen35moe.cpp llama : load MTP tensors only if they are really used (#26296) 2026-07-31 14:57:02 +02:00
refact.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
rnd1.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
rwkv6-base.cpp models : deduplicate delta-net graphs for Qwen family (#19597) 2026-02-16 14:35:04 +02:00
rwkv6.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
rwkv6qwen2.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
rwkv7-base.cpp models : deduplicate delta-net graphs for Qwen family (#19597) 2026-02-16 14:35:04 +02:00
rwkv7.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
seed-oss.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
smallthinker.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
smollm3.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
stablelm.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
starcoder.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
starcoder2.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
step35.cpp llama : load MTP tensors only if they are really used (#26296) 2026-07-31 14:57:02 +02:00
t5.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
t5encoder.cpp model: move load_hparams and load_tensors to per-model definition (#22004) 2026-05-04 12:36:59 +02:00
talkie.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00
wavtokenizer-dec.cpp model : NvFP4 quantized LM head support (#23046) 2026-05-16 11:09:27 +02:00
xverse.cpp hparams : refactor hparams.n_layer (#24060) 2026-06-05 11:09:36 +03:00