Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,242 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
-
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
# Model Card for
|
7 |
-
|
8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
-
|
10 |
-
|
11 |
|
12 |
## Model Details
|
13 |
|
14 |
### Model Description
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
19 |
|
20 |
-
- **Developed by:**
|
21 |
-
- **
|
22 |
-
- **
|
23 |
-
- **Model type:** [More Information Needed]
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model
|
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 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
39 |
-
|
40 |
### Direct Use
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
[More Information Needed]
|
45 |
-
|
46 |
-
### Downstream Use [optional]
|
47 |
-
|
48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
49 |
-
|
50 |
-
[More Information Needed]
|
51 |
|
52 |
### Out-of-Scope Use
|
53 |
|
54 |
-
|
55 |
|
56 |
-
|
|
|
57 |
|
58 |
## Bias, Risks, and Limitations
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
[More Information Needed]
|
63 |
|
64 |
### Recommendations
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
69 |
|
70 |
## How to Get Started with the Model
|
71 |
|
72 |
Use the code below to get started with the model.
|
73 |
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
## Training Details
|
77 |
|
78 |
### Training Data
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
[More Information Needed]
|
83 |
|
84 |
### Training Procedure
|
85 |
|
86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
-
|
88 |
-
#### Preprocessing [optional]
|
89 |
-
|
90 |
-
[More Information Needed]
|
91 |
-
|
92 |
-
|
93 |
#### Training Hyperparameters
|
94 |
|
95 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
#### Speeds, Sizes, Times [optional]
|
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 |
-
|
144 |
-
|
145 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
**APA:**
|
180 |
|
181 |
-
[
|
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 |
-
[
|
196 |
|
197 |
## Model Card Contact
|
198 |
|
199 |
-
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
+
license: bigcode-openrail-m
|
4 |
+
datasets:
|
5 |
+
- AlfredPros/smart-contracts-instructions
|
6 |
+
language:
|
7 |
+
- en
|
8 |
---
|
9 |
|
10 |
+
# Model Card for Starcoder2-15B Fine-Tuned with QLORA on Solidity Dataset
|
|
|
|
|
|
|
|
|
11 |
|
12 |
## Model Details
|
13 |
|
14 |
### Model Description
|
15 |
|
16 |
+
This model has been fine-tuned using QLORA to generate Solidity smart contracts from natural language instructions. Training was done using the same dataset used to train [https://huggingface.co/yoniebans/starcoder2-3b-qlora-solidity](starcoder2-3b-qlora-solidity). This should allow for a direct comparison between the two models. The `starcoder2-15b` base model benefits from having being trained on a lot more code that also included solidity code for reference.
|
|
|
|
|
17 |
|
18 |
+
- **Developed by:** @yoniebans
|
19 |
+
- **Model type:** Transformer-based Causal Language Model
|
20 |
+
- **Language(s) (NLP):** English with programming language syntax (Solidity)
|
|
|
|
|
21 |
- **License:** [More Information Needed]
|
22 |
+
- **Finetuned from model** bigcode/starcoder2-15b
|
23 |
|
24 |
### Model Sources [optional]
|
25 |
|
|
|
|
|
26 |
- **Repository:** [More Information Needed]
|
|
|
27 |
- **Demo [optional]:** [More Information Needed]
|
28 |
|
29 |
## Uses
|
30 |
|
|
|
|
|
31 |
### Direct Use
|
32 |
|
33 |
+
This model was created to demonstrate how fine-tuning a base model such as starcoder2-15b using qlora can increase the model's ability to create Solidity code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
### Out-of-Scope Use
|
36 |
|
37 |
+
This model is not intended for:
|
38 |
|
39 |
+
- Deployment in production systems without rigorous testing.
|
40 |
+
- Use in non-technical text generation or any context outside smart contract development.
|
41 |
|
42 |
## Bias, Risks, and Limitations
|
43 |
|
44 |
+
The training data consists of code from publicly sourced Solidity projects which may not encompass the full diversity of programming styles and techniques. The Solidity source code originates from mwritescode's Slither Audited Smart Contracts (https://huggingface.co/datasets/mwritescode/slither-audited-smart-contracts).
|
|
|
|
|
45 |
|
46 |
### Recommendations
|
47 |
|
48 |
+
Users are advised to use this model as a starting point for development and not as a definitive solution. Generated code should always be reviewed by experienced developers to ensure security and functionality.
|
|
|
|
|
49 |
|
50 |
## How to Get Started with the Model
|
51 |
|
52 |
Use the code below to get started with the model.
|
53 |
|
54 |
+
```python
|
55 |
+
import sys, torch, accelerate
|
56 |
+
from peft import PeftModel
|
57 |
+
from transformers import BitsAndBytesConfig, AutoTokenizer, AutoModelForCausalLM
|
58 |
+
|
59 |
+
use_4bit = True
|
60 |
+
bnb_4bit_compute_dtype = "float32"
|
61 |
+
bnb_4bit_quant_type = "nf4"
|
62 |
+
use_double_nested_quant = True
|
63 |
+
compute_dtype = getattr(torch, bnb_4bit_compute_dtype)
|
64 |
+
|
65 |
+
device_map = "auto"
|
66 |
+
max_memory = '75000MB'
|
67 |
+
n_gpus = torch.cuda.device_count()
|
68 |
+
max_memory = {i: max_memory for i in range(n_gpus)}
|
69 |
+
|
70 |
+
checkpoint = "bigcode/starcoder2-15b"
|
71 |
+
model = AutoModelForCausalLM.from_pretrained(
|
72 |
+
checkpoint,
|
73 |
+
cache_dir=None,
|
74 |
+
device_map=device_map,
|
75 |
+
max_memory=max_memory,
|
76 |
+
quantization_config=BitsAndBytesConfig(
|
77 |
+
load_in_4bit=use_4bit,
|
78 |
+
llm_int8_threshold=6.0,
|
79 |
+
llm_int8_has_fp16_weight=False,
|
80 |
+
bnb_4bit_compute_dtype=compute_dtype,
|
81 |
+
bnb_4bit_use_double_quant=use_double_nested_quant,
|
82 |
+
bnb_4bit_quant_type=bnb_4bit_quant_type
|
83 |
+
),
|
84 |
+
torch_dtype=torch.float32,
|
85 |
+
trust_remote_code=False
|
86 |
+
)
|
87 |
+
|
88 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
89 |
+
checkpoint,
|
90 |
+
cache_dir=None,
|
91 |
+
padding_side="right",
|
92 |
+
use_fast=False,
|
93 |
+
tokenizer_type=None, # Needed for HF name change
|
94 |
+
trust_remote_code=False,
|
95 |
+
use_auth_token=False,
|
96 |
+
)
|
97 |
+
|
98 |
+
if tokenizer._pad_token is None:
|
99 |
+
num_new_tokens = tokenizer.add_special_tokens(dict(pad_token="[PAD]"))
|
100 |
+
model.resize_token_embeddings(len(tokenizer))
|
101 |
+
|
102 |
+
if num_new_tokens > 0:
|
103 |
+
input_embeddings_data = model.get_input_embeddings().weight.data
|
104 |
+
output_embeddings_data = model.get_output_embeddings().weight.data
|
105 |
+
|
106 |
+
input_embeddings_avg = input_embeddings_data[:-num_new_tokens].mean(dim=0, keepdim=True)
|
107 |
+
output_embeddings_avg = output_embeddings_data[:-num_new_tokens].mean(dim=0, keepdim=True)
|
108 |
+
|
109 |
+
input_embeddings_data[-num_new_tokens:] = input_embeddings_avg
|
110 |
+
output_embeddings_data[-num_new_tokens:] = output_embeddings_avg
|
111 |
+
|
112 |
+
local_adapter_weights = "yoniebans/starcoder2-15b-qlora-solidity"
|
113 |
+
model = PeftModel.from_pretrained(model, local_adapter_weights)
|
114 |
+
|
115 |
+
input='Make a smart contract for a memecoin named 'LLMAI', adhering to the ERC20 standard. The contract should enforce a purchase limit where no individual wallet can acquire more than 1% of the total token supply, which is set at 10 billion tokens. This purchasing limit should be modifiable and can only be disabled by the contract owner at their discretion. Note that the interfaces for ERC20, Ownable, and any other dependencies should be assumed as already imported and do not need to be included in your code response.'
|
116 |
+
|
117 |
+
prompt = f"""### Instruction:
|
118 |
+
Use the Task below and the Input given to write the Response, which is a programming code that can solve the following Task:
|
119 |
+
|
120 |
+
### Task:
|
121 |
+
{input}
|
122 |
+
|
123 |
+
### Solution:
|
124 |
+
"""
|
125 |
+
|
126 |
+
input_ids = tokenizer(prompt, return_tensors="pt", truncation=True).input_ids.cuda()
|
127 |
+
outputs = model.generate(
|
128 |
+
input_ids=input_ids,
|
129 |
+
max_new_tokens=2048,
|
130 |
+
do_sample=True,
|
131 |
+
top_p=0.9,
|
132 |
+
temperature=0.001,
|
133 |
+
pad_token_id=1
|
134 |
+
)
|
135 |
+
|
136 |
+
output_text = tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0]
|
137 |
+
output_text_without_prompt = output_text[len(prompt):]
|
138 |
+
|
139 |
+
file_path = './smart_contract.sol'
|
140 |
+
|
141 |
+
with open(file_path, 'w') as file:
|
142 |
+
file.write(output_text_without_prompt)
|
143 |
+
|
144 |
+
print(f"Output written to {file_path}")
|
145 |
+
```
|
146 |
|
147 |
## Training Details
|
148 |
|
149 |
### Training Data
|
150 |
|
151 |
+
The model was trained on a dataset consisting of pairs of natural language instructions and their corresponding Solidity code implementations. This dataset includes over 6000 input and outputs.
|
|
|
|
|
152 |
|
153 |
### Training Procedure
|
154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
#### Training Hyperparameters
|
156 |
|
157 |
+
- Number of train epochs: 6
|
158 |
+
- Double quant: true
|
159 |
+
- Quant type: nf4
|
160 |
+
- Bits: 4
|
161 |
+
- Lora r: 64
|
162 |
+
- Lora aplha: 16
|
163 |
+
- Lora dropout: 0.0
|
164 |
+
- Per device train batch size: 1
|
165 |
+
- Gradient accumulation steps: 1
|
166 |
+
- Max steps: 2000
|
167 |
+
- Weight decay: 0.0 #use lora dropout instead for regularization if needed
|
168 |
+
- Learning rate: 2e-4
|
169 |
+
- Max gradient normal: 0.3
|
170 |
+
- Gradient checkpointing: true
|
171 |
+
- FP16: false
|
172 |
+
- FP16 option level: O1
|
173 |
+
- BF16: false
|
174 |
+
- Optimizer: paged AdamW 32-bit
|
175 |
+
- Learning rate scheduler type: constant
|
176 |
+
- Warmup ratio: 0.03
|
177 |
|
178 |
#### Speeds, Sizes, Times [optional]
|
179 |
|
180 |
+
| Epoch | Grad Norm | Loss | Step |
|
181 |
+
|-------|-----------|------|------|
|
182 |
+
| 0.03 | 0.299587 | 0.9556 | 10 |
|
183 |
+
| 0.30 | 0.496698 | 0.6772 | 100 |
|
184 |
+
| 0.59 | 0.249761 | 0.5784 | 200 |
|
185 |
+
| 0.89 | 0.233806 | 0.6166 | 300 |
|
186 |
+
| 1.18 | 0.141580 | 0.3541 | 400 |
|
187 |
+
| 1.48 | 0.129458 | 0.3517 | 500 |
|
188 |
+
| 1.78 | 0.114603 | 0.3793 | 600 |
|
189 |
+
| 2.07 | 0.085970 | 0.3937 | 700 |
|
190 |
+
| 2.37 | 0.085016 | 0.3209 | 800 |
|
191 |
+
| 2.67 | 0.097650 | 0.3716 | 900 |
|
192 |
+
| 2.96 | 0.093905 | 0.3437 | 1000 |
|
193 |
+
| 3.26 | 0.137684 | 0.3026 | 1100 |
|
194 |
+
| 3.55 | 0.137903 | 0.3432 | 1200 |
|
195 |
+
| 3.85 | 0.103362 | 0.3310 | 1300 |
|
196 |
+
| 4.15 | 0.174095 | 0.3567 | 1400 |
|
197 |
+
| 4.44 | 0.203337 | 0.3279 | 1500 |
|
198 |
+
| 4.74 | 0.229325 | 0.4026 | 1600 |
|
199 |
+
| 5.04 | 0.134137 | 0.1737 | 1700 |
|
200 |
+
| 5.33 | 0.113009 | 0.2132 | 1800 |
|
201 |
+
| 5.63 | 0.066551 | 0.2207 | 1900 |
|
202 |
+
| 5.92 | 0.136091 | 0.2193 | 2000 |
|
203 |
+
|
204 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/65e20784f70c00af9691d07b/OxGiUiSUMZEsdLWuYU2jl.png)
|
|
|
|
|
205 |
|
206 |
### Results
|
207 |
|
|
|
|
|
208 |
#### Summary
|
209 |
|
210 |
+
Initial evaluations show promising results in generating Solidity code. More work required to understand effectiveness of input promt and max_length for training and inference.
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
|
212 |
## Environmental Impact
|
213 |
|
214 |
+
- **Hardware Type:** NVIDIA A100 • 80GB (80 GB VRAM) • 117 GB RAM • 8 vCPU
|
215 |
+
- **Hours used:** 8
|
216 |
+
- **Cloud Provider:** https://www.runpod.io
|
|
|
|
|
|
|
|
|
217 |
- **Compute Region:** [More Information Needed]
|
218 |
- **Carbon Emitted:** [More Information Needed]
|
219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
## Citation [optional]
|
221 |
|
|
|
|
|
222 |
**BibTeX:**
|
223 |
+
```
|
224 |
+
@misc{lozhkov2024starcoder,
|
225 |
+
title={StarCoder 2 and The Stack v2: The Next Generation},
|
226 |
+
author={Anton Lozhkov and Raymond Li and Loubna Ben Allal and Federico Cassano and Joel Lamy-Poirier and Nouamane Tazi and Ao Tang and Dmytro Pykhtar and Jiawei Liu and Yuxiang Wei and Tianyang Liu and Max Tian and Denis Kocetkov and Arthur Zucker and Younes Belkada and Zijian Wang and Qian Liu and Dmitry Abulkhanov and Indraneil Paul and Zhuang Li and Wen-Ding Li and Megan Risdal and Jia Li and Jian Zhu and Terry Yue Zhuo and Evgenii Zheltonozhskii and Nii Osae Osae Dade and Wenhao Yu and Lucas Krauß and Naman Jain and Yixuan Su and Xuanli He and Manan Dey and Edoardo Abati and Yekun Chai and Niklas Muennighoff and Xiangru Tang and Muhtasham Oblokulov and Christopher Akiki and Marc Marone and Chenghao Mou and Mayank Mishra and Alex Gu and Binyuan Hui and Tri Dao and Armel Zebaze and Olivier Dehaene and Nicolas Patry and Canwen Xu and Julian McAuley and Han Hu and Torsten Scholak and Sebastien Paquet and Jennifer Robinson and Carolyn Jane Anderson and Nicolas Chapados and Mostofa Patwary and Nima Tajbakhsh and Yacine Jernite and Carlos Muñoz Ferrandis and Lingming Zhang and Sean Hughes and Thomas Wolf and Arjun Guha and Leandro von Werra and Harm de Vries},
|
227 |
+
year={2024},
|
228 |
+
eprint={2402.19173},
|
229 |
+
archivePrefix={arXiv},
|
230 |
+
primaryClass={cs.SE}
|
231 |
+
}
|
232 |
+
```
|
233 |
|
234 |
**APA:**
|
235 |
|
236 |
+
Starcoder2-15B: BigCode Team. (2024). Starcoder2-15B [Software]. Available from https://huggingface.co/bigcode/starcoder2-15b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
|
238 |
+
AlfredPros Smart Contracts Instructions: AlfredPros. (2023). Smart Contracts Instructions [Data set]. Available from https://huggingface.co/datasets/AlfredPros/smart-contracts-instructions
|
239 |
|
240 |
## Model Card Contact
|
241 |
|
242 |
+
jonny@edennetwork.io
|