Views
No views yet
0.6B parameter draft (speculative decoding) model for use with Kimi-K2-Instruct.config.json is set for context length up to 32k tokens. Add the "rope_scaling" section to config.json to enable YaRN, eg:1 "max_position_embeddings": 65536,
2 ...
3 "rope_scaling": {
4 "factor": 2.0,
5 "original_max_position_embeddings": 32768,
6 "type": "yarn"
7 },1 "max_position_embeddings": 131072,
2 ...
3 "rope_scaling": {
4 "factor": 4.0,
5 "original_max_position_embeddings": 32768,
6 "type": "yarn"
7 },llama.cpp uses "static-YaRN" the scaling factor remains constant regardless of input length! Only add the rope_scaling configuration when processing long contexts is required...1python ./transplant_vocab.py \
2 ./Qwen2.5-0.5B-Instruct \
3 ./Kimi-K2-Instruct \
4 ./Kimi-K2-Instruct-DRAFT-0.6B-UNTRAINED \
5 --trust-remote-code \
6 --override "[BOS]" "<|endoftext|>" \
7 --override "[EOS]" "<|im_end|>" \
8 --override "<|im_end|>" "<|im_end|>" \
9 --override "<|im_user|>" "<|im_start|>user" \
10 --override "<|im_assistant|>" "<|im_start|>assistant" \
11 --override "<|start_header_id|>" "<|im_start|>" \
12 --override "<|end_header_id|>" "<|im_end|>" \
13 --override "[EOT]" "<|endoftext|>" \
14 --override "<|im_system|>" "<|im_start|>system" \
15 --override "<|tool_calls_section_begin|>" "<tool_call>" \
16 --override "<|tool_calls_section_end|>" "</tool_call>" \
17 --override "<|tool_call_begin|>" "<tool_call>" \
18 --override "<|tool_call_argument_begin|>" "<tool_call>" \
19 --override "<|tool_call_end|>" "</tool_call>" \
20 --override "<|im_middle|>" "\\n" \
21 --override "[UNK]" "<|endoftext|>" \
22 --override "[PAD]" "<|endoftext|>"
23
24Loading config from 'Qwen2.5-0.5B-Instruct'... Done.
25Loading config from 'Kimi-K2-Instruct'... Done.
26Loading tokenizer from 'Qwen2.5-0.5B-Instruct'... Done.
27Loading tokenizer from 'Kimi-K2-Instruct'... Done.
28Loading model from 'Qwen2.5-0.5B-Instruct'... Done.
29
30Input model configuration:
31- Target vocabulary size : 163840 (used = 163840, unused = 0)
32- Donor vocabulary size : 151936
33- Donor num layers : 24 (tied embeddings = True)
34- Donor hidden size : 896
35- Donor attention heads : 14
36- Donor intermediate size : 4864 (ratio = 1:5.4)
37- Donor total parameters : 494032768 (0.49B)
38-- Embedding parameters : 136134656 (0.14B)
39-- Non-embedding parameters : 357898112 (0.36B)
40
41Processing 3 automatic token overrides:
42✔ 'bos_token_id' : 163584 '[BOS]' → [151643] '<|endoftext|>'
43✔ 'eos_token_id' : 163585 '[EOS]' → [151645] '<|im_end|>'
44✔ 'pad_token_id' : 163839 '[PAD]' → [151643] '<|endoftext|>'
45
46Processing 17 manual token overrides:
47✔ 163584 : '[BOS]' → [151643] '<|endoftext|>'
48✔ 163585 : '[EOS]' → [151645] '<|im_end|>'
49✔ 163586 : '<|im_end|>' → [151645] '<|im_end|>'
50✔ 163587 : '<|im_user|>' → [151644, 872] '<|im_start|>user'
51✔ 163588 : '<|im_assistant|>' → [151644, 77091] '<|im_start|>assistant'
52✔ 163590 : '<|start_header_id|>' → [151644] '<|im_start|>'
53✔ 163591 : '<|end_header_id|>' → [151645] '<|im_end|>'
54✔ 163593 : '[EOT]' → [151643] '<|endoftext|>'
55✔ 163594 : '<|im_system|>' → [151644, 8948] '<|im_start|>system'
56✔ 163595 : '<|tool_calls_section_begin|>' → [151657] '<tool_call>'
57✔ 163596 : '<|tool_calls_section_end|>' → [151658] '</tool_call>'
58✔ 163597 : '<|tool_call_begin|>' → [151657] '<tool_call>'
59✔ 163598 : '<|tool_call_argument_begin|>' → [151657] '<tool_call>'
60✔ 163599 : '<|tool_call_end|>' → [151658] '</tool_call>'
61✔ 163601 : '<|im_middle|>' → [198] '\n'
62✔ 163838 : '[UNK]' → [151643] '<|endoftext|>'
63✔ 163839 : '[PAD]' → [151643] '<|endoftext|>'
64
65NOTE: Using an "untied" copy of 'embed_tokens.weight' as new 'lm_head.weight' tensor...
66
67Transplanting tokens: 100%|████████████████████████████████████████████████████████████| 163840/163840 [01:08<00:00, 2406.47token/s]
68
69Transplant mappings:
70- 1 to 1 : 95449 (58%)
71- 2 to 1 : 61938 (38%)
72- 3 to 1 : 4995 (3%)
73- 4 to 1 : 980 (0.6%)
74- 5 to 1 : 147 (0.09%)
75- 6 to 1 : 52 (0.032%)
76- 7 to 1 : 15 (0.0092%)
77- 8 to 1 : 17 (0.01%)
78- 9 to 1 : 2 (0.0012%)
79- 10 to 1 : 5 (0.0031%)
80- 11 to 1 : 1 (0.00061%)
81- 13 to 1 : 239 (0.15%)
82
83Head initialized with:
84- Copies : 95449 (58%)
85- Means : 68391 (42%)
86- Zeros : 0 (0%)
87
88Output model configuration:
89- Output vocabulary size : 163840
90- Output num layers : 24 (tied embeddings = False)
91- Output hidden size : 896
92- Output attention heads : 14
93- Output intermediate size : 4864 (ratio = 1:5.4)
94- Output total parameters : 651499392 (0.65B)
95-- Embedding parameters : 293601280 (0.29B)
96-- Non-embedding parameters : 357898112 (0.36B)
97
98Saving model and tokenizer to 'Kimi-K2-Instruct-DRAFT-0.6B-UNTRAINED' folder
99[2025-08-07 15:47:15,620] [INFO] [real_accelerator.py:203:get_accelerator] Setting ds_accelerator to cuda (auto detect)
100
101Patching 'torch_dtype' in 'Kimi-K2-Instruct-DRAFT-0.6B-UNTRAINED/config.json' based on actual saved tensors
102- Updated 'torch_dtype' to 'bfloat16' based on actual tensor dtype
103
104Operation completed successfully (ignore any 'segmentation fault' that follows!!!)--trust-remote-code option."pad_token_id": 163839 from config.json to get it to match the tokeniser when used in llama.cpp as a draft model.output field only)[EOS] tags.1# ==============================
2# MODEL AND OUTPUT CONFIGURATION
3# ==============================
4
5model_dir = 'models/Kimi-K2-Instruct-DRAFT-0.6B-UNTRAINED'
6output_dir = 'finetuned'
7
8# ===========================
9# TRAINING TYPE CONFIGURATION
10# ===========================
11
12full_fine_tune = true
13
14# =======================
15# OPTIMIZER CONFIGURATION
16# =======================
17
18lr = 5e-5
19
20# ======================
21# TRAINING CONFIGURATION
22# ======================
23
24sequence_len = 32768
25
26gradient_accumulation_steps = 10 # 10×6 = batch size 60, 10×6×32768 = ~2M tokens per step
27
28# =====================
29# DATASET CONFIGURATION
30# =====================
31
32[[datasets]]
33dataset_path = 'datasets/common-crawl-sample/*.json'
34drop_tails = true
35
36[[datasets]]
37dataset_path = 'datasets/the-stack-smol-xl/*.jsonl'
38drop_tails = true
39
40[[datasets]]
41dataset_path = 'datasets/rombodawg-Everything-Instruct/*.json'
42drop_tails = true--trust-remote-code option passing on the deepspeed call to train.py.RTX A6000 GPUs over three nodes and hence the 60 batch size (6 x 10 gradient accumulation steps = 60):
TikToken / SentencePiece tokenizer mismatch in llama.cppconvert_hf_to_gguf.py:1@ModelBase.register("Qwen2Model", "Qwen2ForCausalLM", "Qwen2AudioForConditionalGeneration")
2class Qwen2Model(TextModel):
3 model_arch = gguf.MODEL_ARCH.QWEN2
4
5 #def set_vocab(self):
6 # try:
7 # self._set_vocab_sentencepiece()
8 # except FileNotFoundError:
9 # self._set_vocab_gpt2()
10 def set_vocab(self):
11 from transformers import AutoTokenizer
12 tokenizer = AutoTokenizer.from_pretrained(self.dir_model, trust_remote_code=True)
13 tokpre = self.get_vocab_base_pre(tokenizer)
14
15 # Build merges list using the approach similar to HunYuanMoE
16 merges = []
17 vocab = {}
18 mergeable_ranks = tokenizer.model._mergeable_ranks
19 for token, rank in mergeable_ranks.items():
20 vocab[QwenModel.token_bytes_to_string(token)] = rank
21 if len(token) == 1:
22 continue
23 merged = QwenModel.bpe(mergeable_ranks, token, max_rank=rank)
24 if len(merged) == 2:
25 merges.append(' '.join(map(QwenModel.token_bytes_to_string, merged)))
26
27 # Build token list
28 vocab_size = self.hparams["vocab_size"]
29 special_tokens = tokenizer.special_tokens
30 reverse_vocab = {id_ : encoded_tok for encoded_tok, id_ in {**vocab, **special_tokens}.items()}
31 tokens: list[str] = []
32 toktypes: list[int] = []
33
34 for i in range(vocab_size):
35 if i not in reverse_vocab:
36 tokens.append(f"[PAD{i}]")
37 toktypes.append(gguf.TokenType.UNUSED)
38 else:
39 token = reverse_vocab[i]
40 tokens.append(token)
41 if i in special_tokens.values():
42 toktypes.append(gguf.TokenType.CONTROL)
43 else:
44 toktypes.append(gguf.TokenType.NORMAL)
45
46 self.gguf_writer.add_tokenizer_model("gpt2")
47 self.gguf_writer.add_tokenizer_pre(tokpre)
48 self.gguf_writer.add_token_list(tokens)
49 self.gguf_writer.add_token_types(toktypes)
50 self.gguf_writer.add_token_merges(merges)
51
52 special_vocab = gguf.SpecialVocab(self.dir_model, load_merges=False)
53 special_vocab.add_to_gguf(self.gguf_writer)~/llama.cpp/convert_hf_to_gguf.py --outtype auto --outfile Kimi-K2-Instruct-DRAFT-0.6B-BF16.gguf Kimi-K2-Instruct-DRAFT-0.6B~/llama.cpp/build/bin/llama-quantize Kimi-K2-Instruct-DRAFT-0.6B-BF16.gguf Kimi-K2-Instruct-DRAFT-0.6B-Q4_0.gguf Q4_0 44