kristian-a commited on
Commit
556144a
1 Parent(s): ae0e8ca

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +98 -60
README.md CHANGED
@@ -1,51 +1,58 @@
1
  ---
2
  library_name: peft
3
  base_model: deepseek-ai/deepseek-coder-6.7b-instruct
 
 
 
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
 
 
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
 
@@ -53,75 +60,112 @@ base_model: deepseek-ai/deepseek-coder-6.7b-instruct
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
@@ -132,12 +176,6 @@ Use the code below to get started with the model.
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 -->
 
1
  ---
2
  library_name: peft
3
  base_model: deepseek-ai/deepseek-coder-6.7b-instruct
4
+ license: mit
5
+ language:
6
+ - en
7
  ---
8
 
9
  # Model Card for Model ID
10
+ Fine-tuned version of `deepseek-coder-6.7b-instruct` aiming to improve vulnerability detection in solidity smart contracts and provide informative explanations on what the vulnerabilities are, and how to solve them.
 
 
11
 
12
 
13
  ## Model Details
14
 
15
  ### Model Description
16
 
17
+ Given the following prompt below:
18
+ ```
19
+ Below are one or more Solidity codeblocks. The codeblocks might contain vulnerable code.
20
+ If there is a vulnerability please provide a description of the vulnearblity in terms of the code that is responsible for it.
21
+ Describe how an attacker would be able to take advantage of the vulnerability so the explanation is even more clear.
22
 
23
+ Output only the description of the vulnerability and the attacking vector. No additional information is needed.
24
 
25
+ If there is no vulnerability output "There is no vulnearbility".
26
 
27
+ Codeblocks:
28
+ {}
29
+ ```
 
 
 
 
30
 
31
+ When 1 or more codeblocks are provided to the model using this prompt, the model will output:
32
+ 1. Wether there is a vulnerability or not.
33
+ 2. What the vulnerability is.
34
+ 3. How an attacker would take advantage of the detected vulnerability.
35
 
36
+ Afterwards, the above output can be chained to produce a solution - the context has the code, the vulnerability and the attacking vector so deducing a solution becomes a more straight-forward task.
37
+ Additionally, the same fine-tuned model can be used for the solution recommendation as the fine-tuning is low-rank (LoRA) and a lot of the model ability is preserved.
38
 
 
 
 
 
 
39
 
40
+ - **Developed by:** [Kristian Apostolov]
41
+ - **Shared by:** [Kristian Apostolov]
42
+ - **Model type:** [Decoder]
43
+ - **Language(s) (NLP):** [English]
44
+ - **License:** [MIT]
45
+ - **Finetuned from model:** [deepseek-ai/deepseek-coder-6.7b-instruct]
46
 
47
+ ### Model Sources [optional]
48
 
49
+ - **Repository:** [https://huggingface.co/msc-smart-contract-auditing/deepseek-coder-6.7b-vulnerability-detection]
50
 
51
+ ## Uses
52
 
53
+ Provide code from a smart contract for a preliminary audit.
54
 
55
+ ### Direct Use
56
 
57
  [More Information Needed]
58
 
 
60
 
61
  <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
62
 
63
+ Malicious entity could detect 0-day vulnerability and take advantage of it.
64
 
65
  ## Bias, Risks, and Limitations
66
 
67
+ The training data could be improved. Audits sometimes describe vulnerabilities which are not necessarily contained in the code itself, but are a part of a larger context.
 
 
68
 
69
  ### Recommendations
70
 
71
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
 
 
72
 
73
  ## How to Get Started with the Model
74
 
75
  Use the code below to get started with the model.
76
 
77
+ ```python
78
+ model_name = 'msc-smart-contract-auditing/deepseek-coder-6.7b-vulnerability'
79
+ tokenizer = AutoTokenizer.from_pretrained( # For some reason the tokenizer didn't safe properly
80
+ "deepseek-ai/deepseek-coder-6.7b-instruct",
81
+ trust_remote_code=True,
82
+ force_download=True,
83
+ )
84
 
85
+ prompt = \
86
+ """
87
+ Below are one or more Solidity codeblocks. The codeblocks might contain vulnerable code.
88
+ If there is a vulnerability please provide a description of the vulnearblity in terms of the code that is responsible for it.
89
+ Describe how an attacker would be able to take advantage of the vulnerability so the explanation is even more clear.
90
 
91
+ Output only the description of the vulnerability and the attacking vector. No additional information is needed.
92
 
93
+ If there is no vulnerability output "There is no vulnearbility".
94
 
95
+ Codeblocks:
96
+ {}
97
 
98
+ """
99
 
100
+ codeblocks = "Your code here"
101
 
102
+ messages = [
103
+ { 'role': 'user', 'content': prompt.format(codeblocks) }
104
+ ]
105
 
106
+ inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
107
+ outputs = model.generate(inputs, max_new_tokens=512, do_sample=True, top_k=25, top_p=0.95, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)
108
+ description = tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True)
109
 
110
+ print(description)
111
+ ```
112
+ ## Training Details
113
 
114
+ ### Training Data
115
 
116
+ https://huggingface.co/datasets/msc-smart-contract-auditing/audits-with-reasons
117
 
118
+ ### Training Procedure
119
 
120
+ lora_config = LoraConfig(
121
+ r=16, # rank
122
+ lora_alpha=32, # scaling factor
123
+ target_modules = ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj",],
124
+ lora_dropout=0.05, # dropout rate for LoRA layers
125
+ )
126
+
127
+ model = get_peft_model(model, lora_config)
128
+
129
+ from transformers import Trainer, TrainingArguments
130
+
131
+ trainer = Trainer(
132
+ model=model,
133
+ args=TrainingArguments(
134
+ per_device_train_batch_size = 2,
135
+ gradient_accumulation_steps = 4,
136
+ warmup_steps = 5,
137
+ num_train_epochs = 1,
138
+ learning_rate = 2e-4,
139
+ fp16 = True,
140
+ logging_steps = 1,
141
+ optim = "adamw_8bit",
142
+ weight_decay = 0.01,
143
+ lr_scheduler_type = "linear",
144
+ seed = 3407,
145
+ output_dir = "outputs",
146
+ ),
147
+ train_dataset=train_prompts,
148
+ eval_dataset=test_prompts,
149
+ )
150
 
151
+ #### Training Hyperparameters
152
 
153
+ - **Training regime:** fp16 mixed precision
154
 
155
+ ## Evaluation
156
 
157
  ### Testing Data, Factors & Metrics
158
 
159
  #### Testing Data
160
 
161
+ https://huggingface.co/datasets/msc-smart-contract-auditing/audits-with-reasons
 
 
162
 
163
  #### Factors
164
 
 
 
165
  [More Information Needed]
166
 
167
  #### Metrics
168
 
 
 
169
  [More Information Needed]
170
 
171
  ### Results
 
176
 
177
 
178
 
 
 
 
 
 
 
179
  ## Environmental Impact
180
 
181
  <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->