Distilling Kimi K3 into Qwen 3.6 27B
Distilling Kimi K3 into Qwen 3.6 27B MTP, basically improving coding and agentic accuracy/flow a bit, hopefully.
just vibe coded example for later after a long chat session, no clue if this works as listed. I believe something like this might run a few hours. I believe you'll need at least 32gb vram to achieve this, not sure!
import torch from datasets import load_dataset from trl import SFTTrainer from transformers import TrainingArguments from unsloth import FastLanguageModel, is_bfloat16_supported
1. Model Configuration
max_seq_length = 4096 # Cap sequence length to prevent VRAM spikes on long debugging traces model_name = "Qwen/Qwen3.6-27B-Instruct"
Load base model in 4-bit QLoRA (Loads core backbone + native MTP layers)
model, tokenizer = FastLanguageModel.from_pretrained( model_name=model_name, max_seq_length=max_seq_length, dtype=None, # Auto-selects bfloat16 for modern GPUs load_in_4bit=True, )
2. Target Core Backbone for LoRA (Leaves MTP Draft Heads Frozen)
model = FastLanguageModel.get_peft_model( model, r=16, target_modules=[ "q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj", ], lora_alpha=32, lora_dropout=0, bias="none", use_gradient_checkpointing="unsloth", random_state=3407, )
3. Load and Format Dataset
dataset = load_dataset("greghavens/kimi-k3-coding-and-debugging-traces", split="train")
def format_prompts(examples): formatted_texts = [] for messages in examples["messages"]: # Apply native Qwen 3.6 ChatML template with tool preservation text = tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=False, ) formatted_texts.append(text) return {"text": formatted_texts}
dataset = dataset.map(format_prompts, batched=True)
4. Configure Trainer
trainer = SFTTrainer( model=model, tokenizer=tokenizer, train_dataset=dataset, dataset_text_field="text", max_seq_length=max_seq_length, dataset_num_proc=2, packing=False, args=TrainingArguments( per_device_train_batch_size=2, gradient_accumulation_steps=8, # Effective batch size = 16 warmup_steps=10, max_steps=300, learning_rate=2e-4, fp16=not is_bfloat16_supported(), bf16=is_bfloat16_supported(), logging_steps=1, optim="adamw_8bit", weight_decay=0.01, lr_scheduler_type="linear", seed=3407, output_dir="outputs", ), )
5. Train
trainer_stats = trainer.train()
6. Save & Export directly to Q5_K_XL GGUF (preserves merged LoRA + MTP headers)
model.save_pretrained_gguf( "qwen3.6-27b-k3-agent-q5-xl", tokenizer, quantization_method="q5_k_xl", # Specify Q5 XL / UD-Q5_K_XL )
print("Training complete! Q5 XL MTP GGUF saved successfully.")