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,101 @@ 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 |
+
datasets:
|
13 |
+
- elyza/ELYZA-tasks-100
|
14 |
+
- weblab-GENIAC/aya-ja-nemotron-dpo-masked
|
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 |
+
|
28 |
+
|
29 |
+
# Datasets
|
30 |
+
|
31 |
+
The models have been fine-tuned on the following datasets. Language is Japanese only.
|
32 |
+
|
33 |
+
| Purpose | Dataset | license | copyright holder |
|
34 |
+
| ---- | ---- | ---- | ---- |
|
35 |
+
| Instruction tuning | [ichikara-instruction-003-002-1](https://liat-aip.sakura.ne.jp/wp/llm%e3%81%ae%e3%81%9f%e3%82%81%e3%81%ae%e6%97%a5%e6%9c%ac%e8%aa%9e%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%a9%e3%82%af%e3%82%b7%e3%83%a7%e3%83%b3%e3%83%87%e3%83%bc%e3%82%bf%e4%bd%9c%e6%88%90/llm%e3%81%ae%e3%81%9f%e3%82%81%e3%81%ae%e6%97%a5%e6%9c%ac%e8%aa%9e%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%a9%e3%82%af%e3%82%b7%e3%83%a7%e3%83%b3%e3%83%87%e3%83%bc%e3%82%bf-%e5%85%ac%e9%96%8b/) | CC-BY-NC-SA | 理化学研究所 |
|
36 |
+
| | [ichikara-instruction-003-003-1](https://liat-aip.sakura.ne.jp/wp/llm%e3%81%ae%e3%81%9f%e3%82%81%e3%81%ae%e6%97%a5%e6%9c%ac%e8%aa%9e%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%a9%e3%82%af%e3%82%b7%e3%83%a7%e3%83%b3%e3%83%87%e3%83%bc%e3%82%bf%e4%bd%9c%e6%88%90/llm%e3%81%ae%e3%81%9f%e3%82%81%e3%81%ae%e6%97%a5%e6%9c%ac%e8%aa%9e%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%a9%e3%82%af%e3%82%b7%e3%83%a7%e3%83%b3%e3%83%87%e3%83%bc%e3%82%bf-%e5%85%ac%e9%96%8b/) | CC-BY-NC-SA | 理化学研究所 |
|
37 |
+
| | elyza/ELYZA-tasks-100 | CC BY-SA 4.0 | ELYZA |
|
38 |
+
| DPO | weblab-GENIAC/aya-ja-nemotron-dpo-masked | apache-2.0 | GENIAC 松尾研LLMプロジェクト |
|
39 |
+
|
40 |
+
|
41 |
+
# Usage
|
42 |
+
|
43 |
+
The following script should be run for inference
|
44 |
+
```
|
45 |
+
# 必要なライブラリをインストール
|
46 |
+
%%capture
|
47 |
+
!pip install unsloth
|
48 |
+
!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
49 |
+
!pip install -U torch
|
50 |
+
!pip install -U peft
|
51 |
+
|
52 |
+
# 必要なライブラリを読み込み
|
53 |
+
from unsloth import FastLanguageModel
|
54 |
+
from peft import PeftModel
|
55 |
+
import torch
|
56 |
+
import json
|
57 |
+
from tqdm import tqdm
|
58 |
+
import re
|
59 |
+
|
60 |
+
# ベースとなるモデルと学習したLoRAのアダプタ(Hugging FaceのIDを指定)。
|
61 |
+
model_id = "llm-jp/llm-jp-3-13b"
|
62 |
+
adapter_id = "cyumizou/llm-jp-3-13b-finetune-adapter_lora-dpo"
|
63 |
+
|
64 |
+
# Hugging Face Token を指定。
|
65 |
+
# 下記の URL から Hugging Face Token を取得できますので下記の HF_TOKEN に入れてください。
|
66 |
+
# https://huggingface.co/settings/tokens
|
67 |
+
HF_TOKEN = "Your token" #@param {type:"string"}
|
68 |
+
|
69 |
+
# unslothのFastLanguageModelで元のモデルをロード。
|
70 |
+
dtype = None # Noneにしておけば自動で設定
|
71 |
+
load_in_4bit = True # 今回は13Bモデルを扱うためTrue
|
72 |
+
|
73 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
74 |
+
model_name=model_id,
|
75 |
+
dtype=dtype,
|
76 |
+
load_in_4bit=load_in_4bit,
|
77 |
+
trust_remote_code=True,
|
78 |
+
)
|
79 |
+
|
80 |
+
# 元のモデルにLoRAのアダプタを統合。
|
81 |
+
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
|
82 |
+
|
83 |
+
# タスクとなるデータの読み込み。
|
84 |
+
# 事前にデータをアップロードしてください。
|
85 |
+
datasets = []
|
86 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
87 |
+
item = ""
|
88 |
+
for line in f:
|
89 |
+
line = line.strip()
|
90 |
+
item += line
|
91 |
+
if item.endswith("}"):
|
92 |
+
datasets.append(json.loads(item))
|
93 |
+
item = ""
|
94 |
+
|
95 |
+
# モデルを用いてタスクの推論。
|
96 |
+
|
97 |
+
# 推論するためにモデルのモードを変更
|
98 |
+
FastLanguageModel.for_inference(model)
|
99 |
+
|
100 |
+
results = []
|
101 |
+
for dt in tqdm(datasets):
|
102 |
+
input = dt["input"]
|
103 |
+
|
104 |
+
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
105 |
+
|
106 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
107 |
+
|
108 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
109 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
110 |
+
|
111 |
+
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
112 |
+
|
113 |
+
|
114 |
+
# 結果をjsonlで保存。
|
115 |
+
|
116 |
+
# ここではadapter_idを元にファイル名を決定しているが、ファイル名は任意で問題なし。
|
117 |
+
json_file_id = re.sub(".*/", "",adapter_id)
|
118 |
+
with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
119 |
+
for result in results:
|
120 |
+
json.dump(result, f, ensure_ascii=False)
|
121 |
+
f.write('\n')
|
122 |
+
|
123 |
+
```
|