Update README.md
Browse files
README.md
CHANGED
@@ -1,200 +1,176 @@
|
|
|
|
|
|
1 |
---
|
2 |
-
|
3 |
tags:
|
|
|
|
|
4 |
- unsloth
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
---
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
###
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
-
|
150 |
-
-
|
151 |
-
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
#### Hardware
|
165 |
-
|
166 |
-
[More Information Needed]
|
167 |
-
|
168 |
-
#### Software
|
169 |
-
|
170 |
-
[More Information Needed]
|
171 |
-
|
172 |
-
## Citation [optional]
|
173 |
-
|
174 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
175 |
-
|
176 |
-
**BibTeX:**
|
177 |
-
|
178 |
-
[More Information Needed]
|
179 |
-
|
180 |
-
**APA:**
|
181 |
-
|
182 |
-
[More Information Needed]
|
183 |
-
|
184 |
-
## Glossary [optional]
|
185 |
-
|
186 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
187 |
-
|
188 |
-
[More Information Needed]
|
189 |
-
|
190 |
-
## More Information [optional]
|
191 |
-
|
192 |
-
[More Information Needed]
|
193 |
-
|
194 |
-
## Model Card Authors [optional]
|
195 |
-
|
196 |
-
[More Information Needed]
|
197 |
-
|
198 |
-
## Model Card Contact
|
199 |
-
|
200 |
-
[More Information Needed]
|
|
|
1 |
+
最終提出README
|
2 |
+
|
3 |
---
|
4 |
+
base_model: llm-jp/llm-jp-3-13b
|
5 |
tags:
|
6 |
+
- text-generation-inference
|
7 |
+
- transformers
|
8 |
- unsloth
|
9 |
+
- llama
|
10 |
+
- trl
|
11 |
+
license: other
|
12 |
+
language:
|
13 |
+
- en
|
14 |
+
- ja
|
15 |
+
datasets:
|
16 |
+
- Aratako/Magpie-Tanuki-8B—annotated-96k
|
17 |
+
- tohoku-nlp/abc-multiple-choice
|
18 |
---
|
19 |
|
20 |
+
# Uploaded model
|
21 |
+
|
22 |
+
- **Developed by:** rlcgn589
|
23 |
+
- **License:** other
|
24 |
+
- **Finetuned from model :** llm-jp/llm-jp-3-13b
|
25 |
+
|
26 |
+
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
27 |
+
|
28 |
+
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
29 |
+
|
30 |
+
# Usage(Code for inference)
|
31 |
+
本モデルを用いてELYZA-tasks-100-TVの出力を得るためのコードです。
|
32 |
+
なお、松尾研LLM講座2024の最終コンペ課題の提出物を得ることを目的としたコードです。そのため、コンペの評価用途以外は使用禁止とします。
|
33 |
+
このコードで生成されたjsonlファイルは課題の成果として提出可能なフォーマットになっています。
|
34 |
+
|
35 |
+
## 環境構築
|
36 |
+
omnicampus環境下で事前にterminalで環境構築の必要があります。
|
37 |
+
```
|
38 |
+
# conda環境の構築
|
39 |
+
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
|
40 |
+
|
41 |
+
# このコマンドではいくつか質問があるので答えて下さい
|
42 |
+
bash Miniforge3-$(uname)-$(uname -m).sh
|
43 |
+
|
44 |
+
# 以下、インストール先が/root/miniforge3であることを前提とします
|
45 |
+
export PATH=/root/miniforge3/bin:$PATH
|
46 |
+
conda init
|
47 |
+
|
48 |
+
# ここで一度、terminalを立ち上げ直す必要があります。
|
49 |
+
# 以下のリンク先に従い環境を作ります
|
50 |
+
# https://docs.unsloth.ai/get-started/installation/conda-install
|
51 |
+
conda create --name unsloth_env python=3.10 pytorch-cuda=12.1 pytorch cudatoolkit xformers -c pytorch -c nvidia -c xformers -y
|
52 |
+
conda activate unsloth_env
|
53 |
+
pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
54 |
+
pip install --no-deps "trl<0.9.0" peft accelerate bitsandbytes
|
55 |
+
|
56 |
+
# jupyter notebook用のセットアップ。
|
57 |
+
conda install -c conda-forge ipykernel -y
|
58 |
+
python -m ipykernel install --user --name=unsloth_env --display-name "Python (unsloth_env)"
|
59 |
+
```
|
60 |
+
|
61 |
+
## 推論用コードの実行
|
62 |
+
```python
|
63 |
+
# 必要なライブラリを読み込み
|
64 |
+
from unsloth import FastLanguageModel
|
65 |
+
from peft import PeftModel
|
66 |
+
import torch
|
67 |
+
import json
|
68 |
+
from tqdm import tqdm
|
69 |
+
import re
|
70 |
+
|
71 |
+
# ベースとなるモデルと学習したLoRAのアダプタ。
|
72 |
+
# model_idの値はomnicampusの環境におけるモデルのパスを表しており、それ以外の環境で実行する場合は変更の必要があります。
|
73 |
+
model_id = "models/models--llm-jp--llm-jp-3-13b/snapshots/cd3823f4c1fcbb0ad2e2af46036ab1b0ca13192a"
|
74 |
+
adapter_id = "rlcgn589/llm-jp-3-13b-it-12_lora"
|
75 |
+
|
76 |
+
# Hugging Face Token を指定。
|
77 |
+
HF_TOKEN = "your Hugging Face Token"
|
78 |
+
|
79 |
+
# unslothのFastLanguageModelで元のモデルをロード。
|
80 |
+
dtype = None # Noneにしておけば自動で設定
|
81 |
+
load_in_4bit = True # 今回は13Bモデルを扱うためTrue
|
82 |
+
|
83 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
84 |
+
model_name=model_id,
|
85 |
+
dtype=dtype,
|
86 |
+
load_in_4bit=load_in_4bit,
|
87 |
+
trust_remote_code=True,
|
88 |
+
)
|
89 |
+
|
90 |
+
# 元のモデルにLoRAのアダプタを統合。
|
91 |
+
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
|
92 |
+
|
93 |
+
# データセットの読み込み。
|
94 |
+
# omnicampusの開発環境では、左にタスクのjsonlをドラッグアンドドロップしてから実行。
|
95 |
+
datasets = []
|
96 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
97 |
+
item = ""
|
98 |
+
for line in f:
|
99 |
+
line = line.strip()
|
100 |
+
item += line
|
101 |
+
if item.endswith("}"):
|
102 |
+
datasets.append(json.loads(item))
|
103 |
+
item = ""
|
104 |
+
|
105 |
+
# モデルを用いてタスクの推論。
|
106 |
+
|
107 |
+
# 推論するためにモデルのモードを変更
|
108 |
+
FastLanguageModel.for_inference(model)
|
109 |
+
|
110 |
+
results = []
|
111 |
+
for dt in tqdm(datasets):
|
112 |
+
input = dt["input"]
|
113 |
+
|
114 |
+
prompt = f"""### 指示\n{input}簡潔に回答してください。\n### 回答\n"""
|
115 |
+
|
116 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
117 |
+
|
118 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
119 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
120 |
+
|
121 |
+
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
122 |
+
|
123 |
+
# 結果をjsonlで保存。
|
124 |
+
jsonl_id = re.sub(".*/", "", adapter_id)
|
125 |
+
with open(f"./{jsonl_id}-outputs.jsonl", 'w', encoding='utf-8') as f:
|
126 |
+
for result in results:
|
127 |
+
json.dump(result, f, ensure_ascii=False) # ensure_ascii=False for handling non-ASCII characters
|
128 |
+
f.write('\n')
|
129 |
+
```
|
130 |
+
|
131 |
+
## Datasets
|
132 |
+
|
133 |
+
### Instruction tuning
|
134 |
+
本モデルは以下のデータセットでファインチューニングしました。
|
135 |
+
|
136 |
+
| Language | Dataset | description |
|
137 |
+
|:---|:---|:---|
|
138 |
+
|Japanese| Aratako/Magpie-Tanuki-8B-annotated-96k | MagpieとTanuki-8B-dpo-v1.0で作成されたデータにcalm3-22bでアノテーションを施した合成データを一部使用 |
|
139 |
+
|Japanese| tohoku-nlp/abc-multiple-choice | オリジナルの4択の選択肢問題を一部加工(クイズと回答は変えていない) |
|
140 |
+
|
141 |
+
### Data Source
|
142 |
+
ファインチューニング用のデータセット作成に作成者が使用したモデルとツールを示します。データを使わせていただきありがとうございます。
|
143 |
+
|
144 |
+
#### Tanuki-8B-dpo-v1.0
|
145 |
+
https://huggingface.co/weblab-GENIAC/Tanuki-8B-dpo-v1.0
|
146 |
+
|
147 |
+
#### Magpie
|
148 |
+
```tex
|
149 |
+
@misc{xu2024magpiealignmentdatasynthesis,
|
150 |
+
title={Magpie: Alignment Data Synthesis from Scratch by Prompting Aligned LLMs with Nothing},
|
151 |
+
author={Zhangchen Xu and Fengqing Jiang and Luyao Niu and Yuntian Deng and Radha Poovendran and Yejin Choi and Bill Yuchen Lin},
|
152 |
+
year={2024},
|
153 |
+
eprint={2406.08464},
|
154 |
+
archivePrefix={arXiv},
|
155 |
+
primaryClass={cs.CL},
|
156 |
+
url={https://arxiv.org/abs/2406.08464},
|
157 |
+
}
|
158 |
+
```
|
159 |
+
|
160 |
+
#### CyberAgentLM3-22B-Chat
|
161 |
+
```tex
|
162 |
+
@misc{cyberagent-calm3-22b-chat,
|
163 |
+
title={cyberagent/calm3-22b-chat},
|
164 |
+
url={https://huggingface.co/cyberagent/calm3-22b-chat},
|
165 |
+
author={Ryosuke Ishigami},
|
166 |
+
year={2024},
|
167 |
+
}
|
168 |
+
```
|
169 |
+
|
170 |
+
#### abc-multiple-choice
|
171 |
+
https://github.com/cl-tohoku/abc-multiple-choice
|
172 |
+
https://jedworkshop.github.io/JLR2024/materials/a-1.pdf
|
173 |
+
|
174 |
+
abc-multiple-choiceのライセンスに関する記載を抜粋して記します。
|
175 |
+
- 本データセットのクイズ問題の著作権は abc/EQIDEN 実行委員会 に帰属します。
|
176 |
+
- 本データセットは研究目的での利用許諾を得ているものです。商用目的での利用は不可とします。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|