Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: bigscience-openrail-m
|
| 3 |
+
pipeline_tag: text-generation
|
| 4 |
+
tags:
|
| 5 |
+
- code
|
| 6 |
+
- automated program repair
|
| 7 |
+
---
|
| 8 |
+
# StarCoder-15B_for_NTR
|
| 9 |
+
|
| 10 |
+
We fine-tuned [StarCoder-15B](https://huggingface.co/bigcode/starcoder) on [Transfer_dataset](https://drive.google.com/drive/folders/1Z-2xcLSmh643BfX_j0yQW2GmdPoru6j3?usp=drive_link) under the NMT workflow [[Jiang et al.](https://github.com/lin-tan/clm), [Huang et al.](https://github.com/LLMC-APR/STUDY)] for APR research.
|
| 11 |
+
|
| 12 |
+
## Model Use
|
| 13 |
+
|
| 14 |
+
To use this model, please make sure to install transformers, peft, bitsandbytes, and accelerate.
|
| 15 |
+
|
| 16 |
+
```bash
|
| 17 |
+
pip install transformers
|
| 18 |
+
pip install peft
|
| 19 |
+
pip install bitsandbytes
|
| 20 |
+
pip install accelerate
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
Then, please run the following script to merge the adapter into the CodeLlama.
|
| 24 |
+
|
| 25 |
+
```bash
|
| 26 |
+
bash merge.sh
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
Finally, you can load the model to generate patches for buggy code.
|
| 30 |
+
|
| 31 |
+
```python
|
| 32 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 33 |
+
from peft import LoraConfig, get_peft_model, prepare_model_for_int8_training
|
| 34 |
+
import torch
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
# load model and tokenizer
|
| 38 |
+
|
| 39 |
+
tokenizer = AutoTokenizer.from_pretrained('bigcode/starcoderbase', use_auth_token=True)
|
| 40 |
+
|
| 41 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 42 |
+
"StarCoder-15B_for_NMT/Epoch_1/-merged",
|
| 43 |
+
use_auth_token=True,
|
| 44 |
+
use_cache=True,
|
| 45 |
+
load_in_8bit=True,
|
| 46 |
+
device_map="auto"
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
model = prepare_model_for_int8_training(model)
|
| 50 |
+
|
| 51 |
+
lora_config = LoraConfig(
|
| 52 |
+
r=16,
|
| 53 |
+
lora_alpha=32,
|
| 54 |
+
lora_dropout=0.05,
|
| 55 |
+
bias="none",
|
| 56 |
+
task_type="CAUSAL_LM",
|
| 57 |
+
target_modules = ["c_proj", "c_attn", "q_attn"]
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
model = get_peft_model(model, lora_config)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
# a bug-fix pairs
|
| 64 |
+
|
| 65 |
+
buggy_code = "
|
| 66 |
+
public MultiplePiePlot(CategoryDataset dataset){
|
| 67 |
+
super();
|
| 68 |
+
// bug_start
|
| 69 |
+
this.dataset=dataset;
|
| 70 |
+
// bug_end
|
| 71 |
+
PiePlot piePlot=new PiePlot(null);
|
| 72 |
+
this.pieChart=new JFreeChart(piePlot);
|
| 73 |
+
this.pieChart.removeLegend();
|
| 74 |
+
this.dataExtractOrder=TableOrder.BY_COLUMN;
|
| 75 |
+
this.pieChart.setBackgroundPaint(null);
|
| 76 |
+
TextTitle seriesTitle=new TextTitle("Series Title",new Font("SansSerif",Font.BOLD,12));
|
| 77 |
+
seriesTitle.setPosition(RectangleEdge.BOTTOM);
|
| 78 |
+
this.pieChart.setTitle(seriesTitle);
|
| 79 |
+
this.aggregatedItemsKey="Other";
|
| 80 |
+
this.aggregatedItemsPaint=Color.lightGray;
|
| 81 |
+
this.sectionPaints=new HashMap();
|
| 82 |
+
}
|
| 83 |
+
"
|
| 84 |
+
|
| 85 |
+
fixed_code = "
|
| 86 |
+
// fix_start
|
| 87 |
+
setDataset(dataset);
|
| 88 |
+
// fix_end
|
| 89 |
+
"
|
| 90 |
+
|
| 91 |
+
# model inference
|
| 92 |
+
|
| 93 |
+
input_text = '<commit_before>\n' + buggy_code + '\n<commit_after>\n'
|
| 94 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(0)
|
| 95 |
+
|
| 96 |
+
eos_id = tokenizer.convert_tokens_to_ids(tokenizer.eos_token)
|
| 97 |
+
generated_ids = model.generate(
|
| 98 |
+
input_ids=input_ids,
|
| 99 |
+
max_new_tokens=256,
|
| 100 |
+
num_beams=10,
|
| 101 |
+
num_return_sequences=10,
|
| 102 |
+
early_stopping=True,
|
| 103 |
+
pad_token_id=eos_id,
|
| 104 |
+
eos_token_id=eos_id
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
for generated_id in generated_ids:
|
| 108 |
+
generated_text = tokenizer.decode(generated_id, skip_special_tokens=False)
|
| 109 |
+
patch = generated_text.split('\n<commit_after>\n')[1]
|
| 110 |
+
patch = patch.replace('<|endoftext|>','')
|
| 111 |
+
print(patch)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
## Model Details
|
| 117 |
+
The model is licensed under the BigCode OpenRAIL-M v1 license agreement. You can find the full agreement [here](https://huggingface.co/spaces/bigcode/bigcode-model-license-agreement).
|