Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
2from peft import PeftModel
3import torch
4
5# 4-bit quantization for memory efficiency
6bnb_config = BitsAndBytesConfig(
7 load_in_4bit=True,
8 bnb_4bit_compute_dtype=torch.bfloat16,
9)
10
11# Load base model
12base_model = AutoModelForCausalLM.from_pretrained(
13 "moonshotai/Kimi-K2.5",
14 quantization_config=bnb_config,
15 device_map="auto",
16 trust_remote_code=True,
17)
18
19# Load LoRA adapter
20model = PeftModel.from_pretrained(base_model, "YOUR_USERNAME/kimi-k2-reasoning-lora")
21tokenizer = AutoTokenizer.from_pretrained("YOUR_USERNAME/kimi-k2-reasoning-lora")
22
23# Generate
24messages = [{"role": "user", "content": "What is the square root of 144?"}]
25inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
26outputs = model.generate(inputs, max_new_tokens=512)
27print(tokenizer.decode(outputs[0]))| Parameter | Value |
|---|---|
| Base Model | moonshotai/Kimi-K2.5 |
| Method | QLoRA (4-bit) |
| LoRA Rank | 64 |
| LoRA Alpha | 16 |
| Learning Rate | 2e-4 |
| Epochs | 3 |
| Dataset Size | 250 examples |