aino813 commited on
Commit
1c56d20
·
verified ·
1 Parent(s): 85b352a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +146 -10
README.md CHANGED
@@ -24,22 +24,158 @@ This llama model was trained 2x faster with [Unsloth](https://github.com/unsloth
24
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
25
 
26
 
27
- ## How to Use
28
 
29
- ### ライブラリーのインストール・アップグレード
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  ```
31
- !pip uninstall unsloth -y
32
- !pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
33
- !pip install --upgrade torch
34
- !pip install --upgrade xformers
 
35
  ```
36
 
37
- ### ライブラリーのインポート
38
  ```python
39
- from unsloth import FastLanguageModel
 
 
 
 
 
40
  import torch
41
- if torch.cuda.get_device_capability()[0] >= 8:
42
- !pip install --no-deps packaging ninja einops "flash-attn>=2.6.3"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  ```
44
 
 
 
 
 
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
25
 
26
 
27
+ # 学習用データについて
28
 
29
+ このモデルは、以下のデータを用いて指示チューニング(Instruction Tuning)を行いました。
30
+
31
+ ## 使用したデータセット
32
+
33
+ | データセット名 | 言語 | 件数 | 主な用途 |
34
+ |-----------------------------------|--------|--------------|------------------------------------------|
35
+ | databricks-dolly-15k | 英語 | 約15,000件 | 指示チューニング用 |
36
+ | databricks-dolly-15k-ja | 日本語 | 約15,000件 | 日本語指示チューニング用 |
37
+ | oasst1-21k-en | 英語 | 約21,000件 | 会話モデルや指示応答モデルのトレーニング |
38
+ | oasst1-21k-ja | 日本語 | 約21,000件 | 日本語会話モデルや指示応答モデルのトレーニング |
39
+ | ichikara-instruction-003-001 | 日本語 | 2,903件 | 日本語特化 |
40
+
41
+
42
+ 1. **databricks-dolly-15k**
43
+ - Databricksが公開した、指示応答形式のデータセット。
44
+ - 約15,000件の英語の指示・応答ペアを含む。
45
+ - 質問応答、説明、生成タスクなどが含まれる。
46
+
47
+ 2. **databricks-dolly-15k-ja**
48
+ - databricks-dolly-15kを日本語に翻訳したデータセット。
49
+ - 英語の指示・応答ペアを高品質な日本語翻訳に変換。
50
+ - 総件数: 約15000件。
51
+
52
+ 3. **oasst1-21k-en**
53
+ - Open Assistantが公開した、英語の指示応答データセット。
54
+ - 約21,000件の英語データを含む。
55
+ - コミュニティから収集したデータで、多様なタスクや質問形式が含まれる。
56
+
57
+ 4. **oasst1-21k-ja**
58
+ - oasst1-21k-enを日本語に翻訳したバージョン。
59
+ - 多様なタスクや指示形式に対応。
60
+ - 総件数: 約21,000件
61
+
62
+ 5. **ichikara-instruction-003-001**
63
+ - LLMのための日本語のシングルターン指示応答データセット。
64
+ - 約2,903件の高品質な日本語データを含む。
65
+
66
+
67
+ # ライセンス
68
+ Apache-2.0 ライセンスに基づいて提供されています。
69
+
70
+
71
+ # How to Use
72
+
73
+ #### ライブラリーのインストール・アップグレード
74
  ```
75
+ !pip install -U bitsandbytes
76
+ !pip install -U transformers
77
+ !pip install -U accelerate
78
+ !pip install -U datasets
79
+ !pip install -U peft
80
  ```
81
 
82
+ #### ライブラリーのインポート
83
  ```python
84
+ from transformers import (
85
+ AutoModelForCausalLM,
86
+ AutoTokenizer,
87
+ BitsAndBytesConfig,
88
+ )
89
+ from peft import PeftModel
90
  import torch
91
+ from tqdm import tqdm
92
+ import json
93
+ ```
94
+
95
+ #### HF_TOKENの設定
96
+ ```
97
+ HF_TOKEN = "******************"
98
+ ```
99
+
100
+ #### モデルidの指定
101
+ ```python
102
+ model_id = "models/models--llm-jp--llm-jp-3-13b/snapshots/cd3823f4c1fcbb0ad2e2af46036ab1b0ca13192a"
103
+ adapter_id = "aino813/llm-jp-3-13b-241213-SFT-dolly-oasst-ichikara-final_lora"
104
+ ```
105
+
106
+ #### 量子化の設定
107
+ ```python
108
+ bnb_config = BitsAndBytesConfig(
109
+ load_in_4bit=True,
110
+ bnb_4bit_quant_type="nf4",
111
+ bnb_4bit_compute_dtype=torch.bfloat16,
112
+ )
113
+ ```
114
+
115
+ #### 元のモデルとトークナイザーの読み込み
116
+ ```python
117
+ model = AutoModelForCausalLM.from_pretrained(
118
+ model_id,
119
+ quantization_config=bnb_config,
120
+ device_map="auto",
121
+ token = HF_TOKEN
122
+ )
123
+
124
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True, token = HF_TOKEN)
125
  ```
126
 
127
+ ####  元のモデルとLoRAアダプターの統合
128
+ ```python
129
+ model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
130
+ ```
131
 
132
+ #### データセットの読み込み
133
+ ```python
134
+ datasets = []
135
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
136
+ item = ""
137
+ for line in f:
138
+ line = line.strip()
139
+ item += line
140
+ if item.endswith("}"):
141
+ datasets.append(json.loads(item))
142
+ item = ""
143
+ ```
144
+
145
+ #### 推論
146
+ ```python
147
+ results = []
148
+ for data in tqdm(datasets):
149
+
150
+ input = data["input"]
151
+
152
+ prompt = f"""### 指示
153
+ {input}
154
+ ### 回答
155
+ """
156
+
157
+ tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
158
+ attention_mask = torch.ones_like(tokenized_input)
159
+ with torch.no_grad():
160
+ outputs = model.generate(
161
+ tokenized_input,
162
+ attention_mask=attention_mask,
163
+ max_new_tokens=1024,
164
+ do_sample=False,
165
+ repetition_penalty=1.2,
166
+ pad_token_id=tokenizer.eos_token_id
167
+ )[0]
168
+ output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
169
+
170
+ results.append({"task_id": data["task_id"], "input": input, "output": output})
171
+ ```
172
+
173
+ #### ファイルの作成
174
+ ```python
175
+ import re
176
+ jsonl_id = re.sub(".*/", "", adapter_id)
177
+ with open(f"./{jsonl_id}-outputs.jsonl", 'w', encoding='utf-8') as f:
178
+ for result in results:
179
+ json.dump(result, f, ensure_ascii=False) # ensure_ascii=False for handling non-ASCII characters
180
+ f.write('\n')
181
+ ```