Update README.md
Browse files
README.md
CHANGED
@@ -27,20 +27,24 @@ This llama model was trained 2x faster with [Unsloth](https://github.com/unsloth
|
|
27 |
'''
|
28 |
python
|
29 |
## 必要パッケージのインストール
|
|
|
30 |
%%capture
|
31 |
!pip install unsloth
|
32 |
!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
33 |
!pip install -U torch
|
34 |
!pip install -U peft
|
35 |
-
|
36 |
-
|
|
|
37 |
from unsloth import FastLanguageModel
|
38 |
from peft import PeftModel
|
39 |
import torch
|
40 |
import json
|
41 |
from tqdm import tqdm
|
42 |
import re
|
43 |
-
|
|
|
|
|
44 |
model_id = "llm-jp/llm-jp-3-13b"
|
45 |
adapter_id = "TKKKMMM/llm-jp-3-13b-it_lora"
|
46 |
|
@@ -49,16 +53,19 @@ HF_TOKEN = "YOURE TOKEN"
|
|
49 |
dtype = None
|
50 |
load_in_4bit = True
|
51 |
|
52 |
-
## モデル、トークナイザーの読み込み
|
53 |
model, tokenizer = FastLanguageModel.from_pretrained(
|
54 |
model_name=model_id,
|
55 |
dtype=dtype,
|
56 |
load_in_4bit=load_in_4bit,
|
57 |
trust_remote_code=True,
|
58 |
)
|
|
|
59 |
## 元のモデルにLoRAのアダプタを統合。
|
|
|
60 |
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
|
|
|
61 |
## データセット読み込み
|
|
|
62 |
datasets = []
|
63 |
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
64 |
item = ""
|
@@ -68,8 +75,9 @@ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
|
68 |
if item.endswith("}"):
|
69 |
datasets.append(json.loads(item))
|
70 |
item = ""
|
71 |
-
|
72 |
## 回答の生成と格納
|
|
|
73 |
FastLanguageModel.for_inference(model)
|
74 |
|
75 |
results = []
|
@@ -86,13 +94,14 @@ for dt in tqdm(datasets):
|
|
86 |
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
87 |
|
88 |
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
89 |
-
|
90 |
## jsonファイルへのエクスポート
|
|
|
91 |
json_file_id = re.sub(".*/", "", adapter_id)
|
92 |
with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
93 |
for result in results:
|
94 |
json.dump(result, f, ensure_ascii=False)
|
95 |
f.write('\n')
|
96 |
-
|
97 |
|
98 |
|
|
|
27 |
'''
|
28 |
python
|
29 |
## 必要パッケージのインストール
|
30 |
+
```
|
31 |
%%capture
|
32 |
!pip install unsloth
|
33 |
!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
34 |
!pip install -U torch
|
35 |
!pip install -U peft
|
36 |
+
```
|
37 |
+
## ライブラリの読み込み
|
38 |
+
```
|
39 |
from unsloth import FastLanguageModel
|
40 |
from peft import PeftModel
|
41 |
import torch
|
42 |
import json
|
43 |
from tqdm import tqdm
|
44 |
import re
|
45 |
+
```
|
46 |
+
## モデル、トークナイザーの読み込み
|
47 |
+
```
|
48 |
model_id = "llm-jp/llm-jp-3-13b"
|
49 |
adapter_id = "TKKKMMM/llm-jp-3-13b-it_lora"
|
50 |
|
|
|
53 |
dtype = None
|
54 |
load_in_4bit = True
|
55 |
|
|
|
56 |
model, tokenizer = FastLanguageModel.from_pretrained(
|
57 |
model_name=model_id,
|
58 |
dtype=dtype,
|
59 |
load_in_4bit=load_in_4bit,
|
60 |
trust_remote_code=True,
|
61 |
)
|
62 |
+
```
|
63 |
## 元のモデルにLoRAのアダプタを統合。
|
64 |
+
```
|
65 |
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
|
66 |
+
```
|
67 |
## データセット読み込み
|
68 |
+
```
|
69 |
datasets = []
|
70 |
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
71 |
item = ""
|
|
|
75 |
if item.endswith("}"):
|
76 |
datasets.append(json.loads(item))
|
77 |
item = ""
|
78 |
+
```
|
79 |
## 回答の生成と格納
|
80 |
+
```
|
81 |
FastLanguageModel.for_inference(model)
|
82 |
|
83 |
results = []
|
|
|
94 |
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
95 |
|
96 |
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
97 |
+
```
|
98 |
## jsonファイルへのエクスポート
|
99 |
+
```
|
100 |
json_file_id = re.sub(".*/", "", adapter_id)
|
101 |
with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
102 |
for result in results:
|
103 |
json.dump(result, f, ensure_ascii=False)
|
104 |
f.write('\n')
|
105 |
+
```
|
106 |
|
107 |
|