Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: other
|
3 |
+
license_name: deepseek-license
|
4 |
+
license_link: LICENSE
|
5 |
+
---
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
### 1. Introduction of Deepseek Coder
|
10 |
+
|
11 |
+
Deepseek Coder comprises a series of code language models trained on both 87% code and 13% natural language in English and Chinese, with each model pre-trained on 2T tokens. We provide various sizes of the code model, ranging from 1B to 33B versions. Each model is pre-trained on project-level code corpus by employing a window size of 16K and a extra fill-in-the-blank task, to support project-level code completion and infilling. For coding capabilities, Deepseek Coder achieves state-of-the-art performance among open-source code models on multiple programming languages and various benchmarks.
|
12 |
+
|
13 |
+
- **Massive Training Data**: Trained on 2T tokens, including 87% code and 13% linguistic data in both English and Chinese languages.
|
14 |
+
|
15 |
+
- **Highly Flexible & Scalable**: Offered in model sizes of 1.3B, 5.7B, 6.7B, and 33B, enabling users to choose the setup most suitable for their requirements.
|
16 |
+
|
17 |
+
- **Superior Model Performance**: State-of-the-art performance among publicly available code models on HumanEval, MultiPL-E, MBPP, DS-1000, and APPS benchmarks.
|
18 |
+
|
19 |
+
- **Advanced Code Completion Capabilities**: A window size of 16K and a fill-in-the-blank task, supporting project-level code completion and infilling tasks.
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
### 2. Model Summary
|
24 |
+
deepseek-coder-6.7b-base is a 6.7B parameter model with Multi-Head Attention trained on 2 trillion tokens.
|
25 |
+
- **Home Page:** [DeepSeek](https://deepseek.com/)
|
26 |
+
- **Repository:** [deepseek-ai/deepseek-coder](https://github.com/deepseek-ai/deepseek-coder)
|
27 |
+
- **Chat With DeepSeek Coder:** [DeepSeek-Coder](https://coder.deepseek.com/)
|
28 |
+
|
29 |
+
|
30 |
+
### 3. How to Use
|
31 |
+
Here give some examples of how to use our model.
|
32 |
+
#### 1)Code Completion
|
33 |
+
```python
|
34 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
35 |
+
import torch
|
36 |
+
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-coder-6.7b-base", trust_remote_code=True)
|
37 |
+
model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-coder-6.7b-base", trust_remote_code=True).cuda()
|
38 |
+
input_text = "#write a quick sort algorithm"
|
39 |
+
inputs = tokenizer(input_text, return_tensors="pt").cuda()
|
40 |
+
outputs = model.generate(**inputs, max_length=128)
|
41 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
42 |
+
```
|
43 |
+
|
44 |
+
#### 2)Code Insertion
|
45 |
+
```python
|
46 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
47 |
+
import torch
|
48 |
+
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-coder-6.7b-base", trust_remote_code=True)
|
49 |
+
model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-coder-6.7b-base", trust_remote_code=True).cuda()
|
50 |
+
input_text = """<|fim▁begin|>def quick_sort(arr):
|
51 |
+
if len(arr) <= 1:
|
52 |
+
return arr
|
53 |
+
pivot = arr[0]
|
54 |
+
left = []
|
55 |
+
right = []
|
56 |
+
<|fim▁hole|>
|
57 |
+
if arr[i] < pivot:
|
58 |
+
left.append(arr[i])
|
59 |
+
else:
|
60 |
+
right.append(arr[i])
|
61 |
+
return quick_sort(left) + [pivot] + quick_sort(right)<|fim▁end|>"""
|
62 |
+
inputs = tokenizer(input_text, return_tensors="pt").cuda()
|
63 |
+
outputs = model.generate(**inputs, max_length=128)
|
64 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True)[len(input_text):])
|
65 |
+
```
|
66 |
+
|
67 |
+
#### 3)Repository Level Code Completion
|
68 |
+
```python
|
69 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
70 |
+
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-coder-6.7b-base", trust_remote_code=True)
|
71 |
+
model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-coder-6.7b-base", trust_remote_code=True).cuda()
|
72 |
+
|
73 |
+
input_text = """#utils.py
|
74 |
+
import torch
|
75 |
+
from sklearn import datasets
|
76 |
+
from sklearn.model_selection import train_test_split
|
77 |
+
from sklearn.preprocessing import StandardScaler
|
78 |
+
from sklearn.metrics import accuracy_score
|
79 |
+
|
80 |
+
def load_data():
|
81 |
+
iris = datasets.load_iris()
|
82 |
+
X = iris.data
|
83 |
+
y = iris.target
|
84 |
+
|
85 |
+
# Standardize the data
|
86 |
+
scaler = StandardScaler()
|
87 |
+
X = scaler.fit_transform(X)
|
88 |
+
|
89 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
|
90 |
+
|
91 |
+
# Convert numpy data to PyTorch tensors
|
92 |
+
X_train = torch.tensor(X_train, dtype=torch.float32)
|
93 |
+
X_test = torch.tensor(X_test, dtype=torch.float32)
|
94 |
+
y_train = torch.tensor(y_train, dtype=torch.int64)
|
95 |
+
y_test = torch.tensor(y_test, dtype=torch.int64)
|
96 |
+
|
97 |
+
return X_train, X_test, y_train, y_test
|
98 |
+
|
99 |
+
def evaluate_predictions(y_test, y_pred):
|
100 |
+
return accuracy_score(y_test, y_pred)
|
101 |
+
#model.py
|
102 |
+
import torch
|
103 |
+
import torch.nn as nn
|
104 |
+
import torch.optim as optim
|
105 |
+
from torch.utils.data import DataLoader, TensorDataset
|
106 |
+
|
107 |
+
class IrisClassifier(nn.Module):
|
108 |
+
def __init__(self):
|
109 |
+
super(IrisClassifier, self).__init__()
|
110 |
+
self.fc = nn.Sequential(
|
111 |
+
nn.Linear(4, 16),
|
112 |
+
nn.ReLU(),
|
113 |
+
nn.Linear(16, 3)
|
114 |
+
)
|
115 |
+
|
116 |
+
def forward(self, x):
|
117 |
+
return self.fc(x)
|
118 |
+
|
119 |
+
def train_model(self, X_train, y_train, epochs, lr, batch_size):
|
120 |
+
criterion = nn.CrossEntropyLoss()
|
121 |
+
optimizer = optim.Adam(self.parameters(), lr=lr)
|
122 |
+
|
123 |
+
# Create DataLoader for batches
|
124 |
+
dataset = TensorDataset(X_train, y_train)
|
125 |
+
dataloader = DataLoader(dataset, batch_size=batch_size, shuffle=True)
|
126 |
+
|
127 |
+
for epoch in range(epochs):
|
128 |
+
for batch_X, batch_y in dataloader:
|
129 |
+
optimizer.zero_grad()
|
130 |
+
outputs = self(batch_X)
|
131 |
+
loss = criterion(outputs, batch_y)
|
132 |
+
loss.backward()
|
133 |
+
optimizer.step()
|
134 |
+
|
135 |
+
def predict(self, X_test):
|
136 |
+
with torch.no_grad():
|
137 |
+
outputs = self(X_test)
|
138 |
+
_, predicted = outputs.max(1)
|
139 |
+
return predicted.numpy()
|
140 |
+
#main.py
|
141 |
+
from utils import load_data, evaluate_predictions
|
142 |
+
from model import IrisClassifier as Classifier
|
143 |
+
|
144 |
+
def main():
|
145 |
+
# Model training and evaluation
|
146 |
+
"""
|
147 |
+
inputs = tokenizer(input_text, return_tensors="pt").cuda()
|
148 |
+
outputs = model.generate(**inputs, max_new_tokens=140)
|
149 |
+
print(tokenizer.decode(outputs[0]))
|
150 |
+
```
|
151 |
+
|
152 |
+
|
153 |
+
|
154 |
+
### 4. Lincense
|
155 |
+
This code repository is licensed under the MIT License. The use of DeepSeek Coder model and weights is subject to the Model License. DeepSeek Coder supports commercial use.
|
156 |
+
|
157 |
+
See the [LICENSE-MODEL](https://github.com/deepseek-ai/deepseek-coder/blob/main/LICENSE-MODEL) for more details.
|
158 |
+
|
159 |
+
### 5. Contact
|
160 |
+
|
161 |
+
If you have any questions, please raise an issue or contact us at [[email protected]](mailto:[email protected]).
|