Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# CodeLlama-70B_for_NTR
|
2 |
+
|
3 |
+
We fine-tuned [CodeLlama-70B](https://huggingface.co/codellama/CodeLlama-70b-hf) on [Transfer_dataset](https://drive.google.com/drive/folders/1F1BPfTxHDGX-OCBthudCbu_6Qvcg_fbP?usp=drive_link) under the [NTR](https://sites.google.com/view/neuraltemplaterepair) framework for APR research.
|
4 |
+
|
5 |
+
## Model Use
|
6 |
+
|
7 |
+
To use this model, please make sure to install transformers, peft, bitsandbytes, and accelerate.
|
8 |
+
|
9 |
+
```bash
|
10 |
+
pip install transformers
|
11 |
+
pip install peft
|
12 |
+
pip install bitsandbytes
|
13 |
+
pip install accelerate
|
14 |
+
```
|
15 |
+
|
16 |
+
Then, please run the following script to merge the adapter into the CodeLlama.
|
17 |
+
|
18 |
+
```bash
|
19 |
+
bash merge.sh
|
20 |
+
```
|
21 |
+
|
22 |
+
Finally, you can load the model to generate patches for buggy code.
|
23 |
+
|
24 |
+
```python
|
25 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
26 |
+
from peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training
|
27 |
+
import torch
|
28 |
+
|
29 |
+
|
30 |
+
# load model and tokenizer
|
31 |
+
|
32 |
+
tokenizer = AutoTokenizer.from_pretrained("CodeLlama-70B_for_NTR/Epoch_1/-merged", use_auth_token=True)
|
33 |
+
|
34 |
+
nf4_config = BitsAndBytesConfig(
|
35 |
+
load_in_4bit=True,
|
36 |
+
bnb_4bit_quant_type="nf4",
|
37 |
+
bnb_4bit_use_double_quant=True,
|
38 |
+
bnb_4bit_compute_dtype=torch.bfloat16
|
39 |
+
)
|
40 |
+
|
41 |
+
model = AutoModelForCausalLM.from_pretrained(
|
42 |
+
"CodeLlama-70B_for_NTR/Epoch_1/-merged",
|
43 |
+
quantization_config=nf4_config,
|
44 |
+
device_map='auto'
|
45 |
+
)
|
46 |
+
|
47 |
+
model = prepare_model_for_kbit_training(model)
|
48 |
+
|
49 |
+
lora_config = LoraConfig(
|
50 |
+
r=16,
|
51 |
+
lora_alpha=32,
|
52 |
+
lora_dropout=0.05,
|
53 |
+
bias="none",
|
54 |
+
task_type="CAUSAL_LM",
|
55 |
+
target_modules = ["q_proj", "k_proj", "v_proj", "o_proj"]
|
56 |
+
)
|
57 |
+
|
58 |
+
model = get_peft_model(model, lora_config)
|
59 |
+
|
60 |
+
|
61 |
+
# a bug-fix pairs
|
62 |
+
|
63 |
+
buggy_code = "
|
64 |
+
public MultiplePiePlot(CategoryDataset dataset){
|
65 |
+
super();
|
66 |
+
// bug_start
|
67 |
+
this.dataset=dataset;
|
68 |
+
// bug_end
|
69 |
+
PiePlot piePlot=new PiePlot(null);
|
70 |
+
this.pieChart=new JFreeChart(piePlot);
|
71 |
+
this.pieChart.removeLegend();
|
72 |
+
this.dataExtractOrder=TableOrder.BY_COLUMN;
|
73 |
+
this.pieChart.setBackgroundPaint(null);
|
74 |
+
TextTitle seriesTitle=new TextTitle("Series Title",new Font("SansSerif",Font.BOLD,12));
|
75 |
+
seriesTitle.setPosition(RectangleEdge.BOTTOM);
|
76 |
+
this.pieChart.setTitle(seriesTitle);
|
77 |
+
this.aggregatedItemsKey="Other";
|
78 |
+
this.aggregatedItemsPaint=Color.lightGray;
|
79 |
+
this.sectionPaints=new HashMap();
|
80 |
+
}
|
81 |
+
"
|
82 |
+
|
83 |
+
repair_template = "OtherTemplate"
|
84 |
+
|
85 |
+
fixed_code = "
|
86 |
+
// fix_start
|
87 |
+
setDataset(dataset);
|
88 |
+
// fix_end
|
89 |
+
"
|
90 |
+
|
91 |
+
# model inference
|
92 |
+
|
93 |
+
B_INST, E_INST = "[INST]", "[/INST]"
|
94 |
+
input_text = tokenizer.bos_token + B_INST +'\n[bug_function]\n' + buggy_code + '\n[fix_template]\n' + repair_template + '\n[fix_code]\n' + E_INST
|
95 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(0)
|
96 |
+
|
97 |
+
eos_id = tokenizer.convert_tokens_to_ids(tokenizer.eos_token)
|
98 |
+
generated_ids = model.generate(
|
99 |
+
input_ids=input_ids,
|
100 |
+
max_new_tokens=256,
|
101 |
+
num_beams=10,
|
102 |
+
num_return_sequences=10,
|
103 |
+
early_stopping=True,
|
104 |
+
pad_token_id=eos_id,
|
105 |
+
eos_token_id=eos_id
|
106 |
+
)
|
107 |
+
|
108 |
+
for generated_id in generated_ids:
|
109 |
+
generated_text = tokenizer.decode(generated_id, skip_special_tokens=False)
|
110 |
+
patch = generated_text.split(E_INST)[1]
|
111 |
+
patch = text.replace(tokenizer.eos_token,'')
|
112 |
+
print(patch)
|
113 |
+
|
114 |
+
|
115 |
+
```
|
116 |
+
|
117 |
+
## Model Details
|
118 |
+
*Note: Use of this model is governed by the Meta license. Meta developed and publicly released the Code Llama family of large language models (LLMs).
|