File size: 6,049 Bytes
cca899b
 
 
 
 
 
 
 
 
 
 
 
 
89d180e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0102e92
89d180e
 
 
 
 
 
 
 
 
 
cca899b
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
---
base_model: llm-jp/llm-jp-3-13b
tags:
- text-generation-inference
- transformers
- unsloth
- llama
- trl
license: apache-2.0
language:
- en
---

# llm-jp-3-13b-it-v3

このモデルは、llm-jp-3-13bをベースに、Ichikara Instructionのデータセットでファインチューニングを行ったLoRAアダプタです。

## 動作環境
- GPU: NVIDIA L4(24GB)以上のGPUメモリ
- RAM: 16GB以上推奨
- Python 3.10以上

## モデルの概要

- ベースモデル: llm-jp/llm-jp-3-13b
- 学習データ: ichikara-instruction-003-001-1
- 手法: QLoRA(unslothを使用)
- コンテキスト長: 512トークン

## データセット前処理

学習データは以下の手順で前処理を行いました:

1. データセットの読み込みと変換:
```python
from datasets import load_dataset

# データセットの読み込み
dataset = load_dataset("json", data_files="ichikara-instruction-003-001-1.json")

# プロンプトフォーマットの定義
prompt = """### 指示
{}
### 回答
{}"""

# フォーマット変換関数
def formatting_prompts_func(examples):
    input = examples["text"]
    output = examples["output"]
    text = prompt.format(input, output) + tokenizer.eos_token
    return {"formatted_text": text}

# データの変換
dataset = dataset.map(
    formatting_prompts_func,
    num_proc=4,
)
```

2. データセットの統計情報:
- 総サンプル数: 1,729
- instruction/outputの組み合わせを保持
- 日本語のインストラクションデータ

## 出力の再現性について
本READMEの手順に従うことで、提出したjsonlファイルと同様の出力を再現することができます。再現性を確保するため、以下の点に注意してください:
- モデルの推論設定(repetition_penalty=1.2, do_sample=False など)を変更しない
- 入力プロンプトのフォーマット(### 指示\n...\n### 回答\n)を維持する
- 乱数シードは3407に設定
- PyTorchのバージョンは2.5.1以上を推奨

## ベンチマーク出力方法

ELYZA-tasks-100-TVのベンチマーク出力を生成するための手順:

1. 環境準備
```python
import os
import torch
import json
from tqdm import tqdm
from unsloth import FastLanguageModel

# 必要なパッケージのインストール
!pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
!pip install --upgrade torch xformers
```

2. モデルとトークナイザーの準備
```python
# GPU設定の確認
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# モデルとトークナイザーの読み込み
model_id = "llm-jp/llm-jp-3-13b"
max_seq_length = 512
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name=model_id,
    dtype=None,
    load_in_4bit=True,
    trust_remote_code=True,
)

# 推論モードに設定
FastLanguageModel.for_inference(model)
```

3. 評価用データの読み込みと推論実行、出力生成
```python
# データセットの読み込み
datasets = []
with open("elyza-tasks-100-TV_0.jsonl", "r") as f:
    item = ""
    for line in f:
        line = line.strip()
        item += line
        if item.endswith("}"):
            datasets.append(json.loads(item))
            item = ""

# 推論実行
results = []
for dt in tqdm(datasets):
    input = dt["input"]
    prompt = f"""### 指示\n{input}\n### 回答\n"""
    
    inputs = tokenizer([prompt], return_tensors="pt").to(device)
    outputs = model.generate(
        **inputs,
        max_new_tokens=512,
        use_cache=True,
        do_sample=False,
        repetition_penalty=1.2
    )
    prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
    
    results.append({
        "task_id": dt["task_id"],
        "input": input,
        "output": prediction
    })

# 結果をjsonl形式で保存
with open("llm-jp-3-13b-it-v3_output.jsonl", 'w', encoding='utf-8') as f:
    for result in results:
        json.dump(result, f, ensure_ascii=False)
        f.write('\n')
```

必要なファイル:
- elyza-tasks-100-TV_0.jsonl(評価用データ)

出力ファイル:
- llm-jp-3-13b-it-v3_output.jsonl(ベンチマークの出力結果)

## 学習設定

モデルは以下の設定で学習を行いました:

- ライブラリ: unsloth
- rank (r): 32
- lora_alpha: 32
- lora_dropout: 0.05
- target_modules: ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]
- バッチサイズ: 2
- 勾配累積ステップ: 4
- エポック数: 1
- 学習率: 2e-4
- warmup_steps: 10
- max_seq_length: 512

## ライセンス

このモデルは、元のllm-jp-3-13bおよびIchikara Instructionデータセットのライセンスに従います。商用利用の際は、各ライセンスをご確認ください。

## 引用

このモデルを使用する場合は、以下を引用してください:

```bibtex
@misc{llm-jp-3-13b-it-v3,
  author = {[YOUR_NAME]},
  title = {llm-jp-3-13b-it-v3: Instruction-tuned LLM-JP-3-13B with QLoRA},
  year = {2024},
  publisher = {Hugging Face},
  journal = {Hugging Face Hub},
  howpublished = {\url{https://huggingface.co/[YOUR_USERNAME]/llm-jp-3-13b-it-v3}},
}

@inproceedings{sekine-etal-2024-ichikara,
  title = {ichikara-instruction: LLMのための日本語インストラクションデータの構築},
  author = {関根 聡 and 安藤 まや and 後藤 美知子 and 鈴木 久美 and 河原 大輔 and 井之上 直也 and 乾 健太郎},
  booktitle = {言語処理学会第30回年次大会},
  year = {2024}
}
```

# Uploaded  model

- **Developed by:** sabia0080
- **License:** apache-2.0
- **Finetuned from model :** llm-jp/llm-jp-3-13b

This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.

[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)