update
Browse files
README.md
CHANGED
@@ -13,16 +13,19 @@ language:
|
|
13 |
---
|
14 |
|
15 |
# 推論用コード
|
|
|
16 |
Hugging Faceにアップロードしたモデルを用いてELYZA-tasks-100-TVの出力を得るためのコードです。
|
17 |
このコードで生成されたjsonlファイルは課題の成果として提出可能なフォーマットになっております。
|
18 |
|
19 |
-
|
|
|
|
|
20 |
!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
21 |
!pip install -U xformers --index-url https://download.pytorch.org/whl/cu124
|
22 |
!pip install --no-deps "trl<0.9.0" peft accelerate bitsandbytes
|
23 |
```
|
24 |
|
25 |
-
```
|
26 |
!pip uninstall unsloth -y
|
27 |
!pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
28 |
# Google Colab のデフォルトで入っているパッケージをアップグレード
|
@@ -30,18 +33,21 @@ Hugging Faceにアップロードしたモデルを用いてELYZA-tasks-100-TV
|
|
30 |
!pip install --upgrade xformers
|
31 |
```
|
32 |
|
33 |
-
```
|
34 |
# Install Flash Attention 2 for softcapping support
|
35 |
import torch
|
36 |
if torch.cuda.get_device_capability()[0] >= 8:
|
37 |
!pip install --no-deps packaging ninja einops "flash-attn>=2.6.3"
|
38 |
```
|
39 |
|
40 |
-
|
|
|
41 |
HF_TOKEN = "your_token" #@param {type:"string"}
|
42 |
```
|
43 |
|
44 |
-
|
|
|
|
|
45 |
# llm-jp/llm-jp-3-13bを4bit量子化のqLoRA設定でロード。
|
46 |
|
47 |
from unsloth import FastLanguageModel
|
@@ -77,13 +83,13 @@ model = FastLanguageModel.get_peft_model(
|
|
77 |
)
|
78 |
```
|
79 |
|
80 |
-
```
|
81 |
from datasets import load_dataset
|
82 |
|
83 |
dataset = load_dataset("json", data_files="./ichikara-instruction-003-001-1.json")
|
84 |
```
|
85 |
|
86 |
-
```
|
87 |
# 学習時のプロンプトフォーマットの定義
|
88 |
prompt = """### 指示
|
89 |
{}
|
@@ -109,14 +115,12 @@ dataset = dataset.map(
|
|
109 |
)
|
110 |
|
111 |
dataset
|
112 |
-
```
|
113 |
|
114 |
-
```
|
115 |
# データを確認
|
116 |
print(dataset["train"]["formatted_text"][3])
|
117 |
```
|
118 |
|
119 |
-
```
|
120 |
"""
|
121 |
training_arguments: 学習の設定
|
122 |
|
@@ -208,7 +212,7 @@ trainer = SFTTrainer(
|
|
208 |
)
|
209 |
```
|
210 |
|
211 |
-
```
|
212 |
#@title 現在のメモリ使用量を表示
|
213 |
gpu_stats = torch.cuda.get_device_properties(0)
|
214 |
start_gpu_memory = round(torch.cuda.max_memory_reserved() / 1024 / 1024 / 1024, 3)
|
@@ -217,12 +221,13 @@ print(f"GPU = {gpu_stats.name}. Max memory = {max_memory} GB.")
|
|
217 |
print(f"{start_gpu_memory} GB of memory reserved.")
|
218 |
```
|
219 |
|
220 |
-
```
|
221 |
#@title 学習実行
|
222 |
trainer_stats = trainer.train()
|
223 |
```
|
224 |
|
225 |
-
|
|
|
226 |
# ELYZA-tasks-100-TVの読み込み。事前にファイルをアップロードしてください
|
227 |
# データセットの読み込み。
|
228 |
# omnicampusの開発環境では、左にタスクのjsonlをドラッグアンドドロップしてから実行。
|
@@ -238,7 +243,9 @@ with open("/content//elyza-tasks-100-TV_0.jsonl", "r") as f:
|
|
238 |
item = ""
|
239 |
```
|
240 |
|
241 |
-
|
|
|
|
|
242 |
# 学習したモデルを用いてタスクを実行
|
243 |
from tqdm import tqdm
|
244 |
|
@@ -259,16 +266,15 @@ for dt in tqdm(datasets):
|
|
259 |
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
260 |
```
|
261 |
|
262 |
-
|
|
|
|
|
263 |
# jsonlで保存
|
264 |
with open(f"{new_model_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
265 |
for result in results:
|
266 |
json.dump(result, f, ensure_ascii=False)
|
267 |
f.write('\n')```
|
268 |
|
269 |
-
```
|
270 |
-
|
271 |
-
```
|
272 |
# LoRAアダプタだけ保存
|
273 |
model.push_to_hub_merged(
|
274 |
new_model_id+"_lora",
|
|
|
13 |
---
|
14 |
|
15 |
# 推論用コード
|
16 |
+
|
17 |
Hugging Faceにアップロードしたモデルを用いてELYZA-tasks-100-TVの出力を得るためのコードです。
|
18 |
このコードで生成されたjsonlファイルは課題の成果として提出可能なフォーマットになっております。
|
19 |
|
20 |
+
## セットアップ
|
21 |
+
|
22 |
+
```python
|
23 |
!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
24 |
!pip install -U xformers --index-url https://download.pytorch.org/whl/cu124
|
25 |
!pip install --no-deps "trl<0.9.0" peft accelerate bitsandbytes
|
26 |
```
|
27 |
|
28 |
+
```python
|
29 |
!pip uninstall unsloth -y
|
30 |
!pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
31 |
# Google Colab のデフォルトで入っているパッケージをアップグレード
|
|
|
33 |
!pip install --upgrade xformers
|
34 |
```
|
35 |
|
36 |
+
```python
|
37 |
# Install Flash Attention 2 for softcapping support
|
38 |
import torch
|
39 |
if torch.cuda.get_device_capability()[0] >= 8:
|
40 |
!pip install --no-deps packaging ninja einops "flash-attn>=2.6.3"
|
41 |
```
|
42 |
|
43 |
+
write権限のあるtokenを入力する
|
44 |
+
```python
|
45 |
HF_TOKEN = "your_token" #@param {type:"string"}
|
46 |
```
|
47 |
|
48 |
+
## モデル・トークナイザの読み込み
|
49 |
+
|
50 |
+
```python
|
51 |
# llm-jp/llm-jp-3-13bを4bit量子化のqLoRA設定でロード。
|
52 |
|
53 |
from unsloth import FastLanguageModel
|
|
|
83 |
)
|
84 |
```
|
85 |
|
86 |
+
```python
|
87 |
from datasets import load_dataset
|
88 |
|
89 |
dataset = load_dataset("json", data_files="./ichikara-instruction-003-001-1.json")
|
90 |
```
|
91 |
|
92 |
+
```python
|
93 |
# 学習時のプロンプトフォーマットの定義
|
94 |
prompt = """### 指示
|
95 |
{}
|
|
|
115 |
)
|
116 |
|
117 |
dataset
|
|
|
118 |
|
|
|
119 |
# データを確認
|
120 |
print(dataset["train"]["formatted_text"][3])
|
121 |
```
|
122 |
|
123 |
+
```python
|
124 |
"""
|
125 |
training_arguments: 学習の設定
|
126 |
|
|
|
212 |
)
|
213 |
```
|
214 |
|
215 |
+
```python
|
216 |
#@title 現在のメモリ使用量を表示
|
217 |
gpu_stats = torch.cuda.get_device_properties(0)
|
218 |
start_gpu_memory = round(torch.cuda.max_memory_reserved() / 1024 / 1024 / 1024, 3)
|
|
|
221 |
print(f"{start_gpu_memory} GB of memory reserved.")
|
222 |
```
|
223 |
|
224 |
+
```python
|
225 |
#@title 学習実行
|
226 |
trainer_stats = trainer.train()
|
227 |
```
|
228 |
|
229 |
+
## 入力データの準備
|
230 |
+
```python
|
231 |
# ELYZA-tasks-100-TVの読み込み。事前にファイルをアップロードしてください
|
232 |
# データセットの読み込み。
|
233 |
# omnicampusの開発環境では、左にタスクのjsonlをドラッグアンドドロップしてから実行。
|
|
|
243 |
item = ""
|
244 |
```
|
245 |
|
246 |
+
### 推論実行
|
247 |
+
|
248 |
+
```python
|
249 |
# 学習したモデルを用いてタスクを実行
|
250 |
from tqdm import tqdm
|
251 |
|
|
|
266 |
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
267 |
```
|
268 |
|
269 |
+
## モデルの保存
|
270 |
+
|
271 |
+
```python
|
272 |
# jsonlで保存
|
273 |
with open(f"{new_model_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
274 |
for result in results:
|
275 |
json.dump(result, f, ensure_ascii=False)
|
276 |
f.write('\n')```
|
277 |
|
|
|
|
|
|
|
278 |
# LoRAアダプタだけ保存
|
279 |
model.push_to_hub_merged(
|
280 |
new_model_id+"_lora",
|