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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
- reasoning
|
| 13 |
- axolotl
|
| 14 |
- r1
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# DeepSeek-R1-Distill-Llama-3B
|
| 18 |
+
|
| 19 |
+
This model is the distilled version of DeepSeek-R1 on Llama-3.2-3B with R1-Distill-SFT dataset.
|
| 20 |
+
|
| 21 |
+
[<img src="https://raw.githubusercontent.com/OpenAccess-AI-Collective/axolotl/main/image/axolotl-badge-web.png" alt="Built with Axolotl" width="200" height="32"/>](https://github.com/OpenAccess-AI-Collective/axolotl)
|
| 22 |
+
|
| 23 |
+
<details><summary>See axolotl config</summary>
|
| 24 |
+
|
| 25 |
+
```yaml
|
| 26 |
+
base_model: unsloth/Llama-3.2-3B-Instruct
|
| 27 |
+
model_type: AutoModelForCausalLM
|
| 28 |
+
tokenizer_type: AutoTokenizer
|
| 29 |
+
|
| 30 |
+
load_in_8bit: true
|
| 31 |
+
load_in_4bit: false
|
| 32 |
+
strict: false
|
| 33 |
+
|
| 34 |
+
chat_template: llama3
|
| 35 |
+
datasets:
|
| 36 |
+
- path: ./custom_dataset.json
|
| 37 |
+
type: chat_template
|
| 38 |
+
conversation: chatml
|
| 39 |
+
ds_type: json
|
| 40 |
+
|
| 41 |
+
add_bos_token: true
|
| 42 |
+
add_eos_token: true
|
| 43 |
+
use_default_system_prompt: false
|
| 44 |
+
|
| 45 |
+
special_tokens:
|
| 46 |
+
bos_token: "<|begin_of_text|>"
|
| 47 |
+
eos_token: "<|eot_id|>"
|
| 48 |
+
pad_token: "<|eot_id|>"
|
| 49 |
+
additional_special_tokens:
|
| 50 |
+
- "<|begin_of_text|>"
|
| 51 |
+
- "<|eot_id|>"
|
| 52 |
+
|
| 53 |
+
adapter: lora
|
| 54 |
+
lora_model_dir:
|
| 55 |
+
lora_r: 16
|
| 56 |
+
lora_alpha: 32
|
| 57 |
+
lora_dropout: 0.1
|
| 58 |
+
lora_target_linear: true
|
| 59 |
+
|
| 60 |
+
hub_model_id: suayptalha/DeepSeek-R1-Distill-Llama-3B
|
| 61 |
+
|
| 62 |
+
sequence_len: 2048
|
| 63 |
+
sample_packing: false
|
| 64 |
+
pad_to_sequence_len: true
|
| 65 |
+
micro_batch_size: 2
|
| 66 |
+
gradient_accumulation_steps: 8
|
| 67 |
+
num_epochs: 1
|
| 68 |
+
learning_rate: 2e-5
|
| 69 |
+
optimizer: paged_adamw_8bit
|
| 70 |
+
lr_scheduler: cosine
|
| 71 |
+
|
| 72 |
+
train_on_inputs: false
|
| 73 |
+
group_by_length: false
|
| 74 |
+
bf16: false
|
| 75 |
+
fp16: true
|
| 76 |
+
tf32: false
|
| 77 |
+
|
| 78 |
+
gradient_checkpointing: true
|
| 79 |
+
flash_attention: false
|
| 80 |
+
|
| 81 |
+
logging_steps: 50
|
| 82 |
+
warmup_steps: 100
|
| 83 |
+
saves_per_epoch: 1
|
| 84 |
+
|
| 85 |
+
output_dir: ./finetune-sft-results
|
| 86 |
+
save_safetensors: true
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
# Prompt Template
|
| 90 |
+
|
| 91 |
+
You can use Llama3 prompt template while using the model:
|
| 92 |
+
|
| 93 |
+
### Llama3
|
| 94 |
+
|
| 95 |
+
```
|
| 96 |
+
<|start_header_id|>system<|end_header_id|>
|
| 97 |
+
{system}<|eot_id|>
|
| 98 |
+
|
| 99 |
+
<|start_header_id|>user<|end_header_id|>
|
| 100 |
+
{user}<|eot_id|>
|
| 101 |
+
|
| 102 |
+
<|start_header_id|>assistant<|end_header_id|>
|
| 103 |
+
{assistant}<|eot_id|>
|
| 104 |
+
```
|
| 105 |
+
</details><br>
|
| 106 |
+
|
| 107 |
+
Example usage:
|
| 108 |
+
```py
|
| 109 |
+
import torch
|
| 110 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 111 |
+
|
| 112 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 113 |
+
"suayptalha/DeepSeek-R1-Distill-Llama-3B-4bit",
|
| 114 |
+
load_in_4bit = True,
|
| 115 |
+
device_map="auto"
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
tokenizer = AutoTokenizer.from_pretrained("suayptalha/DeepSeek-R1-Distill-Llama-3B-4bit")
|
| 119 |
+
|
| 120 |
+
SYSTEM_PROMPT = """Respond in the following format:
|
| 121 |
+
<think>
|
| 122 |
+
You should reason between these tags.
|
| 123 |
+
</think>
|
| 124 |
+
|
| 125 |
+
Answer goes here...
|
| 126 |
+
|
| 127 |
+
Always use <think> </think> tags even if they are not necessary.
|
| 128 |
+
"""
|
| 129 |
+
|
| 130 |
+
messages = [
|
| 131 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 132 |
+
{"role": "user", "content": "Which one is larger? 9.11 or 9.9?"},
|
| 133 |
+
]
|
| 134 |
+
inputs = tokenizer.apply_chat_template(
|
| 135 |
+
messages,
|
| 136 |
+
tokenize = True,
|
| 137 |
+
add_generation_prompt = True,
|
| 138 |
+
return_tensors = "pt",
|
| 139 |
+
).to("cuda")
|
| 140 |
+
output = model.generate(input_ids=inputs, max_new_tokens=256, use_cache=True, temperature=0.7)
|
| 141 |
+
decoded_output = tokenizer.decode(output[0], skip_special_tokens=False)
|
| 142 |
+
print(decoded_output)
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
Output:
|
| 146 |
+
```
|
| 147 |
+
<think>
|
| 148 |
+
First, I need to compare the two numbers 9.11 and 9.9.
|
| 149 |
+
|
| 150 |
+
Next, I'll analyze each number. The first digit after the decimal point in 9.11 is 1, and in 9.9, it's 9.
|
| 151 |
+
|
| 152 |
+
Since 9 is greater than 1, 9.9 is larger than 9.11.
|
| 153 |
+
</think>
|
| 154 |
+
|
| 155 |
+
To determine which number is larger, let's compare the two numbers:
|
| 156 |
+
|
| 157 |
+
**9.11** and **9.9**
|
| 158 |
+
|
| 159 |
+
1. **Identify the Decimal Places:**
|
| 160 |
+
- Both numbers have two decimal places.
|
| 161 |
+
|
| 162 |
+
2. **Compare the Tens Place (Right of the Decimal Point):**
|
| 163 |
+
- **9.11:** The tens place is 1.
|
| 164 |
+
- **9.9:** The tens place is 9.
|
| 165 |
+
|
| 166 |
+
3. **Conclusion:**
|
| 167 |
+
- Since 9 is greater than 1, the number with the larger tens place is 9.9.
|
| 168 |
+
|
| 169 |
+
**Answer:** **9.9** is larger than **9.11**.<
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
Suggested system prompt:
|
| 174 |
+
```
|
| 175 |
+
Respond in the following format:
|
| 176 |
+
<think>
|
| 177 |
+
You should reason between these tags.
|
| 178 |
+
</think>
|
| 179 |
+
|
| 180 |
+
Answer goes here...
|
| 181 |
+
|
| 182 |
+
Always use <think> </think> tags even if they are not necessary.
|
| 183 |
+
```
|
| 184 |
+
|
| 185 |
+
## Parameters
|
| 186 |
+
- lr: 2e-5
|
| 187 |
+
- epochs: 1
|
| 188 |
+
- batch_size: 16
|
| 189 |
+
- optimizer: paged_adamw_8bit
|
| 190 |
+
|
| 191 |
+
## Support
|
| 192 |
+
|
| 193 |
+
<a href="https://www.buymeacoffee.com/suayptalha" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
|