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inese) [[English]](#english)
|
12 |
+
|
13 |
+
<a id="english"></a>
|
14 |
+
|
15 |
+
<p align="center">
|
16 |
+
<img width="300px" alt="OpenCSG" src="https://cdn-uploads.huggingface.co/production/uploads/64c71b27d43e4dee51a8b31a/GwYXPKuEoGCGcMICeW-sb.jpeg">
|
17 |
+
</p>
|
18 |
+
|
19 |
+
<p align="center"><a href="https://portal.opencsg.com/models">[OpenCSG Community]</a> <a href="https://github.com/opencsgs">[github]</a> <a href="https://cdn-uploads.huggingface.co/production/uploads/64c71b27d43e4dee51a8b31a/HU6vz21qKTEmUBCWqCFh9.jpeg">[wechat]</a> <a href="https://twitter.com/OpenCsg">[Twitter]</a> </p>
|
20 |
+
|
21 |
+
|
22 |
+
</div>
|
23 |
+
OpenCSG stands for Converged resources, Software refinement, and Generative LM. The 'C' represents Converged resources, indicating the integration and full utilization of hybrid resources. The 'S' stands for Software refinement, signifying software that is refined by large models. The 'G' represents Generative LM, which denotes widespread, inclusive, and democratized generative large models.
|
24 |
+
|
25 |
+
The vision of OpenCSG is to empower every industry, every company, and every individual to own their models. We adhere to the principles of openness and open source, making the large model software stack of OpenCSG available to the community. We welcome everyone to use, send feedback, and contribute collaboratively.
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
+
## Model Description
|
32 |
+
|
33 |
+
Phi-2 is a 2.7 billion-parameter Transformer model trained on augmented data sources, including synthetic NLP texts and filtered websites, alongside existing data used for Phi-1.5. It performs nearly state-of-the-art on benchmarks for common sense, language understanding, and logical reasoning, despite having fewer than 13 billion parameters.
|
34 |
+
Unlike some models, Phi-2 hasn't been fine-tuned through reinforcement learning from human feedback. The goal of this open-source model is to enable research into safety challenges like reducing toxicity, understanding biases, enhancing controllability, etc.
|
35 |
+
|
36 |
+
|
37 |
+
opencsg-phi-2-v0.1 is a model based on phi-2 that have been fine-tuned using full-parameter tuning methods.
|
38 |
+
<br>
|
39 |
+
|
40 |
+
This is the repository for the base 2.7B version finetuned based on [phi-2](https://huggingface.co/microsoft/phi-2).
|
41 |
+
|
42 |
+
| Model Size | Base Model |
|
43 |
+
| --- | ----------------------------------------------------------------------------- |
|
44 |
+
| 2.7B | [opencsg/Opencsg-phi-2-v0.1](https://huggingface.co/opencsg/opencsg-phi-2-v0.1) |
|
45 |
+
| opencsg-stable-coder-3b-v1 |[opencsg/Opencsg-stable-coder-3b-v1](https://huggingface.co/opencsg/opencsg-stable-code-3b-v1)|
|
46 |
+
|
47 |
+
## Model Eval
|
48 |
+
|
49 |
+
HumanEval is the most common code generation benchmark for evaluating model performance, especially on the compeltion of code exercise cases.
|
50 |
+
Model evaluation is, to some extent, a metaphysics. Different models have different sensitivities to decoding methods, parameters and instructions.
|
51 |
+
It is impratical for us to manually set specific configurations for each fine-tuned model, because a real LLM should master general capabilities despite the parameters being manipulated by users.
|
52 |
+
|
53 |
+
Therefore, OpenCSG racked their brains to provide a relatively fair method to compare the fine-tuned models on the HumanEval benchmark.
|
54 |
+
To simplify the comparison, we chosed the Pass@1 metric for the Python language, but our fine-tuning dataset includes samples in multiple languages.
|
55 |
+
|
56 |
+
**For fairness, we evaluated the original and fine-tuned phi-2 models based only on the prompts from the original cases, without including any other instructions.**
|
57 |
+
|
58 |
+
**Besides, we use the greedy decoding method for each model during evaluation.**
|
59 |
+
|
60 |
+
| Model | HumanEval python pass@1 |
|
61 |
+
| --- |----------------------------------------------------------------------------- |
|
62 |
+
| phi-2 | 48.2% |
|
63 |
+
| **opencsg-phi-2-v0.1** |**54.3%**|
|
64 |
+
| stable-coder-3b | 29.3%|
|
65 |
+
| **opencsg-stable-coder-3b-v1**| **46.3%** |
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
**TODO**
|
70 |
+
- We will provide more benchmark scores on fine-tuned models in the future.
|
71 |
+
- We will provide different practical problems to evaluate the performance of fine-tuned models in the field of software engineering.
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
# Model Usage
|
76 |
+
|
77 |
+
```
|
78 |
+
import torch
|
79 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
80 |
+
|
81 |
+
torch.set_default_device("cuda")
|
82 |
+
|
83 |
+
model = AutoModelForCausalLM.from_pretrained("opencsg/opencsg-phi-2-v0.1", torch_dtype="auto", trust_remote_code=True)
|
84 |
+
tokenizer = AutoTokenizer.from_pretrained("opencsg/opencsg-phi-2-v0.1", trust_remote_code=True)
|
85 |
+
|
86 |
+
inputs = tokenizer('''def print_prime(n):
|
87 |
+
"""
|
88 |
+
Print all primes between 1 and n
|
89 |
+
"""''', return_tensors="pt", return_attention_mask=False)
|
90 |
+
|
91 |
+
outputs = model.generate(**inputs, max_length=200)
|
92 |
+
text = tokenizer.batch_decode(outputs)[0]
|
93 |
+
print(text)
|
94 |
+
```
|
95 |
+
|
96 |
+
# Training
|
97 |
+
|
98 |
+
## Hardware
|
99 |
+
|
100 |
+
- **GPUs:** 8 Tesla A800
|
101 |
+
- **Training time:** 4 hours
|
102 |
+
|
103 |
+
## Software
|
104 |
+
|
105 |
+
- **Orchestration:** [Deepspeed](https://github.com/OpenCSGs)
|
106 |
+
- **Neural networks:** [PyTorch](https://github.com/pytorch/pytorch)
|
107 |
+
- **BP16 if applicable:** [apex](https://github.com/NVIDIA/apex)
|
108 |
+
|
109 |
+
|
110 |
+
<a id="chinese"></a>
|
111 |
+
|
112 |
+
<p>
|
113 |
+
|
114 |
+
</p>
|
115 |
+
|
116 |
+
# OpenCSG介绍
|
117 |
+
|
118 |
+
|
119 |
+
<p align="center">
|
120 |
+
<img width="300px" alt="OpenCSG" src="https://cdn-uploads.huggingface.co/production/uploads/64c71b27d43e4dee51a8b31a/GwYXPKuEoGCGcMICeW-sb.jpeg">
|
121 |
+
</p>
|
122 |
+
|
123 |
+
<p align="center"><a href="https://opencsg.com/models">[OpenCSG 社区]</a> <a href="https://github.com/opencsgs">[github]</a> <a href="https://cdn-uploads.huggingface.co/production/uploads/64c71b27d43e4dee51a8b31a/HU6vz21qKTEmUBCWqCFh9.jpeg">[微信]</a> <a href="https://twitter.com/OpenCsg">[推特]</a> </p>
|
124 |
+
|
125 |
+
|
126 |
+
|
127 |
+
</div>
|
128 |
+
OpenCSG 致力于资源融合、软件求精和生成式 LM。其中,“C”代表资源融合(Converged resources),表示多种混合资源的整合和充分利用。 “S”代表软件求精(Software refinement),表示通过大模型精炼过的软件。 “G”代表生成型语言模型(Generative LM),它表示广泛使用的、包容性的、经过民主化的生成式大模型。
|
129 |
+
|
130 |
+
OpenCSG 的愿景是让每个行业、每个公司、每个人都拥有自己的模型。 我们坚持开放开源的原则,将OpenCSG的大模型栈提供给社区。 欢迎大家积极使用、反馈想法和贡献内容。
|
131 |
+
|
132 |
+
|
133 |
+
|
134 |
+
## 模型介绍
|
135 |
+
|
136 |
+
|
137 |
+
Phi-2是一个拥有27亿参数的Transformer模型,使用了经过增强的数据源进行训练,包括合成的NLP文本和经过筛选的网站,同时还使用了Phi-1.5使用的现有数据。尽管参数少于130亿,但它在常识、语言理解和逻辑推理的基准测试中表现出了接近最先进的水平。
|
138 |
+
与一些模型不同,Phi-2没有通过人类反馈的强化学习进行微调。这个开源模型的目标是促进对安全挑战的研究,如减少毒性、理解偏见、增强可控性等。
|
139 |
+
|
140 |
+
opencsg-phi-2-v0.1是基于phi-2的通过全参数微调方法进行调优的模型。
|
141 |
+
<br>
|
142 |
+
|
143 |
+
这是基于 [phi-2](https://huggingface.co/microsoft/phi-2) 进行微调的模型版本。
|
144 |
+
|
145 |
+
| 模型大小 | 基座模型 |
|
146 |
+
| --- | ----------------------------------------------------------------------------- |
|
147 |
+
| 2.7B | [opencsg/Opencsg-phi-2-v0.1](https://huggingface.co/opencsg/opencsg-phi-2-v0.1) |
|
148 |
+
| opencsg-stable-coder-3b-v1 |[opencsg/Opencsg-stable-coder-3b-v1](https://huggingface.co/opencsg/opencsg-stable-code-3b-v1)|
|
149 |
+
|
150 |
+
|
151 |
+
## 模型评估
|
152 |
+
|
153 |
+
HumanEval 是评估模型在代码生成方面性能的最常见的基准,尤其是在代码习题的补全方面。
|
154 |
+
模型评估在某种程度上是一种玄学。不同的模型对解码方法、参数和指令的敏感度不同,
|
155 |
+
优秀的大模型是具备通用能力的,而不会因为解码参数的调整使得模型的生成表现有很大的差异。
|
156 |
+
|
157 |
+
因此,OpenCSG 提供了一个相对公平的方法来在 HumanEval 基准上比较各微调模型。
|
158 |
+
方便起见,我们选择了Python语言Pass@1指标,但要注意的是,我们的微调数据集是包含多种编程语言。
|
159 |
+
|
160 |
+
**为了公平起见,我们仅根据原始问题的提示来评估原始和微调过的 phi-2 模型,不包含任何其他说明。**
|
161 |
+
|
162 |
+
**除此之外,我们在评估过程中对每个模型都使用贪婪解码方法。**
|
163 |
+
|
164 |
+
| 模型 | HumanEval python pass@1 |
|
165 |
+
| --- |----------------------------------------------------------------------------- |
|
166 |
+
| phi-2 | 48.2% |
|
167 |
+
| **opencsg-phi-2-v0.1** |**54.3%**|
|
168 |
+
| stable-coder-3b | 29.3%|
|
169 |
+
| **opencsg-stable-coder-3b-v1**| **46.3%** |
|
170 |
+
|
171 |
+
|
172 |
+
|
173 |
+
**TODO**
|
174 |
+
- 未来我们将提供更多微调模型的在各基准上的分数。
|
175 |
+
- 我们将提供不同的实际问题来评估微调模型在软件工程领域的性能。
|
176 |
+
|
177 |
+
|
178 |
+
|
179 |
+
# 模型使用
|
180 |
+
|
181 |
+
```
|
182 |
+
import torch
|
183 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
184 |
+
|
185 |
+
torch.set_default_device("cuda")
|
186 |
+
|
187 |
+
model = AutoModelForCausalLM.from_pretrained("opencsg/opencsg-phi-2-v0.1", torch_dtype="auto", trust_remote_code=True)
|
188 |
+
tokenizer = AutoTokenizer.from_pretrained("opencsg/opencsg-phi-2-v0.1", trust_remote_code=True)
|
189 |
+
|
190 |
+
inputs = tokenizer('''def print_prime(n):
|
191 |
+
"""
|
192 |
+
Print all primes between 1 and n
|
193 |
+
"""''', return_tensors="pt", return_attention_mask=False)
|
194 |
+
|
195 |
+
outputs = model.generate(**inputs, max_length=200)
|
196 |
+
text = tokenizer.batch_decode(outputs)[0]
|
197 |
+
print(text)
|
198 |
+
```
|
199 |
+
# 训练
|
200 |
+
|
201 |
+
## 硬件资源
|
202 |
+
|
203 |
+
- **GPU数量:** 8 Tesla A800
|
204 |
+
- **训练时间:** 4 小时
|
205 |
+
|
206 |
+
## 软件使用
|
207 |
+
|
208 |
+
- **微调训练框架:** [Deepspeed](https://github.com/OpenCSGs)
|
209 |
+
- **深度学习框架:** [PyTorch](https://github.com/pytorch/pytorch)
|
210 |
+
- **BP16:** [apex](https://github.com/NVIDIA/apex)
|