Views
No views yet
google/gemma-4-26B-A4B-it on Kimi K2 reasoning distill dataset — 7,836 high-quality reasoning examples, trained entirely by UKA (Hermes Agent) 🤖| Detail | Value |
|---|---|
| Base Model | google/gemma-4-26B-A4B-it (26B MoE, 128 experts, ~4B active/token) |
| Dataset | lordx64/reasoning-distill-kimi-k2-6-max-sft (7,836 examples) |
| Method | Custom NF4 per-expert quantization + LoRA |
| Pipeline | AndriejusNak/gemma4-26b-moe-finetune |
| GPU | NVIDIA RTX 5090 32GB (Vast.ai Cloud) |
| Training Time | 128 minutes (~2h 8m) |
| Best Loss | 1.0651 |
| NaN Explosions | 0 |
| Component | Specification |
|---|---|
| GPU | NVIDIA GeForce RTX 5090 32GB GDDR7 |
| CPU | Intel Core i7-14700K (28 cores, 20 logical) |
| RAM | 94 GB DDR5 |
| Disk | 200 GB NVMe SSD |
| Cloud | Vast.ai |
| CUDA | 13.0 |
| PyTorch | 2.12.0.dev (nightly, cu128) |
Why RTX 5090: Gemma 4 26B MoE ต้องการ custom NF4 per-expert quantization — standardbitsandbytesไม่สามารถ quantizenn.Parameter(expert weights) ได้. Pipeline quantize experts ด้วยตัวเอง ทำให้ VRAM peak ~24 GB — พอดีกับ RTX 5090 32GB แต่เกิน RTX 3090 24GB (ถ้าใช้ seq=1024 + MLP LoRA)
1# v6_26b_pipeline.py — Final Config
2MODEL_NAME = "google/gemma-4-26B-A4B-it"
3MAX_SEQ_LENGTH = 1024
4LORA_R = 32
5LORA_ALPHA = 32
6INCLUDE_MLP_LORA = True # Attention + MLP layers
7SFT_EPOCHS = 2
8SFT_BATCH_SIZE = 3 # Per GPU
9SFT_GRAD_ACCUM = 8 # Effective batch = 24
10SFT_LR = 2e-5 # Cosine schedule, warmup 245 steps
11SFT_FILES = ["data/kimi_k2_sft.jsonl"]q_proj, k_proj, v_proj, o_proj (attention) + gate_proj, up_proj, down_proj (MLP)Step 50: Loss 3.0597 (epoch 1)
Step 100: Loss 1.3277
Step 150: Loss 1.1658
Step 200: Loss 1.0906
Step 250: Loss 1.1220
Step 300: Loss 1.0723
→ Epoch 1 avg: 1.4648
Step 350: Loss 1.0660 (epoch 2)
Step 400: Loss 1.0616
Step 450: Loss 1.0722
Step 500: Loss 1.0586
Step 550: Loss 1.0370
Step 600: Loss 1.0983
→ Epoch 2 avg: 1.0651 🎯 Best!pip install transformers peft torch1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5# Load base model (BF16, needs ~52 GB VRAM)
6model = AutoModelForCausalLM.from_pretrained(
7 "google/gemma-4-26B-A4B-it",
8 torch_dtype=torch.bfloat16,
9 device_map="auto"
10)
11
12# Load this LoRA adapter
13model = PeftModel.from_pretrained(
14 model,
15 "hotdogs/gemma4-26b-kimi-k2-reasoning-lora"
16)
17
18# Optional: merge for faster inference
19model = model.merge_and_unload()1tokenizer = AutoTokenizer.from_pretrained("google/gemma-4-26B-A4B-it")
2
3messages = [
4 {"role": "system", "content": "You are a helpful AI assistant."},
5 {"role": "user", "content": "Solve: 3x + 7 = 22"}
6]
7
8inputs = tokenizer.apply_chat_template(
9 messages,
10 tokenize=True,
11 return_tensors="pt",
12 add_generation_prompt=True
13).to(model.device)
14
15outputs = model.generate(
16 inputs,
17 max_new_tokens=512,
18 temperature=0.7,
19 do_sample=True
20)
21
22print(tokenizer.decode(outputs[0], skip_special_tokens=True))text column in Kimi chat format (<|im_start|>role\n...<|im_end|>).1# convert_kimi.py — Parquet → JSONL messages format
2import requests, pyarrow.parquet as pq, io, json, re
3
4url = "https://huggingface.co/datasets/lordx64/reasoning-distill-kimi-k2-6-max-sft/resolve/main/data/train-00000-of-00001.parquet"
5r = requests.get(url)
6table = pq.read_table(io.BytesIO(r.content))
7texts = table.column('text').to_pylist()
8
9pattern = r'<\|im_start\|>(\w+)\n(.*?)<\|im_end\|>'
10with open("data/kimi_k2_sft.jsonl", "w") as f:
11 for text in texts:
12 matches = re.findall(pattern, text, re.DOTALL)
13 messages = [{"role": role.strip(), "content": content.strip()}
14 for role, content in matches]
15 f.write(json.dumps({"messages": messages}, ensure_ascii=False) + "\n")1git clone https://github.com/AndriejusNak/gemma4-26b-moe-finetune.git
2cd gemma4-26b-moe-finetune
3pip install transformers peft bitsandbytes accelerate safetensors pyarrow requests
4
5# Edit v6_26b_pipeline.py:
6# SFT_FILES = ["data/kimi_k2_sft.jsonl"]
7# MAX_SEQ_LENGTH = 1024
8# LORA_R = 32, LORA_ALPHA = 32
9# INCLUDE_MLP_LORA = True
10# SFT_EPOCHS = 2, SFT_BATCH_SIZE = 31python3 v6_26b_pipeline.py --phase 0 # Download model (~7 min)
2python3 -u v6_26b_pipeline.py --phase 1 # Train (~2 hrs) | tee /tmp/sft.logbitsandbytes can't quantize nn.Parameter (expert weights). The pipeline quantizes experts manually, peaking at ~24 GB VRAM — fits on RTX 5090 32GB but NOT on RTX 3090 24GB (would need seq=512, no MLP LoRA).sm_120. PyTorch stable only supports up to sm_90. Nightly cu128 is required.adapter_model.safetensors — LoRA weights (227 MB)
adapter_config.json — LoRA config: r=32, alpha=32, attention+MLP
tokenizer.json — Gemma 4 tokenizer (31 MB)
tokenizer_config.json — Tokenizer config
chat_template.jinja — Chat template