suffix88 commited on
Commit
188a928
1 Parent(s): d662c0b

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +114 -0
README.md ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: llm-jp/llm-jp-3-13b
3
+ tags:
4
+ - text-generation-inference
5
+ - transformers
6
+ - unsloth
7
+ - llama
8
+ - trl
9
+ license: apache-2.0
10
+ language:
11
+ - en
12
+ ---
13
+
14
+ # Uploaded model
15
+
16
+ - **Developed by:** karaage0703
17
+ - **License:** apache-2.0
18
+ - **Finetuned from model :** llm-jp/llm-jp-3-13b
19
+
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)
23
+
24
+
25
+
26
+ ## Usage
27
+ Execute following code in Google Colab
28
+
29
+ ```python
30
+ # 必要なライブラリをインストール
31
+ !pip install unsloth
32
+ !pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
33
+ !pip install -U torch
34
+ !pip install -U peft
35
+
36
+ # 必要なライブラリを読み込み
37
+ from unsloth import FastLanguageModel
38
+ from peft import PeftModel
39
+ import torch
40
+ import json
41
+ from tqdm import tqdm
42
+ import re
43
+
44
+ # ベースとなるモデルと学習したLoRAのアダプタ(Hugging FaceのIDを指定)。
45
+ model_id = "llm-jp/llm-jp-3-13b"
46
+ adapter_id = "karaage0703/llm-jp-3-13b-it-20241205_018"
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 # 今回は13Bモデルを扱うためTrue
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
+ prediction = re.sub(r"[*#]", "", prediction)
93
+
94
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
95
+
96
+ # 結果をjsonlで保存。
97
+ json_file_id = re.sub(".*/", "", adapter_id)
98
+ with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
99
+ for result in results:
100
+ json.dump(result, f, ensure_ascii=False)
101
+ f.write('\n')
102
+ ```
103
+
104
+
105
+ ## Datasets
106
+
107
+ ### Instruction tuning
108
+
109
+ The models have been fine-tuned on the following datasets.
110
+
111
+ | Language | Dataset | description |
112
+ |:---|:---|:---|
113
+ |Japanese| Screened data based on Tengentoppa-sft-v1.0 | A manually constructed instruction dataset based on [Tengentoppa-sft-v1.0](https://huggingface.co/datasets/DeL-TaiseiOzaki/Tengentoppa-sft-v1.0) |
114
+ | | Synthesized data from Elyza-tasks-100| Synthesize data from [Elyza-tasks-100](https://huggingface.co/datasets/elyza/ELYZA-tasks-100) by using LLM(Tanuki-8x8B) |