Transformers
Safetensors
English
yoniebans commited on
Commit
c6894e6
·
verified ·
1 Parent(s): d35e761

Update README.md

Browse files

First draft for README.md

Files changed (1) hide show
  1. README.md +189 -128
README.md CHANGED
@@ -1,199 +1,260 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
-
8
- <!-- Provide a quick summary of what the model is/does. -->
9
-
10
-
11
 
12
  ## Model Details
13
 
14
  ### Model Description
15
 
16
- <!-- Provide a longer summary of what this model is. -->
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:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
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
- <!-- 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
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
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
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
 
56
- [More Information Needed]
 
57
 
58
  ## Bias, Risks, and Limitations
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
 
64
  ### Recommendations
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
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
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  ## Training Details
77
 
78
  ### Training Data
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
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
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
  #### Speeds, Sizes, Times [optional]
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
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
  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-3B 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 specifically for generating Solidity smart contracts from natural language instructions.
 
 
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-3b
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 is designed to demonstrate how fine-tuning a base model such as starcoder2-3b using qlora with a targetted dataset can increase the model's ability to create Solidity code directly from natural language descriptions or instructions.
 
 
 
 
 
 
 
 
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 primarily consists of code from publicly sourced Solidity projects which may not encompass the full diversity of programming styles and techniques used in professional environments. Users should be cautious of potential biases in generated code and always review and test code before use.
 
 
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
56
+ from peft import PeftModel
57
+ from transformers import BitsAndBytesConfig, AutoTokenizer, AutoModelForCausalLM
58
+ import torch
59
+ import accelerate
60
+
61
+ use_4bit = True
62
+ bnb_4bit_compute_dtype = "float32"
63
+ bnb_4bit_quant_type = "nf4"
64
+ use_double_nested_quant = True
65
+ compute_dtype = getattr(torch, bnb_4bit_compute_dtype)
66
+
67
+ device_map = "auto"
68
+ max_memory = '45000MB'
69
+ n_gpus = torch.cuda.device_count()
70
+ max_memory = {i: max_memory for i in range(n_gpus)}
71
+
72
+ model = AutoModelForCausalLM.from_pretrained(
73
+ "bigcode/starcoder2-3b",
74
+ cache_dir=None,
75
+ device_map=device_map,
76
+ max_memory=max_memory,
77
+ quantization_config=BitsAndBytesConfig(
78
+ load_in_4bit=use_4bit,
79
+ llm_int8_threshold=6.0,
80
+ llm_int8_has_fp16_weight=False,
81
+ bnb_4bit_compute_dtype=compute_dtype,
82
+ bnb_4bit_use_double_quant=use_double_nested_quant,
83
+ bnb_4bit_quant_type=bnb_4bit_quant_type
84
+ ),
85
+ torch_dtype=torch.float32,
86
+ trust_remote_code=False
87
+ )
88
+ adapter_weights = "yoniebans/starcoder2-3b-qlora-solidity"
89
+ model = PeftModel.from_pretrained(model, adapter_weights)
90
+
91
+ tokenizer = AutoTokenizer.from_pretrained(
92
+ checkpoint,
93
+ cache_dir=None,
94
+ padding_side="right",
95
+ use_fast=False,
96
+ tokenizer_type=None, # Needed for HF name change
97
+ trust_remote_code=False,
98
+ use_auth_token=False,
99
+ )
100
+
101
+
102
+ 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.'
103
+
104
+ prompt = f"""### Instruction:
105
+ Use the Task below and the Input given to write the Response, which is a programming code that can solve the following Task:
106
+
107
+ ### Task:
108
+ {input}
109
+
110
+ ### Solution:
111
+ """
112
+
113
+ input_ids = tokenizer(prompt, return_tensors="pt", truncation=True).input_ids.cuda()
114
+ outputs = model.generate(
115
+ input_ids=input_ids,
116
+ max_new_tokens=2048,
117
+ do_sample=True,
118
+ top_p=0.9,
119
+ temperature=0.001,
120
+ pad_token_id=1
121
+ )
122
+
123
+ output_text = tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0]
124
+ output_text_without_prompt = output_text[len(prompt):]
125
+
126
+ file_path = './smart_contract.sol'
127
+
128
+ with open(file_path, 'w') as file:
129
+ file.write(output_text_without_prompt)
130
+
131
+ print(f"Output written to {file_path}")
132
+ ```
133
 
134
  ## Training Details
135
 
136
  ### Training Data
137
 
138
+ The model was trained on a dataset consisting of pairs of natural language instructions and their corresponding Solidity code implementations. This dataset includes over [X examples] from diverse sources aimed at covering a broad range of smart contract functionalities.
 
 
139
 
140
  ### Training Procedure
141
 
 
 
 
 
 
 
 
142
  #### Training Hyperparameters
143
 
144
+ - Number of train epochs: 3
145
+ - Double quant: true
146
+ - Quant type: nf4
147
+ - Bits: 4
148
+ - Lora r: 64
149
+ - Lora aplha: 16
150
+ - Lora dropout: 0.0
151
+ - Per device train batch size: 1
152
+ - Gradient accumulation steps: 1
153
+ - Max steps: 10000
154
+ - Weight decay: 0.0 #use lora dropout instead for regularization if needed
155
+ - Learning rate: 2e-4
156
+ - Max gradient normal: 0.3
157
+ - Gradient checkpointing: true
158
+ - FP16: false
159
+ - FP16 option level: O1
160
+ - BF16: false
161
+ - Optimizer: paged AdamW 32-bit
162
+ - Learning rate scheduler type: constant
163
+ - Warmup ratio: 0.03
164
 
165
  #### Speeds, Sizes, Times [optional]
166
 
167
+ | Epoch | Grad Norm | Loss | Step |
168
+ |-------|-----------|------|------|
169
+ | 0.03 | 0.513248 | 2.0948 | 10 |
170
+ | 0.59 | 0.976398 | 0.7952 | 200 |
171
+ | 1.18 | 0.291436 | 0.5081 | 400 |
172
+ | 1.78 | 0.197318 | 0.5007 | 600 |
173
+ | 2.37 | 0.143200 | 0.4189 | 800 |
174
+ | 2.96 | 0.153539 | 0.4314 | 1000 |
175
+ | 3.55 | 0.199708 | 0.4554 | 1200 |
176
+ | 4.15 | 0.258209 | 0.4856 | 1400 |
177
+ | 4.74 | 0.295185 | 0.5446 | 1600 |
178
+ | 5.33 | 0.157903 | 0.3209 | 1800 |
179
+ | 5.92 | 0.149965 | 0.3203 | 2000 |
180
+ | 6.52 | 0.166200 | 0.4046 | 2200 |
181
+ | 7.11 | 0.181177 | 0.2157 | 2400 |
182
+ | 7.70 | 0.156556 | 0.2937 | 2600 |
183
+ | 8.29 | 0.309143 | 0.2928 | 2800 |
184
+ | 8.89 | 0.211304 | 0.3414 | 3000 |
185
+ | 9.48 | 0.166119 | 0.2716 | 3200 |
186
+ | 10.07 | 0.265576 | 0.1727 | 3400 |
187
+ | 10.66 | 0.231398 | 0.2219 | 3600 |
188
+ | 11.26 | 0.183477 | 0.1706 | 3800 |
189
+ | 11.85 | 0.182451 | 0.1471 | 4000 |
190
+ | 12.44 | 0.272920 | 0.1793 | 4200 |
191
+ | 13.03 | 0.189667 | 0.1241 | 4400 |
192
+ | 13.62 | 0.136364 | 0.1278 | 4600 |
193
+ | 14.22 | 0.297066 | 0.1043 | 4800 |
194
+ | 14.81 | 0.213272 | 0.1760 | 5000 |
195
+ | 15.40 | 0.162718 | 0.1062 | 5200 |
196
+ | 15.99 | 0.229559 | 0.1012 | 5400 |
197
+ | 16.59 | 0.271037 | 0.1180 | 5600 |
198
+ | 17.18 | 0.239012 | 0.0871 | 5800 |
199
+ | 17.77 | 0.175727 | 0.0894 | 6000 |
200
+ | 18.36 | 0.151963 | 0.1154 | 6200 |
201
+ | 18.96 | 0.202392 | 0.1096 | 6400 |
202
+ | 19.55 | 0.202703 | 0.0764 | 6600 |
203
+ | 20.18 | 0.148534 | 0.0551 | 6800 |
204
+ | 20.77 | 0.151745 | 0.0599 | 7000 |
205
+ | 21.36 | 0.188332 | 0.0707 | 7200 |
206
+ | 21.95 | 0.190111 | 0.0987 | 7400 |
207
+ | 22.55 | 0.163640 | 0.0567 | 7600 |
208
+ | 23.14 | 0.209854 | 0.0534 | 7800 |
209
+ | 23.73 | 0.225155 | 0.0626 | 8000 |
210
+ | 24.32 | 0.172093 | 0.0389 | 8200 |
211
+ | 24.92 | 0.162895 | 0.0347 | 8400 |
212
+ | 25.52 | 0.187249 | 0.0592 | 8600 |
213
+ | 26.11 | 0.182813 | 0.0368 | 8800 |
214
+ | 26.70 | 0.243531 | 0.0427 | 9000 |
215
+ | 27.29 | 0.190624 | 0.0325 | 9200 |
216
+ | 27.89 | 0.189085 | 0.0311 | 9400 |
217
+ | 28.48 | 0.171129 | 0.0322 | 9600 |
218
+ | 29.07 | 0.138704 | 0.0353 | 9800 |
219
+ | 29.66 | 0.216177 | 0.0312 | 10000 |
220
 
221
  ### Results
222
 
 
 
223
  #### Summary
224
 
225
+ Initial evaluations show promising results in generating syntactically correct Solidity code, with further testing planned to assess the semantic accuracy and security implications of the generated contracts.
 
 
 
 
 
 
226
 
227
  ## Environmental Impact
228
 
229
+ - **Hardware Type:** NVIDIA A40 GPU, 48GB VRAM, 48GB RAM, 9vCPU
230
+ - **Hours used:** 18
231
+ - **Cloud Provider:** runpod.io
 
 
 
 
232
  - **Compute Region:** [More Information Needed]
233
  - **Carbon Emitted:** [More Information Needed]
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  ## Citation [optional]
236
 
 
 
237
  **BibTeX:**
238
 
239
+ @misc{lozhkov2024starcoder,
240
+ title={StarCoder 2 and The Stack v2: The Next Generation},
241
+ 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},
242
+ year={2024},
243
+ eprint={2402.19173},
244
+ archivePrefix={arXiv},
245
+ primaryClass={cs.SE}
246
+ }
247
 
248
  **APA:**
249
 
250
+ Starcoder2-3B:
251
+ Author(s). (Year). Title [Software]. Available from URL
252
+ BigCode Team. (2024). Starcoder2-3B [Software]. Available from https://huggingface.co/bigcode/starcoder2-3b
 
 
 
 
 
 
 
 
 
 
253
 
254
+ AlfredPros Smart Contracts Instructions:
255
+ Author(s). (Year). Title [Data set]. Available from URL
256
+ AlfredPros. (2023). Smart Contracts Instructions [Data set]. Available from https://huggingface.co/datasets/AlfredPros/smart-contracts-instructions
257
 
258
  ## Model Card Contact
259
 
260