Mac
commited on
Commit
Β·
8046c68
1
Parent(s):
15eb8ca
Update README with Hugging Face metadata and full project description
Browse files
README.md
CHANGED
@@ -1,182 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# CodeLLaMA-Linux-BugFix
|
2 |
|
3 |
-
A
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
|
6 |
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
- **Training a specialized model** using QLoRA for efficient fine-tuning
|
11 |
-
- **Generating Git diff patches** that can be applied to fix bugs
|
12 |
-
- **Providing evaluation metrics** to assess model performance
|
13 |
|
14 |
-
##
|
15 |
|
16 |
-
|
17 |
-
- **
|
18 |
-
- **
|
19 |
-
-
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
- **LoRA Config**: r=64, alpha=16, dropout=0.1
|
23 |
-
- **Training**: 3 epochs, batch size 64, learning rate 2e-4
|
24 |
-
- **Memory Optimization**: Gradient checkpointing, mixed precision training
|
25 |
|
26 |
## π Dataset
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
###
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
### Dataset Statistics
|
55 |
-
- **Training Data**: 100K samples (`training_data_100k.jsonl`)
|
56 |
-
- **Format**: JSONL (one JSON object per line)
|
57 |
-
- **Source**: Linux kernel Git repository
|
58 |
|
59 |
## π Quick Start
|
60 |
|
61 |
-
###
|
|
|
62 |
```bash
|
63 |
pip install -r requirements.txt
|
64 |
```
|
65 |
|
66 |
-
### 1. Build Dataset
|
|
|
67 |
```bash
|
68 |
cd dataset_builder
|
69 |
python extract_linux_bugfixes.py
|
70 |
python format_for_training.py
|
71 |
```
|
72 |
|
73 |
-
### 2.
|
|
|
74 |
```bash
|
75 |
cd train
|
76 |
python train_codellama_qlora_linux_bugfix.py
|
77 |
```
|
78 |
|
79 |
-
### 3.
|
|
|
80 |
```bash
|
81 |
cd evaluate
|
82 |
python evaluate_linux_bugfix_model.py
|
83 |
```
|
84 |
|
|
|
|
|
85 |
## π Project Structure
|
86 |
|
87 |
```
|
88 |
CodeLLaMA-Linux-BugFix/
|
89 |
-
βββ dataset_builder/
|
90 |
-
β βββ extract_linux_bugfixes.py
|
91 |
-
β βββ extract_linux_bugfixes_parallel.py
|
92 |
β βββ format_for_training.py
|
93 |
-
βββ dataset/
|
94 |
β βββ training_data_100k.jsonl
|
95 |
β βββ training_data_prompt_completion.jsonl
|
96 |
-
βββ train/
|
97 |
-
β βββ train_codellama_qlora_linux_bugfix.py
|
98 |
β βββ train_codellama_qlora_simple.py
|
99 |
β βββ download_codellama_model.py
|
100 |
-
β βββ output/
|
101 |
-
βββ evaluate/
|
102 |
-
β βββ evaluate_linux_bugfix_model.py
|
103 |
-
β βββ test_samples.jsonl
|
104 |
-
β βββ output/
|
105 |
-
βββ requirements.txt
|
106 |
```
|
107 |
|
108 |
-
|
109 |
|
110 |
-
|
111 |
-
- **QLoRA**: Reduces memory requirements by 75% while maintaining performance
|
112 |
-
- **4-bit Quantization**: Enables training on consumer hardware
|
113 |
-
- **Gradient Checkpointing**: Optimizes memory usage during training
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
|
120 |
-
|
121 |
-
- **BLEU Score**: Measures translation quality
|
122 |
-
- **ROUGE Score**: Evaluates text generation accuracy
|
123 |
-
- **Comprehensive Metrics**: JSON and CSV output formats
|
124 |
|
125 |
-
##
|
126 |
|
127 |
-
|
|
|
|
|
128 |
|
129 |
-
|
130 |
-
2. **Code Review**: Suggest fixes during development
|
131 |
-
3. **Learning**: Study patterns in Linux kernel bug fixes
|
132 |
-
4. **Research**: Advance automated software repair techniques
|
133 |
|
134 |
-
##
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
|
141 |
-
|
142 |
|
143 |
-
|
144 |
-
- **Base**: CodeLLaMA-7B-Instruct with instruction tuning
|
145 |
-
- **Adapter**: LoRA layers for efficient fine-tuning
|
146 |
-
- **Output**: Generates Git diff format patches
|
147 |
|
148 |
-
###
|
149 |
-
1. **Data Preprocessing**: Extract and clean commit data
|
150 |
-
2. **Tokenization**: Convert to model input format
|
151 |
-
3. **QLoRA Training**: Efficient parameter-efficient fine-tuning
|
152 |
-
4. **Checkpointing**: Save model states for evaluation
|
153 |
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
|
|
|
|
158 |
|
159 |
## π€ Contributing
|
160 |
|
161 |
-
1. Fork
|
162 |
-
2. Create a
|
163 |
-
3.
|
164 |
-
4.
|
165 |
-
|
|
|
166 |
|
167 |
## π License
|
168 |
|
169 |
-
|
|
|
|
|
170 |
|
171 |
## π Acknowledgments
|
172 |
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
|
|
|
|
177 |
|
178 |
## π References
|
179 |
|
180 |
-
|
181 |
-
|
182 |
-
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
tags:
|
4 |
+
- codellama
|
5 |
+
- linux
|
6 |
+
- bugfix
|
7 |
+
- lora
|
8 |
+
- qlora
|
9 |
+
- git-diff
|
10 |
+
base_model: codellama/CodeLLaMA-7b-Instruct-hf
|
11 |
+
model_type: LlamaForCausalLM
|
12 |
+
library_name: peft
|
13 |
+
pipeline_tag: text-generation
|
14 |
+
---
|
15 |
+
|
16 |
# CodeLLaMA-Linux-BugFix
|
17 |
|
18 |
+
A fine-tuned version of `CodeLLaMA-7B-Instruct`, designed specifically for Linux kernel bug fixing using QLoRA (Quantized Low-Rank Adaptation). The model learns to generate Git diff patches based on buggy C code and commit messages.
|
19 |
+
|
20 |
+
---
|
21 |
+
|
22 |
+
## π― Overview
|
23 |
|
24 |
+
This project targets automated Linux kernel bug fixing by:
|
25 |
|
26 |
+
- **Mining real commit data** from the kernel Git history
|
27 |
+
- **Training a specialized QLoRA model** on diff-style fixes
|
28 |
+
- **Generating Git patches** in response to bug-prone code
|
29 |
+
- **Evaluating results** using BLEU, ROUGE, and human inspection
|
30 |
|
31 |
+
---
|
|
|
|
|
|
|
32 |
|
33 |
+
## π§ Model Configuration
|
34 |
|
35 |
+
- **Base model**: `CodeLLaMA-7B-Instruct`
|
36 |
+
- **Fine-tuning method**: QLoRA with 4-bit quantization
|
37 |
+
- **Training setup**:
|
38 |
+
- LoRA r=64, alpha=16, dropout=0.1
|
39 |
+
- Batch size: 64, LR: 2e-4, Epochs: 3
|
40 |
+
- Mixed precision (bfloat16), gradient checkpointing
|
41 |
+
- **Hardware**: Optimized for NVIDIA H200 GPUs
|
42 |
|
43 |
+
---
|
|
|
|
|
|
|
44 |
|
45 |
## π Dataset
|
46 |
|
47 |
+
Custom dataset extracted from Linux kernel Git history.
|
48 |
+
|
49 |
+
### Filtering Criteria
|
50 |
+
Bug-fix commits containing:
|
51 |
+
`fix`, `bug`, `crash`, `memory`, `null`, `panic`, `overflow`, `race`, `corruption`, etc.
|
52 |
+
|
53 |
+
### Structure
|
54 |
+
- Language: C (`.c`, `.h`)
|
55 |
+
- Context: 10 lines before/after the change
|
56 |
+
- Format:
|
57 |
+
|
58 |
+
```json
|
59 |
+
{
|
60 |
+
"input": {
|
61 |
+
"original code": "C code snippet with bug",
|
62 |
+
"instruction": "Commit message or fix description"
|
63 |
+
},
|
64 |
+
"output": {
|
65 |
+
"diff codes": "Git diff showing the fix"
|
66 |
+
}
|
67 |
+
}
|
68 |
+
````
|
69 |
+
|
70 |
+
* **File**: `training_data_100k.jsonl` (100,000 samples)
|
71 |
+
|
72 |
+
---
|
|
|
|
|
|
|
|
|
73 |
|
74 |
## π Quick Start
|
75 |
|
76 |
+
### Install dependencies
|
77 |
+
|
78 |
```bash
|
79 |
pip install -r requirements.txt
|
80 |
```
|
81 |
|
82 |
+
### 1. Build the Dataset
|
83 |
+
|
84 |
```bash
|
85 |
cd dataset_builder
|
86 |
python extract_linux_bugfixes.py
|
87 |
python format_for_training.py
|
88 |
```
|
89 |
|
90 |
+
### 2. Fine-tune the Model
|
91 |
+
|
92 |
```bash
|
93 |
cd train
|
94 |
python train_codellama_qlora_linux_bugfix.py
|
95 |
```
|
96 |
|
97 |
+
### 3. Run Evaluation
|
98 |
+
|
99 |
```bash
|
100 |
cd evaluate
|
101 |
python evaluate_linux_bugfix_model.py
|
102 |
```
|
103 |
|
104 |
+
---
|
105 |
+
|
106 |
## π Project Structure
|
107 |
|
108 |
```
|
109 |
CodeLLaMA-Linux-BugFix/
|
110 |
+
βββ dataset_builder/
|
111 |
+
β βββ extract_linux_bugfixes.py
|
112 |
+
β βββ extract_linux_bugfixes_parallel.py
|
113 |
β βββ format_for_training.py
|
114 |
+
βββ dataset/
|
115 |
β βββ training_data_100k.jsonl
|
116 |
β βββ training_data_prompt_completion.jsonl
|
117 |
+
βββ train/
|
118 |
+
β βββ train_codellama_qlora_linux_bugfix.py
|
119 |
β βββ train_codellama_qlora_simple.py
|
120 |
β βββ download_codellama_model.py
|
121 |
+
β βββ output/
|
122 |
+
βββ evaluate/
|
123 |
+
β βββ evaluate_linux_bugfix_model.py
|
124 |
+
β βββ test_samples.jsonl
|
125 |
+
β βββ output/
|
126 |
+
βββ requirements.txt
|
127 |
```
|
128 |
|
129 |
+
---
|
130 |
|
131 |
+
## π§© Features
|
|
|
|
|
|
|
132 |
|
133 |
+
* π§ **Efficient Fine-tuning**: QLoRA + 4-bit quant = massive memory savings
|
134 |
+
* π§ **Real-world commits**: From actual Linux kernel development
|
135 |
+
* π‘ **Context-aware**: Code context extraction around bug lines
|
136 |
+
* π» **Output-ready**: Generates valid Git-style diffs
|
137 |
|
138 |
+
---
|
|
|
|
|
|
|
139 |
|
140 |
+
## π Evaluation Metrics
|
141 |
|
142 |
+
* **BLEU**: Translation-style match to reference diffs
|
143 |
+
* **ROUGE**: Overlap in fix content
|
144 |
+
* **Human Evaluation**: Subjective patch quality
|
145 |
|
146 |
+
---
|
|
|
|
|
|
|
147 |
|
148 |
+
## π§ͺ Use Cases
|
149 |
|
150 |
+
* Automated kernel bug fixing
|
151 |
+
* Code review assistance
|
152 |
+
* Teaching/debugging kernel code
|
153 |
+
* Research in automated program repair (APR)
|
154 |
|
155 |
+
---
|
156 |
|
157 |
+
## π¬ Technical Highlights
|
|
|
|
|
|
|
158 |
|
159 |
+
### Memory & Speed Optimizations
|
|
|
|
|
|
|
|
|
160 |
|
161 |
+
* 4-bit quantization (NF4)
|
162 |
+
* Gradient checkpointing
|
163 |
+
* Mixed precision (bfloat16)
|
164 |
+
* Gradient accumulation
|
165 |
+
|
166 |
+
---
|
167 |
|
168 |
## π€ Contributing
|
169 |
|
170 |
+
1. Fork this repo
|
171 |
+
2. Create a branch
|
172 |
+
3. Add your feature or fix
|
173 |
+
4. Submit a PR π
|
174 |
+
|
175 |
+
---
|
176 |
|
177 |
## π License
|
178 |
|
179 |
+
MIT License β see `LICENSE` file for details.
|
180 |
+
|
181 |
+
---
|
182 |
|
183 |
## π Acknowledgments
|
184 |
|
185 |
+
* Meta for CodeLLaMA
|
186 |
+
* Hugging Face for Transformers + PEFT
|
187 |
+
* The Linux kernel community for open access to commit data
|
188 |
+
* Microsoft for introducing LoRA
|
189 |
+
|
190 |
+
---
|
191 |
|
192 |
## π References
|
193 |
|
194 |
+
* [CodeLLaMA (Meta, 2023)](https://arxiv.org/abs/2308.12950)
|
195 |
+
* [QLoRA (Dettmers et al., 2023)](https://arxiv.org/abs/2305.14314)
|
196 |
+
* [LoRA (Hu et al., 2021)](https://arxiv.org/abs/2106.09685)
|