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|
+
inference: false
|
4 |
+
model-index:
|
5 |
+
- name: checkpoints-finetuning
|
6 |
+
results: []
|
7 |
+
model_creator: ce-lery
|
8 |
+
model_name: japanese-mistral-300m-instruction
|
9 |
+
pipeline_tag: text-generation
|
10 |
+
quantized_by: afrideva
|
11 |
+
tags:
|
12 |
+
- generated_from_trainer
|
13 |
+
- gguf
|
14 |
+
- ggml
|
15 |
+
- quantized
|
16 |
+
- q2_k
|
17 |
+
- q3_k_m
|
18 |
+
- q4_k_m
|
19 |
+
- q5_k_m
|
20 |
+
- q6_k
|
21 |
+
- q8_0
|
22 |
+
---
|
23 |
+
# ce-lery/japanese-mistral-300m-instruction-GGUF
|
24 |
+
|
25 |
+
Quantized GGUF model files for [japanese-mistral-300m-instruction](https://huggingface.co/ce-lery/japanese-mistral-300m-instruction) from [ce-lery](https://huggingface.co/ce-lery)
|
26 |
+
|
27 |
+
|
28 |
+
| Name | Quant method | Size |
|
29 |
+
| ---- | ---- | ---- |
|
30 |
+
| [japanese-mistral-300m-instruction.fp16.gguf](https://huggingface.co/afrideva/japanese-mistral-300m-instruction-GGUF/resolve/main/japanese-mistral-300m-instruction.fp16.gguf) | fp16 | 712.33 MB |
|
31 |
+
| [japanese-mistral-300m-instruction.q2_k.gguf](https://huggingface.co/afrideva/japanese-mistral-300m-instruction-GGUF/resolve/main/japanese-mistral-300m-instruction.q2_k.gguf) | q2_k | 176.84 MB |
|
32 |
+
| [japanese-mistral-300m-instruction.q3_k_m.gguf](https://huggingface.co/afrideva/japanese-mistral-300m-instruction-GGUF/resolve/main/japanese-mistral-300m-instruction.q3_k_m.gguf) | q3_k_m | 195.04 MB |
|
33 |
+
| [japanese-mistral-300m-instruction.q4_k_m.gguf](https://huggingface.co/afrideva/japanese-mistral-300m-instruction-GGUF/resolve/main/japanese-mistral-300m-instruction.q4_k_m.gguf) | q4_k_m | 234.80 MB |
|
34 |
+
| [japanese-mistral-300m-instruction.q5_k_m.gguf](https://huggingface.co/afrideva/japanese-mistral-300m-instruction-GGUF/resolve/main/japanese-mistral-300m-instruction.q5_k_m.gguf) | q5_k_m | 266.47 MB |
|
35 |
+
| [japanese-mistral-300m-instruction.q6_k.gguf](https://huggingface.co/afrideva/japanese-mistral-300m-instruction-GGUF/resolve/main/japanese-mistral-300m-instruction.q6_k.gguf) | q6_k | 307.38 MB |
|
36 |
+
| [japanese-mistral-300m-instruction.q8_0.gguf](https://huggingface.co/afrideva/japanese-mistral-300m-instruction-GGUF/resolve/main/japanese-mistral-300m-instruction.q8_0.gguf) | q8_0 | 379.17 MB |
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
## Original Model Card:
|
41 |
+
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
42 |
+
should probably proofread and complete it, then remove this comment. -->
|
43 |
+
|
44 |
+
# japanese-mistral-300m-instruction
|
45 |
+
|
46 |
+
## Overview
|
47 |
+
|
48 |
+
Welcome to my model card!
|
49 |
+
|
50 |
+
This Model feature is ...
|
51 |
+
|
52 |
+
- Suppression of unknown word generation by using byte fallback in SentencePiece tokenizer and conversion to huggingface Tokenizers format
|
53 |
+
- Pretrained by wikipedia dataset and cc100 dataset
|
54 |
+
- Use of [Mistral 300M](https://huggingface.co/ce-lery/japanese-mistral-300m-base/blob/main/config.json)
|
55 |
+
- Fine-tuning [ce-lery/japanese-mistral-300m-base](https://huggingface.co/ce-lery/japanese-mistral-300m-base) with [kunishou/databricks-dolly-15k-ja](https://huggingface.co/datasets/kunishou/databricks-dolly-15k-ja)
|
56 |
+
|
57 |
+
Yukkuri shite ittene!
|
58 |
+
|
59 |
+
## How to use the model
|
60 |
+
|
61 |
+
```python
|
62 |
+
import torch
|
63 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
64 |
+
import os
|
65 |
+
|
66 |
+
MODEL_NAME = "ce-lery/japanese-mistral-300m-instruction"
|
67 |
+
torch.set_float32_matmul_precision('high')
|
68 |
+
|
69 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
70 |
+
print(device)
|
71 |
+
|
72 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=False,trust_remote_code=True)
|
73 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME,trust_remote_code=True).to(device)
|
74 |
+
|
75 |
+
MAX_ASSISTANT_LENGTH = 100
|
76 |
+
MAX_INPUT_LENGTH = 128
|
77 |
+
INPUT_PROMPT = r'<s>\n以下は、タスクを説明する指示と、文脈のある入力の組み合わせです。要求を適切に満たす応答を書きなさい。\n[SEP]\n指示:\n{instruction}\n[SEP]\n入力:\n{input}\n[SEP]\n応答:\n'
|
78 |
+
NO_INPUT_PROMPT = r'<s>\n以下は、タスクを説明する指示です。要求を適切に満たす応答を書きなさい。\n[SEP]\n指示:\n{instruction}\n[SEP]\n応答:\n'
|
79 |
+
|
80 |
+
def prepare_input(instruction, input_text):
|
81 |
+
if input_text != "":
|
82 |
+
prompt = INPUT_PROMPT.format(instruction=instruction, input=input_text)
|
83 |
+
else:
|
84 |
+
prompt = NO_INPUT_PROMPT.format(instruction=instruction)
|
85 |
+
return prompt
|
86 |
+
|
87 |
+
def format_output(output):
|
88 |
+
output = output.lstrip("<s>").rstrip("</s>").replace("[SEP]", "").replace("\\n", "\n")
|
89 |
+
return output
|
90 |
+
|
91 |
+
def generate_response(instruction, input_text):
|
92 |
+
prompt = prepare_input(instruction, input_text)
|
93 |
+
token_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
|
94 |
+
n = len(token_ids[0])
|
95 |
+
# print(n)
|
96 |
+
|
97 |
+
with torch.no_grad():
|
98 |
+
output_ids = model.generate(
|
99 |
+
token_ids.to(model.device),
|
100 |
+
min_length=n,
|
101 |
+
max_length=min(MAX_INPUT_LENGTH, n + MAX_ASSISTANT_LENGTH),
|
102 |
+
top_p=0.95,
|
103 |
+
top_k=50,
|
104 |
+
temperature=0.4,
|
105 |
+
do_sample=True,
|
106 |
+
no_repeat_ngram_size=2,
|
107 |
+
num_beams=3,
|
108 |
+
pad_token_id=tokenizer.pad_token_id,
|
109 |
+
bos_token_id=tokenizer.bos_token_id,
|
110 |
+
eos_token_id=tokenizer.eos_token_id,
|
111 |
+
bad_words_ids=[[tokenizer.unk_token_id]]
|
112 |
+
)
|
113 |
+
|
114 |
+
output = tokenizer.decode(output_ids.tolist()[0])
|
115 |
+
formatted_output_all = format_output(output)
|
116 |
+
response = f"Assistant:{formatted_output_all.split('応答:')[-1].strip()}"
|
117 |
+
|
118 |
+
return formatted_output_all, response
|
119 |
+
|
120 |
+
instruction = "あなたは何でも正確に答えられるAIです。"
|
121 |
+
questions = [
|
122 |
+
"日本で一番高い山は?",
|
123 |
+
"日本で一番広い湖は?",
|
124 |
+
"世界で一番高い山は?",
|
125 |
+
"世界で一番広い湖は?",
|
126 |
+
"冗談を言ってください。",
|
127 |
+
]
|
128 |
+
|
129 |
+
# 各質問に対して応答を生成して表示
|
130 |
+
for question in questions:
|
131 |
+
formatted_output_all, response = generate_response(instruction, question)
|
132 |
+
print(response)
|
133 |
+
|
134 |
+
```
|
135 |
+
|
136 |
+
## Receipe
|
137 |
+
|
138 |
+
If you want to restruct this model, you can refer [this Github repository](https://github.com/ce-lery/japanese-mistral-300m-recipe).
|
139 |
+
|
140 |
+
I wrote the receipe for struction this model. For example,
|
141 |
+
|
142 |
+
- Preprocess with sentencepiece
|
143 |
+
- Pretraining with flash attention2 and torch.compile and DeepSpeed
|
144 |
+
- Fine-tuning with databricks-dolly-15k-ja
|
145 |
+
|
146 |
+
If you find my mistake,error,...etc, please create issue.
|
147 |
+
If you create pulreqest, I'm very happy!
|
148 |
+
## Training procedure
|
149 |
+
|
150 |
+
### Training hyperparameters
|
151 |
+
|
152 |
+
The following hyperparameters were used during training:
|
153 |
+
- learning_rate: 5e-06
|
154 |
+
- train_batch_size: 4
|
155 |
+
- eval_batch_size: 4
|
156 |
+
- seed: 42
|
157 |
+
- distributed_type: multi-GPU
|
158 |
+
- gradient_accumulation_steps: 64
|
159 |
+
- total_train_batch_size: 256
|
160 |
+
- optimizer: Adam with betas=(0.9,0.95) and epsilon=0.0001
|
161 |
+
- lr_scheduler_type: cosine
|
162 |
+
- lr_scheduler_warmup_steps: 1000
|
163 |
+
- num_epochs: 200
|
164 |
+
- mixed_precision_training: Native AMP
|
165 |
+
|
166 |
+
### Training results
|
167 |
+
|
168 |
+
| Training Loss | Epoch | Step | Validation Loss |
|
169 |
+
|:-------------:|:------:|:----:|:---------------:|
|
170 |
+
| 3.595 | 3.51 | 40 | 3.5299 |
|
171 |
+
| 3.4769 | 7.02 | 80 | 3.3722 |
|
172 |
+
| 3.3037 | 10.53 | 120 | 3.1871 |
|
173 |
+
| 3.1255 | 14.05 | 160 | 3.0088 |
|
174 |
+
| 2.9615 | 17.56 | 200 | 2.8684 |
|
175 |
+
| 2.8468 | 21.07 | 240 | 2.7808 |
|
176 |
+
| 2.7699 | 24.58 | 280 | 2.7205 |
|
177 |
+
| 2.7139 | 28.09 | 320 | 2.6793 |
|
178 |
+
| 2.6712 | 31.6 | 360 | 2.6509 |
|
179 |
+
| 2.6356 | 35.12 | 400 | 2.6294 |
|
180 |
+
| 2.6048 | 38.63 | 440 | 2.6120 |
|
181 |
+
| 2.5823 | 42.14 | 480 | 2.5974 |
|
182 |
+
| 2.5536 | 45.65 | 520 | 2.5849 |
|
183 |
+
| 2.5293 | 49.16 | 560 | 2.5740 |
|
184 |
+
| 2.5058 | 52.67 | 600 | 2.5644 |
|
185 |
+
| 2.482 | 56.19 | 640 | 2.5556 |
|
186 |
+
| 2.4575 | 59.7 | 680 | 2.5477 |
|
187 |
+
| 2.4339 | 63.21 | 720 | 2.5405 |
|
188 |
+
| 2.4073 | 66.72 | 760 | 2.5350 |
|
189 |
+
| 2.3845 | 70.23 | 800 | 2.5303 |
|
190 |
+
| 2.3606 | 73.74 | 840 | 2.5253 |
|
191 |
+
| 2.329 | 77.26 | 880 | 2.5215 |
|
192 |
+
| 2.3071 | 80.77 | 920 | 2.5185 |
|
193 |
+
| 2.2768 | 84.28 | 960 | 2.5155 |
|
194 |
+
| 2.2479 | 87.79 | 1000 | 2.5144 |
|
195 |
+
| 2.2181 | 91.3 | 1040 | 2.5151 |
|
196 |
+
| 2.1901 | 94.81 | 1080 | 2.5139 |
|
197 |
+
| 2.1571 | 98.33 | 1120 | 2.5148 |
|
198 |
+
| 2.1308 | 101.84 | 1160 | 2.5166 |
|
199 |
+
| 2.1032 | 105.35 | 1200 | 2.5193 |
|
200 |
+
| 2.0761 | 108.86 | 1240 | 2.5204 |
|
201 |
+
| 2.0495 | 112.37 | 1280 | 2.5269 |
|
202 |
+
| 2.0231 | 115.88 | 1320 | 2.5285 |
|
203 |
+
| 2.0021 | 119.4 | 1360 | 2.5328 |
|
204 |
+
| 1.9793 | 122.91 | 1400 | 2.5383 |
|
205 |
+
| 1.9575 | 126.42 | 1440 | 2.5442 |
|
206 |
+
| 1.9368 | 129.93 | 1480 | 2.5488 |
|
207 |
+
| 1.9216 | 133.44 | 1520 | 2.5534 |
|
208 |
+
| 1.902 | 136.95 | 1560 | 2.5584 |
|
209 |
+
| 1.8885 | 140.47 | 1600 | 2.5609 |
|
210 |
+
| 1.8728 | 143.98 | 1640 | 2.5657 |
|
211 |
+
| 1.8605 | 147.49 | 1680 | 2.5697 |
|
212 |
+
| 1.8476 | 151.0 | 1720 | 2.5741 |
|
213 |
+
| 1.8402 | 154.51 | 1760 | 2.5770 |
|
214 |
+
| 1.8274 | 158.02 | 1800 | 2.5803 |
|
215 |
+
| 1.8218 | 161.54 | 1840 | 2.5829 |
|
216 |
+
| 1.8144 | 165.05 | 1880 | 2.5847 |
|
217 |
+
| 1.8097 | 168.56 | 1920 | 2.5867 |
|
218 |
+
| 1.8076 | 172.07 | 1960 | 2.5883 |
|
219 |
+
| 1.8014 | 175.58 | 2000 | 2.5892 |
|
220 |
+
| 1.8001 | 179.09 | 2040 | 2.5899 |
|
221 |
+
| 1.7987 | 182.61 | 2080 | 2.5903 |
|
222 |
+
| 1.7971 | 186.12 | 2120 | 2.5906 |
|
223 |
+
| 1.7979 | 189.63 | 2160 | 2.5907 |
|
224 |
+
| 1.7975 | 193.14 | 2200 | 2.5907 |
|
225 |
+
|
226 |
+
|
227 |
+
### Framework versions
|
228 |
+
|
229 |
+
- Transformers 4.35.2
|
230 |
+
- Pytorch 2.1.1+cu121
|
231 |
+
- Datasets 2.14.5
|
232 |
+
- Tokenizers 0.14.1
|