Ken5615 commited on
Commit
89fcd10
·
verified ·
1 Parent(s): e6a8a5e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +95 -1
README.md CHANGED
@@ -25,4 +25,98 @@ datasets:
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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
31
+ ## Usage
32
+ Execute following code in Google Colab
33
+
34
+ ```python
35
+ # 必要なライブラリをインストール
36
+ !pip install unsloth
37
+ !pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
38
+ !pip install -U torch
39
+ !pip install -U peft
40
+
41
+ # 必要なライブラリを読み込み
42
+ from unsloth import FastLanguageModel
43
+ from peft import PeftModel
44
+ import torch
45
+ import json
46
+ from tqdm import tqdm
47
+ import re
48
+
49
+ # ベースとなるモデルと学習したLoRAのアダプタ(Hugging FaceのIDを指定)。
50
+ model_id = "llm-jp/llm-jp-3-13b"
51
+ adapter_id = "Ken5615/llm-jp-3-13b-ft-bigest-latest"
52
+
53
+ from google.colab import userdata
54
+ HF_TOKEN=userdata.get('HF_TOKEN')
55
+
56
+ # unslothのFastLanguageModelで元のモデルをロード。
57
+ dtype = None # Noneにしておけば自動で設定
58
+ load_in_4bit = True # 今回は13Bモデルを扱うためTrue
59
+
60
+ model, tokenizer = FastLanguageModel.from_pretrained(
61
+ model_name=model_id,
62
+ dtype=dtype,
63
+ load_in_4bit=load_in_4bit,
64
+ trust_remote_code=True,
65
+ )
66
+
67
+ # 元のモデルにLoRAのアダプタを統合。
68
+ model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
69
+
70
+ # タスクとなるデータの読み込み。
71
+ # 事前にデータをアップロードしてください。
72
+ datasets = []
73
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
74
+ item = ""
75
+ for line in f:
76
+ line = line.strip()
77
+ item += line
78
+ if item.endswith("}"):
79
+ datasets.append(json.loads(item))
80
+ item = ""
81
+
82
+ # モデルを用いてタスクの推論。
83
+
84
+ # 推論するためにモデルのモードを変更
85
+ FastLanguageModel.for_inference(model)
86
+
87
+ results = []
88
+ for dt in tqdm(datasets):
89
+ input = dt["input"]
90
+
91
+ prompt = f"""### 以下の入力の内容に以下の条件を守って回答してください。\n### 条件\n・step-by-stepで考えて回答してください。\n・入力に示された回答方法を守って回答してください。\n### 入力\n{input}\n### 回答\n"""
92
+
93
+
94
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
95
+
96
+ outputs = model.generate(**inputs, max_new_tokens = 1024, use_cache = True, do_sample=False, repetition_penalty=1.2)
97
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
98
+ prediction = re.sub(r"[*#]", "", prediction)
99
+
100
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
101
+
102
+ # 結果をjsonlで保存。
103
+ json_file_id = re.sub(".*/", "", adapter_id)
104
+ with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
105
+ for result in results:
106
+ json.dump(result, f, ensure_ascii=False)
107
+ f.write('\n')
108
+ ```
109
+
110
+
111
+ ## Datasets
112
+
113
+ ### Instruction tuning
114
+
115
+ The models have been fine-tuned on the following datasets.
116
+
117
+ | Language | Dataset | description |
118
+ |:---|:---|:---|
119
+ |Japanese|[ichikara-instruction-004-002](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/)| A manually constructed instruction dataset |
120
+ | |[llm-jp/databricks-dolly-15k-ja](https://huggingface.co/datasets/llm-jp/databricks-dolly-15k-ja)| A manually constructed instruction dataset created by llm-jp|
121
+ | |[elyza/ELYZA-tasks-100](https://huggingface.co/datasets/elyza/ELYZA-tasks-100)| A manually constructed instruction dataset created by elyza|
122
+ | | Synthesized data from [elyza/ELYZA-tasks-100](https://huggingface.co/datasets/elyza/ELYZA-tasks-100)| Synthesize data from [Elyza-tasks-100](https://huggingface.co/datasets/elyza/ELYZA-tasks-100) by using LLM(Tanuki-8x8B) |