Views
No views yet
<start_of_turn>user
質問<end_of_turn>
<start_of_turn>model
回答<end_of_turn>| パラメータ | 値 |
|---|---|
| ベースモデル | google/gemma-2-2b-it |
| LoRAランク (r) | 16 |
| LoRA alpha | 32 |
| LoRA dropout | 0.1 |
| ターゲットモジュール | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| 学習率 | 5e-5 |
| バッチサイズ | 2 x 8 (gradient accumulation) = 16 |
| エポック数 | 37(途中停止) |
| 最適化手法 | AdamW |
| Warmup ratio | 0.3 |
| Weight decay | 0.05 |
| 精度 | bfloat16 |
| 評価 | 件数 | 割合 |
|---|---|---|
| ✅ 完璧な回答 | 4/9 | 44% |
| ⚠️ 部分的に正確 | 1/9 | 11% |
| ❌ 不正確 | 4/9 | 44% |
pip install transformers peft torch1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3import torch
4
5# ベースモデルとLoRAアダプタをロード
6base_model = AutoModelForCausalLM.from_pretrained(
7 "google/gemma-2-2b-it",
8 device_map="auto",
9 torch_dtype=torch.bfloat16
10)
11
12model = PeftModel.from_pretrained(base_model, "ayousanz/gemma-2-2b-it-game-ft")
13tokenizer = AutoTokenizer.from_pretrained("ayousanz/gemma-2-2b-it-game-ft")
14
15# 推論
16prompt = "What is the offensive strategy?"
17formatted_prompt = f"<start_of_turn>user\n{prompt}<end_of_turn>\n<start_of_turn>model\n"
18
19inputs = tokenizer(formatted_prompt, return_tensors="pt").to(model.device)
20outputs = model.generate(
21 **inputs,
22 max_new_tokens=150,
23 do_sample=False,
24 pad_token_id=tokenizer.pad_token_id,
25 eos_token_id=tokenizer.eos_token_id
26)
27
28response = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
29print(response)
30# 出力: Offensive strategy: High risk, high reward strategy type with frequent attacks.1# LoRAアダプタをベースモデルにマージ
2merged_model = model.merge_and_unload()
3
4# 推論(より高速)
5inputs = tokenizer(formatted_prompt, return_tensors="pt").to(merged_model.device)
6outputs = merged_model.generate(**inputs, max_new_tokens=150)1@misc{gemma-2-2b-it-game-ft,
2 author = {ayousanz},
3 title = {Gemma-2-2B-IT Game Strategy Fine-tuning},
4 year = {2025},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/ayousanz/gemma-2-2b-it-game-ft}}
7}