H-INO commited on
Commit
86cca62
·
verified ·
1 Parent(s): fab76be

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +156 -1
README.md CHANGED
@@ -13,10 +13,165 @@ language:
13
 
14
  # Uploaded model
15
 
16
- - **Developed by:** H-INO
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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  # Uploaded model
15
 
 
16
  - **License:** apache-2.0
17
  - **Finetuned from model :** llm-jp/llm-jp-3-13b
18
 
19
  This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
20
 
21
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
22
+
23
+ # The models have been fine-tuned on the following datasets.
24
+
25
+ Dataset:ichikara-instruction-003-001-1.json
26
+ description:A manually constructed instruction dataset
27
+
28
+ データセット作成チーム: 関根聡, 安藤まや, 後藤美知子, 鈴木久美, 河原大輔, 井之上直也, 乾健太郎.
29
+ ichikara-instruction: LLMのための日本語インストラクションデータの構築. 言語処理学会第30回年次大会(2024)
30
+
31
+ I’m grateful to everyone here.
32
+
33
+ # Usage
34
+
35
+ ```python
36
+ !pip uninstall unsloth -y
37
+ !pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
38
+ !pip install ipywidgets --upgrade
39
+
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
+ HF_TOKEN = "HF_TOKEN" #@param {type:"string"}
45
+
46
+ from unsloth import FastLanguageModel
47
+ import torch
48
+ max_seq_length = 512
49
+ dtype = None
50
+ load_in_4bit = True
51
+
52
+ model_id = "llm-jp/llm-jp-3-13b"
53
+ new_model_id = "model name"
54
+ model, tokenizer = FastLanguageModel.from_pretrained(
55
+ model_name=model_id,
56
+ dtype=dtype,
57
+ load_in_4bit=load_in_4bit,
58
+ trust_remote_code=True,
59
+ )
60
+
61
+ model = FastLanguageModel.get_peft_model(
62
+ model,
63
+ r = 32,
64
+ target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
65
+ "gate_proj", "up_proj", "down_proj",],
66
+ lora_alpha = 32,
67
+ lora_dropout = 0.05,
68
+ bias = "none",
69
+ use_gradient_checkpointing = "unsloth",
70
+ random_state = 3407,
71
+ use_rslora = False,
72
+ loftq_config = None,
73
+ max_seq_length = max_seq_length,
74
+ )
75
+
76
+ from datasets import load_dataset
77
+ dataset = load_dataset("json", data_files="./ichikara-instruction-003-001-1.json")
78
+
79
+ prompt = """### 指示
80
+ {}
81
+ ### 回答
82
+ {}"""
83
+
84
+ EOS_TOKEN = tokenizer.eos_token
85
+ def formatting_prompts_func(examples):
86
+ input = examples["text"]
87
+ output = examples["output"]
88
+ text = prompt.format(input, output) + EOS_TOKEN
89
+ return { "formatted_text" : text, }
90
+ pass
91
+
92
+ dataset = dataset.map(
93
+ formatting_prompts_func,
94
+ num_proc= 4,
95
+ )
96
+
97
+ from trl import SFTTrainer
98
+ from transformers import TrainingArguments
99
+ from unsloth import is_bfloat16_supported
100
+
101
+ trainer = SFTTrainer(
102
+ model = model,
103
+ tokenizer = tokenizer,
104
+ train_dataset=dataset["train"],
105
+ max_seq_length = max_seq_length,
106
+ dataset_text_field="formatted_text",
107
+ packing = False,
108
+ args = TrainingArguments(
109
+ per_device_train_batch_size = 2,
110
+ gradient_accumulation_steps = 4,
111
+ num_train_epochs = 1,
112
+ logging_steps = 10,
113
+ warmup_steps = 10,
114
+ save_steps=100,
115
+ save_total_limit=2,
116
+ max_steps=-1,
117
+ learning_rate = 2e-4,
118
+ fp16 = not is_bfloat16_supported(),
119
+ bf16 = is_bfloat16_supported(),
120
+ group_by_length=True,
121
+ seed = 3407,
122
+ output_dir = "outputs",
123
+ report_to = "none",
124
+ ),
125
+ )
126
+
127
+ trainer_stats = trainer.train()
128
+
129
+ import json
130
+ datasets = []
131
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
132
+ item = ""
133
+ for line in f:
134
+ line = line.strip()
135
+ item += line
136
+ if item.endswith("}"):
137
+ datasets.append(json.loads(item))
138
+ item = ""
139
+
140
+ from tqdm import tqdm
141
+
142
+ FastLanguageModel.for_inference(model)
143
+
144
+ results = []
145
+ for dt in tqdm(datasets):
146
+ input = dt["input"]
147
+
148
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
149
+
150
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
151
+
152
+ outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
153
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
154
+
155
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
156
+
157
+ from tqdm import tqdm
158
+
159
+ FastLanguageModel.for_inference(model)
160
+
161
+ results = []
162
+ for dt in tqdm(datasets):
163
+ input = dt["input"]
164
+
165
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
166
+
167
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
168
+
169
+ outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
170
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
171
+
172
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
173
+
174
+ with open(f"{new_model_id}_output.jsonl", 'w', encoding='utf-8') as f:
175
+ for result in results:
176
+ json.dump(result, f, ensure_ascii=False)
177
+ f.write('\n')