Update README.md
Browse files
README.md
CHANGED
@@ -22,7 +22,7 @@ This llama model was trained 2x faster with [Unsloth](https://github.com/unsloth
|
|
22 |
|
23 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
24 |
|
25 |
-
#
|
26 |
本コードはunslothで学習したqLoRAのアダプタを用いてELYZA-tasks-100-TVの出力を得るためのコードです。
|
27 |
Hugging Faceにアダプタをアップロードしてあることが前提となります。
|
28 |
このコードはunslothライブラリを用いてモデルを読み込み、推論するためのコードとなります。
|
@@ -30,21 +30,24 @@ Hugging Faceにアダプタをアップロードしてあることが前提と
|
|
30 |
|
31 |
※本コードはGoogle Colabでの動作を想定しており、Omnicampusでの動作を想定しておりません。
|
32 |
|
|
|
|
|
33 |
下記セルを上から順に実行することで推論を行えます
|
|
|
|
|
34 |
```
|
35 |
-
# 必要なライブラリをインストール
|
36 |
%%capture
|
37 |
!pip install unsloth
|
38 |
!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
39 |
!pip install -U torch
|
40 |
!pip install -U peft
|
41 |
```
|
|
|
42 |
```
|
43 |
-
#
|
44 |
model_id = "llm-jp/llm-jp-3-13b"
|
45 |
adapter_id = "hiroya3508/llm-jp-3-13b-it-tuning_lora"
|
46 |
-
|
47 |
-
```
|
48 |
# unslothのFastLanguageModelで元のモデルをロード。
|
49 |
dtype = None # Noneにしておけば自動で設定
|
50 |
load_in_4bit = True # 今回は13Bモデルを扱うためTrue
|
@@ -56,11 +59,12 @@ model, tokenizer = FastLanguageModel.from_pretrained(
|
|
56 |
trust_remote_code=True,
|
57 |
)
|
58 |
```
|
|
|
|
|
59 |
```
|
60 |
# 元のモデルにLoRAのアダプタを統合。
|
61 |
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
|
62 |
-
|
63 |
-
```
|
64 |
# タスクとなるデータの読み込み。
|
65 |
# 事前にデータをアップロードしてください。
|
66 |
datasets = []
|
@@ -73,9 +77,9 @@ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
|
73 |
datasets.append(json.loads(item))
|
74 |
item = ""
|
75 |
```
|
76 |
-
```
|
77 |
-
# モデルを用いてタスクの推論。
|
78 |
|
|
|
|
|
79 |
# 推論するためにモデルのモードを変更
|
80 |
FastLanguageModel.for_inference(model)
|
81 |
|
@@ -92,9 +96,8 @@ for dt in tqdm(datasets):
|
|
92 |
|
93 |
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
94 |
```
|
|
|
95 |
```
|
96 |
-
# 結果をjsonlで保存。
|
97 |
-
|
98 |
# ここではadapter_idを元にファイル名を決定しているが、ファイル名は任意で問題なし。
|
99 |
json_file_id = re.sub(".*/", "", adapter_id)
|
100 |
with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
|
|
22 |
|
23 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
24 |
|
25 |
+
# 概要
|
26 |
本コードはunslothで学習したqLoRAのアダプタを用いてELYZA-tasks-100-TVの出力を得るためのコードです。
|
27 |
Hugging Faceにアダプタをアップロードしてあることが前提となります。
|
28 |
このコードはunslothライブラリを用いてモデルを読み込み、推論するためのコードとなります。
|
|
|
30 |
|
31 |
※本コードはGoogle Colabでの動作を想定しており、Omnicampusでの動作を想定しておりません。
|
32 |
|
33 |
+
# 実行手順
|
34 |
+
|
35 |
下記セルを上から順に実行することで推論を行えます
|
36 |
+
# 1. セットアップ
|
37 |
+
## 1-1. 必要なライブラリをインストール
|
38 |
```
|
|
|
39 |
%%capture
|
40 |
!pip install unsloth
|
41 |
!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
42 |
!pip install -U torch
|
43 |
!pip install -U peft
|
44 |
```
|
45 |
+
## 1-2. モデルとトークナイザーの読み込み
|
46 |
```
|
47 |
+
# ベースとなるモデルと学習済みLoRAのアダプタ(Hugging FaceのIDを指定)。
|
48 |
model_id = "llm-jp/llm-jp-3-13b"
|
49 |
adapter_id = "hiroya3508/llm-jp-3-13b-it-tuning_lora"
|
50 |
+
|
|
|
51 |
# unslothのFastLanguageModelで元のモデルをロード。
|
52 |
dtype = None # Noneにしておけば自動で設定
|
53 |
load_in_4bit = True # 今回は13Bモデルを扱うためTrue
|
|
|
59 |
trust_remote_code=True,
|
60 |
)
|
61 |
```
|
62 |
+
|
63 |
+
## 1-3. モデル結合とタスクの読み込み
|
64 |
```
|
65 |
# 元のモデルにLoRAのアダプタを統合。
|
66 |
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
|
67 |
+
|
|
|
68 |
# タスクとなるデータの読み込み。
|
69 |
# 事前にデータをアップロードしてください。
|
70 |
datasets = []
|
|
|
77 |
datasets.append(json.loads(item))
|
78 |
item = ""
|
79 |
```
|
|
|
|
|
80 |
|
81 |
+
# 2.モデルを用いてタスク推論。
|
82 |
+
```
|
83 |
# 推論するためにモデルのモードを変更
|
84 |
FastLanguageModel.for_inference(model)
|
85 |
|
|
|
96 |
|
97 |
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
98 |
```
|
99 |
+
# 3. 結果をjsonlで保存。
|
100 |
```
|
|
|
|
|
101 |
# ここではadapter_idを元にファイル名を決定しているが、ファイル名は任意で問題なし。
|
102 |
json_file_id = re.sub(".*/", "", adapter_id)
|
103 |
with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
|