Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,43 +1,123 @@
|
|
| 1 |
---
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
| 4 |
|
| 5 |
# eyepyon/rcgemma2_9b_it-finetuned
|
| 6 |
|
| 7 |
-
|
| 8 |
|
| 9 |
-
## モデル情報
|
| 10 |
|
| 11 |
-
-
|
| 12 |
-
-
|
| 13 |
-
-
|
| 14 |
-
-
|
| 15 |
-
-
|
|
|
|
| 16 |
|
| 17 |
-
## 使用方法
|
| 18 |
|
| 19 |
```python
|
| 20 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 21 |
from peft import PeftModel
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
base_model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
|
| 26 |
|
| 27 |
-
# LoRA
|
| 28 |
model = PeftModel.from_pretrained(base_model, "eyepyon/rcgemma2_9b_it-finetuned")
|
| 29 |
|
| 30 |
# 推論
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
```
|
| 36 |
|
| 37 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
- 学習率: 2e-4
|
| 41 |
-
- バッチサイズ: 1 × 4 (gradient accumulation)
|
| 42 |
-
- 重み減衰: 0.01
|
| 43 |
-
- 量子化: 4ビット
|
|
|
|
| 1 |
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: google/gemma-2-9b-it
|
| 4 |
+
tags:
|
| 5 |
+
- fine-tuned
|
| 6 |
+
- gemma
|
| 7 |
+
- lora
|
| 8 |
+
- japanese
|
| 9 |
+
- qa
|
| 10 |
+
library_name: transformers
|
| 11 |
+
pipeline_tag: text-generation
|
| 12 |
---
|
| 13 |
|
| 14 |
# eyepyon/rcgemma2_9b_it-finetuned
|
| 15 |
|
| 16 |
+
このモデルは、`google/gemma-2-9b-it` をベースにLoRAでファインチューニングされたモデルです。
|
| 17 |
|
| 18 |
+
## 🔧 モデル情報
|
| 19 |
|
| 20 |
+
- **ベースモデル**: google/gemma-2-9b-it
|
| 21 |
+
- **ファインチューニング手法**: LoRA (Low-Rank Adaptation)
|
| 22 |
+
- **アテンション実装**: eager (Gemma推奨)
|
| 23 |
+
- **量子化**: 4ビット (QLoRA)
|
| 24 |
+
- **対応言語**: 日本語
|
| 25 |
+
- **タスク**: 質問応答
|
| 26 |
|
| 27 |
+
## 🚀 使用方法
|
| 28 |
|
| 29 |
```python
|
| 30 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 31 |
from peft import PeftModel
|
| 32 |
|
| 33 |
+
# ベースモデルとトークナイザーを読み込み
|
| 34 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 35 |
+
"google/gemma-2-9b-it",
|
| 36 |
+
torch_dtype="auto",
|
| 37 |
+
device_map="auto",
|
| 38 |
+
attn_implementation="eager", # Gemma推奨
|
| 39 |
+
trust_remote_code=True
|
| 40 |
+
)
|
| 41 |
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
|
| 42 |
|
| 43 |
+
# LoRAアダプターを適用
|
| 44 |
model = PeftModel.from_pretrained(base_model, "eyepyon/rcgemma2_9b_it-finetuned")
|
| 45 |
|
| 46 |
# 推論
|
| 47 |
+
def generate_response(context, question):
|
| 48 |
+
input_text = f"### コンテキスト:\n{context}\n\n### 質問:\n{question}\n\n### 回答:\n"
|
| 49 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
| 50 |
+
|
| 51 |
+
# GPUに移動
|
| 52 |
+
if torch.cuda.is_available():
|
| 53 |
+
inputs = {k: v.to(model.device) for k, v in inputs.items()}
|
| 54 |
+
|
| 55 |
+
with torch.no_grad():
|
| 56 |
+
outputs = model.generate(
|
| 57 |
+
**inputs,
|
| 58 |
+
max_length=512,
|
| 59 |
+
do_sample=True,
|
| 60 |
+
temperature=0.7,
|
| 61 |
+
top_p=0.9,
|
| 62 |
+
pad_token_id=tokenizer.eos_token_id
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 66 |
+
if "### 回答:" in response:
|
| 67 |
+
response = response.split("### 回答:")[-1].strip()
|
| 68 |
+
return response
|
| 69 |
+
|
| 70 |
+
# 使用例
|
| 71 |
+
context = "人工知能は機械学習技術を使用してデータから学習します。"
|
| 72 |
+
question = "機械学習の特徴は何ですか?"
|
| 73 |
+
answer = generate_response(context, question)
|
| 74 |
+
print(answer)
|
| 75 |
```
|
| 76 |
|
| 77 |
+
## 📊 入力フォーマット
|
| 78 |
+
|
| 79 |
+
```
|
| 80 |
+
### コンテキスト:
|
| 81 |
+
[背景情報やコンテキスト]
|
| 82 |
+
|
| 83 |
+
### 質問:
|
| 84 |
+
[ユーザーの質問]
|
| 85 |
+
|
| 86 |
+
### 回答:
|
| 87 |
+
[期待される回答]
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## ⚙️ トレーニング設定
|
| 91 |
+
|
| 92 |
+
- **LoRAランク**: 8
|
| 93 |
+
- **LoRA Alpha**: 16
|
| 94 |
+
- **ターゲットモジュール**: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
|
| 95 |
+
- **学習率**: 2e-4
|
| 96 |
+
- **バッチサイズ**: 1 × 4 (gradient accumulation)
|
| 97 |
+
- **グラディエントチェックポイント**: use_reentrant=False
|
| 98 |
+
|
| 99 |
+
## ⚠️ 重要な注意事項
|
| 100 |
+
|
| 101 |
+
### Gemma特有の設定
|
| 102 |
+
- **eager attention必須**: `attn_implementation="eager"`を使用してください
|
| 103 |
+
- **use_cache=False**: グラディエントチェックポイントとの互換性のため
|
| 104 |
+
- **use_reentrant=False**: 新しい推奨設定
|
| 105 |
+
|
| 106 |
+
### 制限事項
|
| 107 |
+
- 主に日本語での質問応答に最適化
|
| 108 |
+
- 生成される回答の事実確認が必要
|
| 109 |
+
- 特定のドメイン知識でのファインチューニング
|
| 110 |
+
|
| 111 |
+
## 📄 ライセンス
|
| 112 |
+
|
| 113 |
+
Apache 2.0 License
|
| 114 |
+
|
| 115 |
+
## 🔗 関連リンク
|
| 116 |
+
|
| 117 |
+
- [ベースモデル](google/gemma-2-9b-it)
|
| 118 |
+
- [PEFT Documentation](https://huggingface.co/docs/peft)
|
| 119 |
+
- [Transformers Documentation](https://huggingface.co/docs/transformers)
|
| 120 |
+
|
| 121 |
+
---
|
| 122 |
|
| 123 |
+
**最終更新**: 2025年05月25日
|
|
|
|
|
|
|
|
|
|
|
|