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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: unsloth/DeepSeek-R1-Distill-Llama-8B
|
| 4 |
+
tags:
|
| 5 |
+
- dyck-language
|
| 6 |
+
- bracket-completion
|
| 7 |
+
- reasoning
|
| 8 |
+
- lora
|
| 9 |
+
- fine-tuned
|
| 10 |
+
task: text-generation
|
| 11 |
+
language: en
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# DeepSeek-R1-Dyck-Finetuned
|
| 15 |
+
|
| 16 |
+
## Model Description
|
| 17 |
+
|
| 18 |
+
This model is a fine-tuned version of **unsloth/DeepSeek-R1-Distill-Llama-8B** specifically optimized for **Dyck language bracket completion** tasks. The model has been trained to complete incomplete Dyck bracket sequences by tracking the stack of open brackets and generating the appropriate closing brackets.
|
| 19 |
+
|
| 20 |
+
### Key Features
|
| 21 |
+
|
| 22 |
+
- **Reasoning Capability**: Generates step-by-step reasoning using `<think>` blocks before providing the final answer
|
| 23 |
+
- **Dyck Language Completion**: Accurately completes bracket sequences for 8 different bracket types: `()`, `[]`, `{}`, `<>`, `⟨⟩`, `⟦⟧`, `⦃⦄`, `⦅⦆`
|
| 24 |
+
- **LoRA Fine-tuning**: Uses Low-Rank Adaptation (LoRA) for efficient training
|
| 25 |
+
- **High Accuracy**: Trained on 60k diverse Dyck sequence examples
|
| 26 |
+
|
| 27 |
+
## Training Details
|
| 28 |
+
|
| 29 |
+
### Training Data
|
| 30 |
+
- **Dataset**: 60k Dyck language sequences
|
| 31 |
+
- **Train/Val Split**: 95%/5%
|
| 32 |
+
- **Format**: Chat template with system/user/assistant messages
|
| 33 |
+
- **Reasoning**: All samples include `<think>` reasoning blocks
|
| 34 |
+
|
| 35 |
+
### Training Configuration
|
| 36 |
+
- **Base Model**: unsloth/DeepSeek-R1-Distill-Llama-8B
|
| 37 |
+
- **LoRA Rank**: 32 (attention layers only)
|
| 38 |
+
- **LoRA Alpha**: 64
|
| 39 |
+
- **LoRA Dropout**: 0.25
|
| 40 |
+
- **Learning Rate**: 3e-6
|
| 41 |
+
- **Batch Size**: 4 × 32 (effective batch: 128)
|
| 42 |
+
- **Epochs**: 4
|
| 43 |
+
- **Warmup**: 30% of total steps
|
| 44 |
+
- **Gradient Clipping**: 0.05
|
| 45 |
+
- **Optimizer**: AdamW
|
| 46 |
+
- **Scheduler**: Linear
|
| 47 |
+
|
| 48 |
+
### Training Hardware
|
| 49 |
+
- **GPU**: 40GB GPU
|
| 50 |
+
- **Precision**: Full (bfloat16)
|
| 51 |
+
- **Training Time**: ~6-8 hours
|
| 52 |
+
|
| 53 |
+
## Usage
|
| 54 |
+
|
| 55 |
+
### Installation
|
| 56 |
+
|
| 57 |
+
```bash
|
| 58 |
+
pip install unsloth transformers
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
### Loading the Model
|
| 62 |
+
|
| 63 |
+
```python
|
| 64 |
+
from unsloth import FastLanguageModel
|
| 65 |
+
|
| 66 |
+
# Load LoRA adapters
|
| 67 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 68 |
+
model_name="akashdutta1030/dddd",
|
| 69 |
+
max_seq_length=2048,
|
| 70 |
+
dtype=None,
|
| 71 |
+
load_in_4bit=False, # Use True for 4-bit quantization
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
FastLanguageModel.for_inference(model)
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
### Inference Example
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
messages = [
|
| 81 |
+
{
|
| 82 |
+
"role": "system",
|
| 83 |
+
"content": "You are a logic engine. Complete the Dyck bracket sequence by tracking the stack of open brackets."
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
"role": "user",
|
| 87 |
+
"content": "([{<"
|
| 88 |
+
}
|
| 89 |
+
]
|
| 90 |
+
|
| 91 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 92 |
+
inputs = tokenizer([prompt], return_tensors="pt").to(model.device)
|
| 93 |
+
|
| 94 |
+
with torch.no_grad():
|
| 95 |
+
outputs = model.generate(
|
| 96 |
+
**inputs,
|
| 97 |
+
max_new_tokens=512,
|
| 98 |
+
temperature=0.1,
|
| 99 |
+
top_p=0.95,
|
| 100 |
+
do_sample=True,
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=False)
|
| 104 |
+
print(response)
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
### Expected Output Format
|
| 108 |
+
|
| 109 |
+
The model generates responses in the following format:
|
| 110 |
+
|
| 111 |
+
```
|
| 112 |
+
<think>
|
| 113 |
+
1. Input sequence: (, [, {, <
|
| 114 |
+
2. Maintain a stack of opening brackets:
|
| 115 |
+
- Push '(' -> Stack: ['(']
|
| 116 |
+
- Push '[' -> Stack: ['(', '[']
|
| 117 |
+
- Push '{' -> Stack: ['(', '[', '{']
|
| 118 |
+
- Push '<' -> Stack: ['(', '[', '{', '<']
|
| 119 |
+
3. To close the sequence, pop from the stack in reverse order:
|
| 120 |
+
- Pop '<' -> Closing: '>'
|
| 121 |
+
- Pop '{' -> Closing: '}'
|
| 122 |
+
- Pop '[' -> Closing: ']'
|
| 123 |
+
- Pop '(' -> Closing: ')'
|
| 124 |
+
4. Appending closing brackets to input: ([{<>}])
|
| 125 |
+
</think>
|
| 126 |
+
([{<>}])
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
## Model Architecture
|
| 130 |
+
|
| 131 |
+
- **Base Architecture**: Llama-based (DeepSeek-R1)
|
| 132 |
+
- **Parameters**: 8B base model
|
| 133 |
+
- **LoRA Parameters**: ~167M trainable parameters (1.8% of base model)
|
| 134 |
+
- **Target Modules**: Attention layers only (q_proj, k_proj, v_proj, o_proj)
|
| 135 |
+
|
| 136 |
+
## Performance
|
| 137 |
+
|
| 138 |
+
The model has been trained and validated on:
|
| 139 |
+
- **Training Loss**: Decreasing smoothly
|
| 140 |
+
- **Validation Loss**: Monitored every 200 steps
|
| 141 |
+
- **Gradient Stability**: Controlled with strict clipping (0.05)
|
| 142 |
+
- **Reasoning Quality**: Generates detailed step-by-step reasoning
|
| 143 |
+
|
| 144 |
+
## Limitations
|
| 145 |
+
|
| 146 |
+
- The model is specifically trained for Dyck language bracket completion
|
| 147 |
+
- Performance may vary on sequences with very deep nesting (>20 levels)
|
| 148 |
+
- Requires proper formatting with chat template for best results
|
| 149 |
+
|
| 150 |
+
## Citation
|
| 151 |
+
|
| 152 |
+
If you use this model, please cite:
|
| 153 |
+
|
| 154 |
+
```bibtex
|
| 155 |
+
@misc{deepseek-r1-dyck-finetuned,
|
| 156 |
+
title={DeepSeek-R1-Dyck-Finetuned: Bracket Completion Model},
|
| 157 |
+
author={Fine-tuned on DeepSeek-R1-Distill-Llama-8B},
|
| 158 |
+
year={2024},
|
| 159 |
+
howpublished={\url{https://huggingface.co/akashdutta1030/dddd}}
|
| 160 |
+
}
|
| 161 |
+
```
|
| 162 |
+
|
| 163 |
+
## License
|
| 164 |
+
|
| 165 |
+
This model is licensed under the Apache 2.0 license.
|
| 166 |
+
|
| 167 |
+
## Acknowledgments
|
| 168 |
+
|
| 169 |
+
- Base model: DeepSeek-R1-Distill-Llama-8B
|
| 170 |
+
- Training framework: Unsloth
|
| 171 |
+
- Fine-tuning approach: LoRA (Low-Rank Adaptation)
|