Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,156 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
| 9 |
-
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
## Model Details
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 23 |
-
- **Model type:** [More Information Needed]
|
| 24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
-
|
| 28 |
-
### Model Sources [optional]
|
| 29 |
-
|
| 30 |
-
<!-- Provide the basic links for the model. -->
|
| 31 |
-
|
| 32 |
-
- **Repository:** [More Information Needed]
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
-
|
| 36 |
-
## Uses
|
| 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 |
## Training Details
|
| 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 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
### Results
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
-
|
| 143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
-
|
| 159 |
-
### Compute Infrastructure
|
| 160 |
-
|
| 161 |
-
[More Information Needed]
|
| 162 |
-
|
| 163 |
-
#### Hardware
|
| 164 |
-
|
| 165 |
-
[More Information Needed]
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
-
|
| 187 |
-
[More Information Needed]
|
| 188 |
-
|
| 189 |
-
## More Information [optional]
|
| 190 |
-
|
| 191 |
-
[More Information Needed]
|
| 192 |
-
|
| 193 |
-
## Model Card Authors [optional]
|
| 194 |
-
|
| 195 |
-
[More Information Needed]
|
| 196 |
-
|
| 197 |
-
## Model Card Contact
|
| 198 |
-
|
| 199 |
-
[More Information Needed]
|
|
|
|
| 1 |
---
|
| 2 |
+
license: mit
|
| 3 |
+
base_model: deepseek-ai/deepseek-coder-6.7b-base
|
| 4 |
+
tags:
|
| 5 |
+
- code
|
| 6 |
+
- leetcode
|
| 7 |
+
- python
|
| 8 |
+
- fine-tuned
|
| 9 |
+
- lora
|
| 10 |
+
- qlora
|
| 11 |
+
datasets:
|
| 12 |
+
- LongQ/leetcode_python
|
| 13 |
+
language:
|
| 14 |
+
- en
|
| 15 |
+
pipeline_tag: text-generation
|
| 16 |
---
|
| 17 |
|
| 18 |
+
# DeepSeek-Coder-6.7B LeetCode Fine-Tuned
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
A fine-tuned version of [DeepSeek-Coder-6.7B-Base](https://huggingface.co/deepseek-ai/deepseek-coder-6.7b-base) specialized for solving LeetCode-style algorithmic problems in Python.
|
| 21 |
|
| 22 |
## Model Details
|
| 23 |
|
| 24 |
+
| Attribute | Value |
|
| 25 |
+
|-----------|-------|
|
| 26 |
+
| **Base Model** | deepseek-ai/deepseek-coder-6.7b-base |
|
| 27 |
+
| **Fine-tuning Method** | QLoRA (4-bit quantization + LoRA) |
|
| 28 |
+
| **Training Data** | [LongQ/leetcode_python](https://huggingface.co/datasets/LongQ/leetcode_python) (2,369 problems) |
|
| 29 |
+
| **Epochs** | 3 |
|
| 30 |
+
| **Hardware** | NVIDIA T4 (16GB VRAM) |
|
| 31 |
+
| **Training Time** | ~5 hours |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
## Performance
|
| 34 |
|
| 35 |
+
Evaluated on 100 LeetCode problems with automated code execution:
|
| 36 |
|
| 37 |
+
| Metric | Base Model | Fine-Tuned | Improvement |
|
| 38 |
+
|--------|------------|------------|-------------|
|
| 39 |
+
| **Overall Accuracy** | 24% | 34% | +42% |
|
| 40 |
+
| **Easy Problems** | 30.3% | 52% | +72% |
|
| 41 |
+
| **Medium Problems** | 32.4% | 27.8% | -14% |
|
| 42 |
+
| **Hard Problems** | 9.1% | 28.6% | +214% |
|
| 43 |
|
| 44 |
+
### Key Findings
|
| 45 |
|
| 46 |
+
- **Significant gains on Easy and Hard problems** — model learned both fundamental patterns and complex algorithms
|
| 47 |
+
- **Slight regression on Medium** — possible overfitting to extremes of difficulty distribution
|
| 48 |
+
- **Domain-specific data matters** — initial training on general coding data degraded performance
|
| 49 |
|
| 50 |
+
## Intended Use
|
| 51 |
|
| 52 |
+
- Solving algorithmic coding challenges
|
| 53 |
+
- LeetCode practice and learning
|
| 54 |
+
- Code generation for competitive programming
|
| 55 |
+
- Educational tool for understanding algorithmic solutions
|
| 56 |
|
| 57 |
+
## Limitations
|
| 58 |
|
| 59 |
+
- Optimized specifically for LeetCode-style problems, may not generalize to other coding tasks
|
| 60 |
+
- Python-only (not trained on other languages)
|
| 61 |
+
- May produce syntactically correct but logically incorrect solutions
|
| 62 |
+
- Struggles with problems requiring complex data structure implementations (LinkedList, Trees)
|
| 63 |
|
| 64 |
+
## How to Use
|
| 65 |
|
| 66 |
+
### With Hugging Face Transformers
|
| 67 |
|
| 68 |
+
```python
|
| 69 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 70 |
+
import torch
|
| 71 |
|
| 72 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 73 |
+
"Jerry-lin23/deepseek-leetcode-fp16",
|
| 74 |
+
torch_dtype=torch.float16,
|
| 75 |
+
device_map="auto"
|
| 76 |
+
)
|
| 77 |
+
tokenizer = AutoTokenizer.from_pretrained("Jerry-lin23/deepseek-leetcode-fp16")
|
| 78 |
|
| 79 |
+
prompt = """### Problem:
|
| 80 |
+
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
|
| 81 |
|
| 82 |
+
### Starter Code:
|
| 83 |
+
```python
|
| 84 |
+
class Solution:
|
| 85 |
+
def twoSum(self, nums: List[int], target: int) -> List[int]:
|
| 86 |
+
```
|
| 87 |
|
| 88 |
+
### Solution:
|
| 89 |
+
```python
|
| 90 |
+
"""
|
| 91 |
|
| 92 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 93 |
+
outputs = model.generate(**inputs, max_new_tokens=200, temperature=0.2)
|
| 94 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 95 |
+
```
|
| 96 |
|
| 97 |
+
### With Ollama (Local Deployment)
|
| 98 |
|
| 99 |
+
1. Convert to GGUF format
|
| 100 |
+
2. Create a Modelfile:
|
| 101 |
+
```
|
| 102 |
+
FROM ./deepseek-leetcode-q8.gguf
|
| 103 |
+
PARAMETER temperature 0.2
|
| 104 |
+
PARAMETER top_p 0.95
|
| 105 |
+
```
|
| 106 |
+
3. Import: `ollama create deepseek-leetcode -f Modelfile`
|
| 107 |
+
4. Run: `ollama run deepseek-leetcode`
|
| 108 |
|
| 109 |
## Training Details
|
| 110 |
|
| 111 |
+
### LoRA Configuration
|
| 112 |
+
|
| 113 |
+
```python
|
| 114 |
+
LoraConfig(
|
| 115 |
+
r=16,
|
| 116 |
+
lora_alpha=32,
|
| 117 |
+
target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
|
| 118 |
+
lora_dropout=0.05,
|
| 119 |
+
bias="none",
|
| 120 |
+
task_type="CAUSAL_LM"
|
| 121 |
+
)
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
### Training Arguments
|
| 125 |
+
|
| 126 |
+
```python
|
| 127 |
+
SFTConfig(
|
| 128 |
+
num_train_epochs=3,
|
| 129 |
+
per_device_train_batch_size=1,
|
| 130 |
+
gradient_accumulation_steps=8,
|
| 131 |
+
learning_rate=2e-4,
|
| 132 |
+
warmup_ratio=0.03,
|
| 133 |
+
fp16=True,
|
| 134 |
+
gradient_checkpointing=True,
|
| 135 |
+
max_seq_length=2048,
|
| 136 |
+
dataset_text_field="text"
|
| 137 |
+
)
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
## Citation
|
| 141 |
+
|
| 142 |
+
```bibtex
|
| 143 |
+
@misc{deepseek-leetcode-finetuned,
|
| 144 |
+
author = {Jerry Lin},
|
| 145 |
+
title = {DeepSeek-Coder-6.7B LeetCode Fine-Tuned},
|
| 146 |
+
year = {2024},
|
| 147 |
+
publisher = {Hugging Face},
|
| 148 |
+
url = {https://huggingface.co/Jerry-lin23/deepseek-leetcode-fp16}
|
| 149 |
+
}
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
## Links
|
| 153 |
+
|
| 154 |
+
- 📊 [Benchmark Repository](https://github.com/jerrylin-23/DeepSeek-LeetCode-Oriented-Training)
|
| 155 |
+
- 🤗 [Base Model](https://huggingface.co/deepseek-ai/deepseek-coder-6.7b-base)
|
| 156 |
+
- 📚 [Training Dataset](https://huggingface.co/datasets/LongQ/leetcode_python)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|