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