Update README.md
Browse files
README.md
CHANGED
@@ -9,6 +9,9 @@ tags:
|
|
9 |
license: apache-2.0
|
10 |
language:
|
11 |
- en
|
|
|
|
|
|
|
12 |
---
|
13 |
|
14 |
# Uploaded model
|
@@ -20,3 +23,89 @@ language:
|
|
20 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
license: apache-2.0
|
10 |
language:
|
11 |
- en
|
12 |
+
- ja
|
13 |
+
datasets:
|
14 |
+
- elyza/ELYZA-tasks-100
|
15 |
---
|
16 |
|
17 |
# Uploaded model
|
|
|
23 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
24 |
|
25 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
26 |
+
|
27 |
+
# Useage
|
28 |
+
以下のコードを Google Colab で実行してください。
|
29 |
+
|
30 |
+
``` python
|
31 |
+
# 必要なライブラリをインストール
|
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 |
+
from unsloth import FastLanguageModel
|
39 |
+
from peft import PeftModel
|
40 |
+
import torch
|
41 |
+
import json
|
42 |
+
from tqdm import tqdm
|
43 |
+
|
44 |
+
# ベースとなるモデルと学習したLoRAのアダプタ(Hugging FaceのIDを指定)。
|
45 |
+
model_id = "llm-jp/llm-jp-3-13b"
|
46 |
+
adapter_id = "kittokito/llm-jp-3-13b-it-202412170007"
|
47 |
+
|
48 |
+
from google.colab import userdata
|
49 |
+
HF_TOKEN=userdata.get('HF_TOKEN')
|
50 |
+
|
51 |
+
# unslothのFastLanguageModelで元のモデルをロード。
|
52 |
+
dtype = None # Noneにしておけば自動で設定
|
53 |
+
load_in_4bit = True # 4bit量子化でモデルのパラメーターをダウンロード
|
54 |
+
|
55 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
56 |
+
model_name=model_id,
|
57 |
+
dtype=dtype,
|
58 |
+
load_in_4bit=load_in_4bit,
|
59 |
+
trust_remote_code=True,
|
60 |
+
)
|
61 |
+
|
62 |
+
# 元のモデルにLoRAのアダプタを統合。
|
63 |
+
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
|
64 |
+
|
65 |
+
# タスクとなるデータの読み込み。
|
66 |
+
# 事前にデータをアップロードしてください。
|
67 |
+
datasets = []
|
68 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
69 |
+
item = ""
|
70 |
+
for line in f:
|
71 |
+
line = line.strip()
|
72 |
+
item += line
|
73 |
+
if item.endswith("}"):
|
74 |
+
datasets.append(json.loads(item))
|
75 |
+
item = ""
|
76 |
+
|
77 |
+
# モデルを用いてタスクの推論。
|
78 |
+
|
79 |
+
# 推論するためにモデルのモードを変更
|
80 |
+
FastLanguageModel.for_inference(model)
|
81 |
+
|
82 |
+
results = []
|
83 |
+
for dt in tqdm(datasets):
|
84 |
+
input = dt["input"]
|
85 |
+
|
86 |
+
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
87 |
+
|
88 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
89 |
+
|
90 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
91 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
92 |
+
|
93 |
+
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
94 |
+
|
95 |
+
# 結果をjsonlで保存。
|
96 |
+
with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
97 |
+
for result in results:
|
98 |
+
json.dump(result, f, ensure_ascii=False)
|
99 |
+
f.write('\n')
|
100 |
+
|
101 |
+
```
|
102 |
+
|
103 |
+
# Datasets
|
104 |
+
|
105 |
+
## Instruction Tuning
|
106 |
+
The models have been fine-tuned on the following datasets.
|
107 |
+
|
108 |
+
| **Language** | **Dataset** | **Description** |
|
109 |
+
|--------------|----------------------------------------------|-------------------------------------------------------------------------------|
|
110 |
+
| Japanese | [ichikara-instruction-003-001-1.json](http://liat-aip.sakura.ne.jp/wp/llmのための日本語インストラクションデータ作成/llmのための日本語インストラクションデータ-公開/) | A manually constructed instruction dataset. |
|
111 |
+
| | Synthesized data from [Elyza-tasks-100](https://huggingface.co/datasets/elyza/ELYZA-tasks-100) | Synthesized data from [Elyza-tasks-100](https://huggingface.co/datasets/elyza/ELYZA-tasks-100) by using LLM (Mixtral-8x22B). |
|