koboldcpp/conversion
王金旭 9cd719af21
model: support speculators-format checkpoints for DSpark (#26275)
* dspark: support speculators-format checkpoints (SpecForge exports)

Speculators-format DSpark drafts (e.g. SpecForge exports for the
Gemma-4-26B-A4B target) differ from the dense DeepSpec checkpoints in
three ways:

- the config nests the backbone hparams under transformer_layer_config
  and gives the extract layers as aux_hidden_state_layer_ids
- the block is the DFlash 1+N fill-in layout: the anchor slot is a bonus
  token, not a prediction slot. Written as dflash.bonus_anchor; such
  drafts build the block and read the mask positions exactly like
  DFlash (n_max drafts from a 1+n_max block), only the Markov/confidence
  sampling comes from DSpark
- the draft output vocab may be reduced (draft_vocab_size < vocab_size)
  with a d2t remap table. The converter expands lm_head/markov_w2 back
  to the full vocab and synthesizes an lm_head bias of -1e9 on the rows
  the draft cannot produce, so the runtime needs no d2t remapping. Such
  drafts ship their own (now optional) token_embd/output tensors instead
  of sharing the target's

Verified against gemma4-26b-a4b-dspark: greedy outputs are byte-identical
with and without the draft; acceptance 0.46, mean draft len 3.7 (n_max 6).

Co-authored-by: desovo7 <942845546@qq.com>
Assisted-by: Claude Fable 5

* dspark: fold the speculators draft class into DSparkModel

One class now covers every DSpark variant. What used to pick the class is
a single flag, because the arch name turns out to be the only thing that
separates the two families: SpecForge also exports a flat schema that
carries no speculators_* fields yet still uses the 1+N bonus-anchor block,
so keying on those fields would silently mis-read its drafts.

Also rename i0 to i_first_pred in the draft read loop and the Markov head,
and give the head a real bonus_anchor bool instead of testing i0 > 0.

Converting the Qwen3-8B DeepSpec draft and both gemma-4 speculators drafts
produces byte-identical GGUFs. The one behaviour change is that the
markov_head_type check now also covers the DeepSpec checkpoints, which
previously skipped it.

Co-authored-by: desovo7 <942845546@qq.com>
Assisted-by: Claude Opus 5

* dspark: address review comments

- rename bonus_anchor to sample_from_anchor (GGUF key and code), matching
  the checkpoint config field; absent key still means anchor-first
- rework the reduced draft vocab to match EAGLE3: d2t is written as I64
  absolute target ids and the logits are scattered at runtime, instead of
  expanding lm_head/markov_w2 and synthesizing an output bias at conversion
- move the t2d skip to modify_tensors, like EAGLE3
- drop _is_specforge: the arch name only picks the sample_from_anchor
  default, embed/lm_head sharing is decided by the draft vocab size
- deduplicate the tok_embd create_tensor left behind by the rebase

Verified with the RedHat gemma-4-31b speculator draft: greedy output is
byte-identical with and without the draft; acceptance 0.26 (n_max 7).

Co-authored-by: desovo7 <942845546@qq.com>
Assisted-by: Claude Fable 5

* dspark: fold the sample_from_anchor read into the block_size block

* dspark: fix flake8 continuation indent

* clean up

* dspark: key the sample_from_anchor default off the export format

  Co-authored-by: desovo7 <942845546@qq.com>
  Assisted-by: Claude Fable

* dspark: drop t2d in filter_tensors

  Co-authored-by: desovo7 <942845546@qq.com>
  Assisted-by: Claude Fable

* dspark: map model.lm_head instead of bypassing the dflash prefix

  Co-authored-by: desovo7 <942845546@qq.com>
  Assisted-by: Claude Fable

---------

Co-authored-by: desovo7 <942845546@qq.com>
Co-authored-by: ruixiang63 <wangruixiang07@outlook.com>
2026-08-17 13:51:06 +02:00
..
__init__.py model: support speculators-format checkpoints for DSpark (#26275) 2026-08-17 13:51:06 +02:00
afmoe.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
arctic.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
baichuan.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
bailingmoe.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
bailingmoe3.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
base.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
bert.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
bitnet.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
bloom.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
chameleon.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
chatglm.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
codeshell.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
cogvlm.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
command_r.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
dbrx.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
deci.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
deepseek.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
dots1.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
dotsocr.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
dream.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
ernie.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
exaone.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
falcon.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
falcon_h1.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
gemma.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
glm.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
gpt2.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
gpt_oss.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
gptneox.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
granite.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
grok.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
grovemoe.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
hunyuan.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
internlm.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
internvl.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
jais.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
jamba.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
januspro.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
kimi_k3.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
kimi_linear.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
kimivl.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
laguna.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
lfm2.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
lighton_ocr.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
llada.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
llama.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
llama4.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
llava.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
maincoder.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
mamba.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
mellum.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
mimo.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
minicpm.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
minimax.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
mistral.py convert : fix conversion for Mistral-Medium-3.5-128B (#24268) 2026-06-07 21:41:39 +02:00
mistral3.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
mpt.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
muse_glimmer.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
nanbeige.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
nemotron.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
olmo.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
openelm.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
orion.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
pangu.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
phi.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
pixtral.py Refactor: convert_hf_to_gguf.py (#17114) 2026-05-15 15:18:12 +02:00
plamo.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
plm.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
pockettts.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
qwen.py model: support speculators-format checkpoints for DSpark (#26275) 2026-08-17 13:51:06 +02:00
qwen3tts.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
qwen3vl.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
qwenvl.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
refact.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
rwkv.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
sarashina2.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
smallthinker.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
smolvlm.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
stablelm.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
starcoder.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
step3.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
t5.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
talkie.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
ultravox.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
wavtokenizer.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
xverse.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00
youtuvl.py convert: add @ModelBase.example (#27208) 2026-08-17 10:15:11 +02:00