File size: 9,960 Bytes
85723f7
9dc7a0a
a0ae4e3
85723f7
9dc7a0a
02b57fe
a0ae4e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9dc7a0a
85723f7
a0ae4e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85723f7
 
a0ae4e3
cf83a12
9dc7a0a
010d90c
 
 
 
 
 
 
 
a0ae4e3
 
cf83a12
85723f7
 
 
9dc7a0a
 
88e1b35
9dc7a0a
88e1b35
 
bb90af0
9dc7a0a
 
 
dc16f28
b8ee5ed
9dc7a0a
b8ee5ed
 
 
 
 
9dc7a0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b8ee5ed
 
9dc7a0a
b8ee5ed
dc16f28
b8ee5ed
 
 
 
 
 
 
 
 
 
 
 
 
 
9dc7a0a
 
 
 
 
 
 
 
 
010d90c
9dc7a0a
010d90c
9dc7a0a
010d90c
9dc7a0a
 
 
02b57fe
a0ae4e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
---
language:
  - en
license: apache-2.0
base_model: Locutusque/TinyMistral-248M
datasets:
  - HuggingFaceH4/ultrachat_200k
  - Felladrin/ChatML-ultrachat_200k
  - Open-Orca/OpenOrca
  - Felladrin/ChatML-OpenOrca
  - hkust-nlp/deita-10k-v0
  - Felladrin/ChatML-deita-10k-v0
  - LDJnr/Capybara
  - Felladrin/ChatML-Capybara
  - databricks/databricks-dolly-15k
  - Felladrin/ChatML-databricks-dolly-15k
  - euclaise/reddit-instruct-curated
  - Felladrin/ChatML-reddit-instruct-curated
  - CohereForAI/aya_dataset
  - Felladrin/ChatML-aya_dataset
  - HuggingFaceH4/ultrafeedback_binarized
pipeline_tag: text-generation
widget:
  - messages:
      - role: system
        content:
          You are a highly knowledgeable and friendly assistant. Your goal is to
          understand and respond to user inquiries with clarity. Your interactions are
          always respectful, helpful, and focused on delivering the most accurate information
          to the user.
      - role: user
        content: Hey! Got a question for you!
      - role: assistant
        content: Sure! What's it?
      - role: user
        content: What are some potential applications for quantum computing?
  - messages:
      - role: user
        content: Heya!
      - role: assistant
        content: Hi! How may I help you?
      - role: user
        content:
          I'm interested in developing a career in software engineering. What would
          you recommend me to do?
  - messages:
      - role: user
        content: Morning!
      - role: assistant
        content: Good morning! How can I help you today?
      - role: user
        content: Could you give me some tips for becoming a healthier person?
  - messages:
      - role: system
        content:
          You are a very creative assistant. User will give you a task, which you
          should complete with all your knowledge.
      - role: user
        content:
          Hello! Can you please elaborate a background story of an RPG game about
          wizards and dragons in a sci-fi world?
---

# TinyMistral-248M-Chat

- Base model: [Locutusque/TinyMistral-248M](https://huggingface.co/Locutusque/TinyMistral-248M) with two additional special tokens (`<|im_start|>` and `<|im_end|>`)
- Datasets:
  - [[ChatML](https://huggingface.co/datasets/Felladrin/ChatML-ultrachat_200k)] [HuggingFaceH4/ultrachat_200k](https://huggingface.co/datasets/HuggingFaceH4/ultrachat_200k)
  - [[ChatML](https://huggingface.co/datasets/Felladrin/ChatML-OpenOrca)] [Open-Orca/OpenOrca](https://huggingface.co/datasets/Open-Orca/OpenOrca)
  - [[ChatML](https://huggingface.co/datasets/Felladrin/ChatML-deita-10k-v0)] [hkust-nlp/deita-10k-v0](https://huggingface.co/datasets/hkust-nlp/deita-10k-v0)
  - [[ChatML](https://huggingface.co/datasets/Felladrin/ChatML-Capybara)] [LDJnr/Capybara](https://huggingface.co/datasets/LDJnr/Capybara)
  - [[ChatML](https://huggingface.co/datasets/Felladrin/ChatML-databricks-dolly-15k)] [databricks/databricks-dolly-15k](https://huggingface.co/datasets/databricks/databricks-dolly-15k)
  - [[ChatML](https://huggingface.co/datasets/Felladrin/ChatML-reddit-instruct-curated)] [euclaise/reddit-instruct-curated](https://huggingface.co/datasets/euclaise/reddit-instruct-curated)
  - [[ChatML](https://huggingface.co/datasets/Felladrin/ChatML-aya_dataset)] [CohereForAI/aya_dataset](https://huggingface.co/datasets/CohereForAI/aya_dataset)
  - [HuggingFaceH4/ultrafeedback_binarized](https://huggingface.co/datasets/HuggingFaceH4/ultrafeedback_binarized)
- License: [Apache License 2.0](https://huggingface.co/Felladrin/TinyMistral-248M-Chat-v3/resolve/main/license.txt)

## Recommended Prompt Format

```
<|im_start|>system
{system_message}<|im_end|>
<|im_start|>user
{user_message}<|im_end|>
<|im_start|>assistant
```

## Usage Example

```python
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
import torch

model_path = "Felladrin/TinyMistral-248M-Chat-v3"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path).to(device)
streamer = TextStreamer(tokenizer)
messages = [
    {
        "role": "system",
        "content": "You are a highly knowledgeable and friendly assistant. Your goal is to understand and respond to user inquiries with clarity. Your interactions are always respectful, helpful, and focused on delivering the most accurate information to the user.",
    },
    {
        "role": "user",
        "content": "Hey! Got a question for you!",
    },
    {
        "role": "assistant",
        "content": "Sure! What's it?",
    },
    {
        "role": "user",
        "content": "What are some potential applications for quantum computing?",
    },
]
prompt = tokenizer.apply_chat_template(
    messages, tokenize=False, add_generation_prompt=True
)
inputs = tokenizer(prompt, return_tensors="pt").to(device)
model.generate(
    inputs.input_ids,
    attention_mask=inputs.attention_mask,
    max_length=tokenizer.model_max_length,
    streamer=streamer,
    eos_token_id=tokenizer.eos_token_id,
    pad_token_id=tokenizer.pad_token_id,
    do_sample=True,
    temperature=0.6,
    top_p=0.8,
    top_k=0,
    min_p=0.1,
    typical_p=0.2,
    repetition_penalty=1.176,
)
```

## How it was trained

This model was trained with [SFTTrainer](https://huggingface.co/docs/trl/main/en/sft_trainer) using the following settings:

| Hyperparameter         | Value                                         |
| :--------------------- | :-------------------------------------------- |
| Learning rate          | 2e-5                                          |
| Total train batch size | 32                                            |
| Max. sequence length   | 2048                                          |
| Weight decay           | 0.01                                          |
| Warmup ratio           | 0.1                                           |
| NEFTune Noise Alpha    | 5                                             |
| Optimizer              | Adam with betas=(0.9,0.999) and epsilon=1e-08 |
| Scheduler              | cosine                                        |
| Seed                   | 42                                            |

Then, the model was fine-tuned with DPO through [LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory) using the following hyperparameters and command:

| Parameter                   | Value                                                                                                          |
| :-------------------------- | :------------------------------------------------------------------------------------------------------------- |
| Dataset                     | [HuggingFaceH4/ultrafeedback_binarized](https://huggingface.co/datasets/HuggingFaceH4/ultrafeedback_binarized) |
| Learning rate               | 1e-06                                                                                                          |
| Train batch size            | 4                                                                                                              |
| Eval batch size             | 8                                                                                                              |
| Seed                        | 42                                                                                                             |
| Distributed type            | multi-GPU                                                                                                      |
| Number of devices           | 8                                                                                                              |
| Gradient accumulation steps | 4                                                                                                              |
| Total train batch size      | 128                                                                                                            |
| Total eval batch size       | 64                                                                                                             |
| Optimizer                   | adamw_8bit with betas=(0.9,0.999) and epsilon=1e-08                                                            |
| LR scheduler type           | cosine                                                                                                         |
| LR scheduler warmup ratio   | 0.1                                                                                                            |
| Number of epochs            | 2.0                                                                                                            |

```sh
llamafactory-cli train \
    --stage dpo \
    --do_train True \
    --model_name_or_path ~/TinyMistral-248M-Chat \
    --preprocessing_num_workers $(python -c "import os; print(max(1, os.cpu_count() - 2))") \
    --dataloader_num_workers $(python -c "import os; print(max(1, os.cpu_count() - 2))") \
    --finetuning_type full \
    --template default \
    --flash_attn auto \
    --enable_liger_kernel True \
    --dataset_dir data \
    --dataset ultrafeedback \
    --cutoff_len 1024 \
    --learning_rate 1e-6 \
    --num_train_epochs 2.0 \
    --per_device_train_batch_size 4 \
    --gradient_accumulation_steps 4 \
    --lr_scheduler_type cosine \
    --max_grad_norm 1.0 \
    --logging_steps 10 \
    --save_steps 50 \
    --save_total_limit 1 \
    --warmup_ratio 0.1 \
    --packing False \
    --report_to none \
    --output_dir ~/TinyMistral-248M-Chat-v3 \
    --pure_bf16 True \
    --plot_loss True \
    --trust_remote_code True \
    --ddp_timeout 180000000 \
    --include_tokens_per_second True \
    --include_num_input_tokens_seen True \
    --optim adamw_8bit \
    --pref_beta 0.5 \
    --pref_ftx 0 \
    --pref_loss simpo \
    --gradient_checkpointing True
```