File size: 4,374 Bytes
8046c68 15eb8ca 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 15eb8ca 43864c1 8046c68 43864c1 15eb8ca 43864c1 8046c68 15eb8ca 43864c1 8046c68 43864c1 15eb8ca 43864c1 8046c68 15eb8ca 43864c1 8046c68 15eb8ca 43864c1 8046c68 43864c1 15eb8ca 8046c68 15eb8ca 8046c68 15eb8ca 8046c68 15eb8ca 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 15eb8ca 43864c1 8046c68 43864c1 8046c68 43864c1 8046c68 43864c1 15eb8ca 43864c1 8046c68 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
---
license: mit
tags:
- codellama
- linux
- bugfix
- lora
- qlora
- git-diff
base_model: codellama/CodeLLaMA-7b-Instruct-hf
model_type: LlamaForCausalLM
library_name: peft
pipeline_tag: text-generation
---
# CodeLLaMA-Linux-BugFix
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.
---
## π― Overview
This project targets automated Linux kernel bug fixing by:
- **Mining real commit data** from the kernel Git history
- **Training a specialized QLoRA model** on diff-style fixes
- **Generating Git patches** in response to bug-prone code
- **Evaluating results** using BLEU, ROUGE, and human inspection
---
## π§ Model Configuration
- **Base model**: `CodeLLaMA-7B-Instruct`
- **Fine-tuning method**: QLoRA with 4-bit quantization
- **Training setup**:
- LoRA r=64, alpha=16, dropout=0.1
- Batch size: 64, LR: 2e-4, Epochs: 3
- Mixed precision (bfloat16), gradient checkpointing
- **Hardware**: Optimized for NVIDIA H200 GPUs
---
## π Dataset
Custom dataset extracted from Linux kernel Git history.
### Filtering Criteria
Bug-fix commits containing:
`fix`, `bug`, `crash`, `memory`, `null`, `panic`, `overflow`, `race`, `corruption`, etc.
### Structure
- Language: C (`.c`, `.h`)
- Context: 10 lines before/after the change
- Format:
```json
{
"input": {
"original code": "C code snippet with bug",
"instruction": "Commit message or fix description"
},
"output": {
"diff codes": "Git diff showing the fix"
}
}
````
* **File**: `training_data_100k.jsonl` (100,000 samples)
---
## π Quick Start
### Install dependencies
```bash
pip install -r requirements.txt
```
### 1. Build the Dataset
```bash
cd dataset_builder
python extract_linux_bugfixes.py
python format_for_training.py
```
### 2. Fine-tune the Model
```bash
cd train
python train_codellama_qlora_linux_bugfix.py
```
### 3. Run Evaluation
```bash
cd evaluate
python evaluate_linux_bugfix_model.py
```
---
## π Project Structure
```
CodeLLaMA-Linux-BugFix/
βββ dataset_builder/
β βββ extract_linux_bugfixes.py
β βββ extract_linux_bugfixes_parallel.py
β βββ format_for_training.py
βββ dataset/
β βββ training_data_100k.jsonl
β βββ training_data_prompt_completion.jsonl
βββ train/
β βββ train_codellama_qlora_linux_bugfix.py
β βββ train_codellama_qlora_simple.py
β βββ download_codellama_model.py
β βββ output/
βββ evaluate/
β βββ evaluate_linux_bugfix_model.py
β βββ test_samples.jsonl
β βββ output/
βββ requirements.txt
```
---
## π§© Features
* π§ **Efficient Fine-tuning**: QLoRA + 4-bit quant = massive memory savings
* π§ **Real-world commits**: From actual Linux kernel development
* π‘ **Context-aware**: Code context extraction around bug lines
* π» **Output-ready**: Generates valid Git-style diffs
---
## π Evaluation Metrics
* **BLEU**: Translation-style match to reference diffs
* **ROUGE**: Overlap in fix content
* **Human Evaluation**: Subjective patch quality
---
## π§ͺ Use Cases
* Automated kernel bug fixing
* Code review assistance
* Teaching/debugging kernel code
* Research in automated program repair (APR)
---
## π¬ Technical Highlights
### Memory & Speed Optimizations
* 4-bit quantization (NF4)
* Gradient checkpointing
* Mixed precision (bfloat16)
* Gradient accumulation
---
## π€ Contributing
1. Fork this repo
2. Create a branch
3. Add your feature or fix
4. Submit a PR π
---
## π License
MIT License β see `LICENSE` file for details.
---
## π Acknowledgments
* Meta for CodeLLaMA
* Hugging Face for Transformers + PEFT
* The Linux kernel community for open access to commit data
* Microsoft for introducing LoRA
---
## π References
* [CodeLLaMA (Meta, 2023)](https://arxiv.org/abs/2308.12950)
* [QLoRA (Dettmers et al., 2023)](https://arxiv.org/abs/2305.14314)
* [LoRA (Hu et al., 2021)](https://arxiv.org/abs/2106.09685)
|