Update README.md
Browse files
README.md
CHANGED
|
@@ -1,17 +1,42 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# CodeLLaMA-Linux-BugFix
|
| 17 |
|
|
@@ -323,3 +348,329 @@
|
|
| 323 |
- **v1.0.0**: Initial release with QLoRA training
|
| 324 |
- **v1.1.0**: Added parallel dataset extraction
|
| 325 |
- **v1.2.0**: Improved evaluation metrics and documentation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
model-index:
|
| 16 |
+
- name: CodeLLaMA-Linux-BugFix
|
| 17 |
+
results:
|
| 18 |
+
- task:
|
| 19 |
+
type: text-generation
|
| 20 |
+
name: Bug-fix Patch Generation
|
| 21 |
+
dataset:
|
| 22 |
+
type: custom
|
| 23 |
+
name: Linux Kernel Bugfix Commits
|
| 24 |
+
config: linux-bugfix-prompt-completion
|
| 25 |
+
split: test
|
| 26 |
+
metrics:
|
| 27 |
+
- type: bleu
|
| 28 |
+
value: 33.87
|
| 29 |
+
name: BLEU
|
| 30 |
+
- type: rouge1
|
| 31 |
+
value: 0.4355
|
| 32 |
+
name: ROUGE-1 F1
|
| 33 |
+
- type: rouge2
|
| 34 |
+
value: 0.3457
|
| 35 |
+
name: ROUGE-2 F1
|
| 36 |
+
- type: rougeL
|
| 37 |
+
value: 0.3612
|
| 38 |
+
name: ROUGE-L F1
|
| 39 |
+
---
|
| 40 |
|
| 41 |
# CodeLLaMA-Linux-BugFix
|
| 42 |
|
|
|
|
| 348 |
- **v1.0.0**: Initial release with QLoRA training
|
| 349 |
- **v1.1.0**: Added parallel dataset extraction
|
| 350 |
- **v1.2.0**: Improved evaluation metrics and documentation
|
| 351 |
+
=======
|
| 352 |
+
---
|
| 353 |
+
license: mit
|
| 354 |
+
tags:
|
| 355 |
+
- codellama
|
| 356 |
+
- linux
|
| 357 |
+
- bugfix
|
| 358 |
+
- lora
|
| 359 |
+
- qlora
|
| 360 |
+
- git-diff
|
| 361 |
+
base_model: codellama/CodeLLaMA-7b-Instruct-hf
|
| 362 |
+
model_type: LlamaForCausalLM
|
| 363 |
+
library_name: peft
|
| 364 |
+
pipeline_tag: text-generation
|
| 365 |
+
---
|
| 366 |
+
|
| 367 |
+
# CodeLLaMA-Linux-BugFix
|
| 368 |
+
|
| 369 |
+
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.
|
| 370 |
+
|
| 371 |
+
---
|
| 372 |
+
|
| 373 |
+
## π― Overview
|
| 374 |
+
|
| 375 |
+
This project targets automated Linux kernel bug fixing by:
|
| 376 |
+
|
| 377 |
+
- **Mining real commit data** from the kernel Git history
|
| 378 |
+
- **Training a specialized QLoRA model** on diff-style fixes
|
| 379 |
+
- **Generating Git patches** in response to bug-prone code
|
| 380 |
+
- **Evaluating results** using BLEU, ROUGE, and human inspection
|
| 381 |
+
|
| 382 |
+
The model achieves strong performance in generating accurate Linux kernel bug fixes, making it a valuable tool for automated code review and bug detection.
|
| 383 |
+
|
| 384 |
+
---
|
| 385 |
+
|
| 386 |
+
## π Performance Results
|
| 387 |
+
|
| 388 |
+
### Evaluation Metrics
|
| 389 |
+
|
| 390 |
+
β
**BLEU Score**: 33.87
|
| 391 |
+
|
| 392 |
+
β
**ROUGE Scores**:
|
| 393 |
+
- **ROUGE-1**: P=0.3775, R=0.7306, F1=0.4355
|
| 394 |
+
- **ROUGE-2**: P=0.2898, R=0.6096, F1=0.3457
|
| 395 |
+
- **ROUGE-L**: P=0.3023, R=0.6333, F1=0.3612
|
| 396 |
+
|
| 397 |
+
These results demonstrate the model's ability to:
|
| 398 |
+
- Generate syntactically correct Git diff patches
|
| 399 |
+
- Maintain semantic similarity to reference fixes
|
| 400 |
+
- Produce meaningful code changes that address the underlying bugs
|
| 401 |
+
|
| 402 |
+
---
|
| 403 |
+
|
| 404 |
+
## π§ Model Configuration
|
| 405 |
+
|
| 406 |
+
- **Base model**: `CodeLLaMA-7B-Instruct`
|
| 407 |
+
- **Fine-tuning method**: QLoRA with 4-bit quantization
|
| 408 |
+
- **Training setup**:
|
| 409 |
+
- LoRA r=64, alpha=16, dropout=0.1
|
| 410 |
+
- Batch size: 64, LR: 2e-4, Epochs: 3
|
| 411 |
+
- Mixed precision (bfloat16), gradient checkpointing
|
| 412 |
+
- **Hardware**: Optimized for NVIDIA H200 GPUs
|
| 413 |
+
|
| 414 |
+
---
|
| 415 |
+
|
| 416 |
+
## π Dataset
|
| 417 |
+
|
| 418 |
+
Custom dataset extracted from Linux kernel Git history.
|
| 419 |
+
|
| 420 |
+
### Filtering Criteria
|
| 421 |
+
Bug-fix commits containing:
|
| 422 |
+
`fix`, `bug`, `crash`, `memory`, `null`, `panic`, `overflow`, `race`, `corruption`, etc.
|
| 423 |
+
|
| 424 |
+
### Structure
|
| 425 |
+
- Language: C (`.c`, `.h`)
|
| 426 |
+
- Context: 10 lines before/after the change
|
| 427 |
+
- Format:
|
| 428 |
+
|
| 429 |
+
```json
|
| 430 |
+
{
|
| 431 |
+
"input": {
|
| 432 |
+
"original code": "C code snippet with bug",
|
| 433 |
+
"instruction": "Commit message or fix description"
|
| 434 |
+
},
|
| 435 |
+
"output": {
|
| 436 |
+
"diff codes": "Git diff showing the fix"
|
| 437 |
+
}
|
| 438 |
+
}
|
| 439 |
+
```
|
| 440 |
+
|
| 441 |
+
* **File**: `training_data_100k.jsonl` (100,000 samples)
|
| 442 |
+
|
| 443 |
+
---
|
| 444 |
+
|
| 445 |
+
## π Quick Start
|
| 446 |
+
|
| 447 |
+
### Prerequisites
|
| 448 |
+
|
| 449 |
+
- Python 3.8+
|
| 450 |
+
- CUDA-compatible GPU (recommended)
|
| 451 |
+
- 16GB+ RAM
|
| 452 |
+
- 50GB+ disk space
|
| 453 |
+
|
| 454 |
+
### Install dependencies
|
| 455 |
+
|
| 456 |
+
```bash
|
| 457 |
+
pip install -r requirements.txt
|
| 458 |
+
```
|
| 459 |
+
|
| 460 |
+
### 1. Build the Dataset
|
| 461 |
+
|
| 462 |
+
```bash
|
| 463 |
+
cd dataset_builder
|
| 464 |
+
python extract_linux_bugfixes_parallel.py
|
| 465 |
+
python format_for_training.py
|
| 466 |
+
```
|
| 467 |
+
|
| 468 |
+
### 2. Fine-tune the Model
|
| 469 |
+
|
| 470 |
+
```bash
|
| 471 |
+
cd train
|
| 472 |
+
python train_codellama_qlora_linux_bugfix.py
|
| 473 |
+
```
|
| 474 |
+
|
| 475 |
+
### 3. Run Evaluation
|
| 476 |
+
|
| 477 |
+
```bash
|
| 478 |
+
cd evaluate
|
| 479 |
+
python evaluate_linux_bugfix_model.py
|
| 480 |
+
```
|
| 481 |
+
|
| 482 |
+
### 4. Use the Model
|
| 483 |
+
|
| 484 |
+
```python
|
| 485 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 486 |
+
from peft import PeftModel
|
| 487 |
+
|
| 488 |
+
# Load the fine-tuned model
|
| 489 |
+
model = AutoModelForCausalLM.from_pretrained("codellama/CodeLLaMA-7b-Instruct-hf")
|
| 490 |
+
model = PeftModel.from_pretrained(model, "train/output/qlora-codellama-bugfix")
|
| 491 |
+
tokenizer = AutoTokenizer.from_pretrained("codellama/CodeLLaMA-7b-Instruct-hf")
|
| 492 |
+
|
| 493 |
+
# Generate a bug fix
|
| 494 |
+
prompt = """
|
| 495 |
+
Given the following original C code:
|
| 496 |
+
if (!file->filter)
|
| 497 |
+
return;
|
| 498 |
+
|
| 499 |
+
Instruction: Fix the null pointer dereference
|
| 500 |
+
|
| 501 |
+
Return the diff that fixes it:
|
| 502 |
+
"""
|
| 503 |
+
|
| 504 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 505 |
+
outputs = model.generate(**inputs, max_length=512, temperature=0.1)
|
| 506 |
+
fix = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 507 |
+
print(fix)
|
| 508 |
+
```
|
| 509 |
+
|
| 510 |
+
---
|
| 511 |
+
|
| 512 |
+
## π Project Structure
|
| 513 |
+
|
| 514 |
+
```
|
| 515 |
+
CodeLLaMA-Linux-BugFix/
|
| 516 |
+
βββ dataset_builder/
|
| 517 |
+
β βββ extract_linux_bugfixes_parallel.py # Parallel extraction of bug fixes
|
| 518 |
+
β βββ format_for_training.py # Format data for training
|
| 519 |
+
β βββ build_dataset.py # Main dataset builder
|
| 520 |
+
βββ dataset/
|
| 521 |
+
β βββ training_data_100k.jsonl # 100K training samples
|
| 522 |
+
β βββ training_data_prompt_completion.jsonl # Formatted training data
|
| 523 |
+
βββ train/
|
| 524 |
+
β βββ train_codellama_qlora_linux_bugfix.py # Main training script
|
| 525 |
+
β βββ train_codellama_qlora_simple.py # Simplified training
|
| 526 |
+
β βββ download_codellama_model.py # Model download utility
|
| 527 |
+
β βββ output/
|
| 528 |
+
β βββ qlora-codellama-bugfix/ # Trained model checkpoints
|
| 529 |
+
βββ evaluate/
|
| 530 |
+
β βββ evaluate_linux_bugfix_model.py # Evaluation script
|
| 531 |
+
β βββ test_samples.jsonl # Test dataset
|
| 532 |
+
β βββ output/ # Evaluation results
|
| 533 |
+
β βββ eval_results.csv # Detailed results
|
| 534 |
+
β βββ eval_results.json # JSON format results
|
| 535 |
+
βββ requirements.txt # Python dependencies
|
| 536 |
+
βββ README.md # This file
|
| 537 |
+
βββ PROJECT_STRUCTURE.md # Detailed project overview
|
| 538 |
+
```
|
| 539 |
+
|
| 540 |
+
---
|
| 541 |
+
|
| 542 |
+
## π§© Features
|
| 543 |
+
|
| 544 |
+
* π§ **Efficient Fine-tuning**: QLoRA + 4-bit quant = massive memory savings
|
| 545 |
+
* π§ **Real-world commits**: From actual Linux kernel development
|
| 546 |
+
* π‘ **Context-aware**: Code context extraction around bug lines
|
| 547 |
+
* π» **Output-ready**: Generates valid Git-style diffs
|
| 548 |
+
* π **Strong Performance**: BLEU score of 33.87 with good ROUGE metrics
|
| 549 |
+
* π **Production-ready**: Optimized for real-world deployment
|
| 550 |
+
|
| 551 |
+
---
|
| 552 |
+
|
| 553 |
+
## π Evaluation Metrics
|
| 554 |
+
|
| 555 |
+
* **BLEU**: Translation-style match to reference diffs
|
| 556 |
+
* **ROUGE**: Overlap in fix content and semantic similarity
|
| 557 |
+
* **Human Evaluation**: Subjective patch quality assessment
|
| 558 |
+
|
| 559 |
+
### Current Performance
|
| 560 |
+
- **BLEU Score**: 33.87 (excellent for code generation tasks)
|
| 561 |
+
- **ROUGE-1 F1**: 0.4355 (good semantic overlap)
|
| 562 |
+
- **ROUGE-2 F1**: 0.3457 (reasonable bigram matching)
|
| 563 |
+
- **ROUGE-L F1**: 0.3612 (good longest common subsequence)
|
| 564 |
+
|
| 565 |
+
---
|
| 566 |
+
|
| 567 |
+
## π§ͺ Use Cases
|
| 568 |
+
|
| 569 |
+
* **Automated kernel bug fixing**: Generate fixes for common kernel bugs
|
| 570 |
+
* **Code review assistance**: Help reviewers identify potential issues
|
| 571 |
+
* **Teaching/debugging kernel code**: Educational tool for kernel development
|
| 572 |
+
* **Research in automated program repair (APR)**: Academic research applications
|
| 573 |
+
* **CI/CD integration**: Automated testing and fixing in development pipelines
|
| 574 |
+
|
| 575 |
+
---
|
| 576 |
+
|
| 577 |
+
## π¬ Technical Highlights
|
| 578 |
+
|
| 579 |
+
### Memory & Speed Optimizations
|
| 580 |
+
|
| 581 |
+
* 4-bit quantization (NF4)
|
| 582 |
+
* Gradient checkpointing
|
| 583 |
+
* Mixed precision (bfloat16)
|
| 584 |
+
* Gradient accumulation
|
| 585 |
+
* LoRA parameter efficiency
|
| 586 |
+
|
| 587 |
+
### Training Efficiency
|
| 588 |
+
|
| 589 |
+
* **QLoRA**: Reduces memory usage by ~75%
|
| 590 |
+
* **4-bit quantization**: Further memory optimization
|
| 591 |
+
* **Gradient checkpointing**: Trades compute for memory
|
| 592 |
+
* **Mixed precision**: Faster training with maintained accuracy
|
| 593 |
+
|
| 594 |
+
---
|
| 595 |
+
|
| 596 |
+
## π οΈ Advanced Usage
|
| 597 |
+
|
| 598 |
+
### Custom Training
|
| 599 |
+
|
| 600 |
+
```bash
|
| 601 |
+
# Train with custom parameters
|
| 602 |
+
python train_codellama_qlora_linux_bugfix.py \
|
| 603 |
+
--learning_rate 1e-4 \
|
| 604 |
+
--num_epochs 5 \
|
| 605 |
+
--batch_size 32 \
|
| 606 |
+
--lora_r 32 \
|
| 607 |
+
--lora_alpha 16
|
| 608 |
+
```
|
| 609 |
+
|
| 610 |
+
### Evaluation on Custom Data
|
| 611 |
+
|
| 612 |
+
```bash
|
| 613 |
+
# Evaluate on your own test set
|
| 614 |
+
python evaluate_linux_bugfix_model.py \
|
| 615 |
+
--test_file your_test_data.jsonl \
|
| 616 |
+
--output_dir custom_eval_results
|
| 617 |
+
```
|
| 618 |
+
|
| 619 |
+
---
|
| 620 |
+
|
| 621 |
+
## π€ Contributing
|
| 622 |
+
|
| 623 |
+
1. Fork this repo
|
| 624 |
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
| 625 |
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
| 626 |
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
| 627 |
+
5. Open a Pull Request π
|
| 628 |
+
|
| 629 |
+
### Development Guidelines
|
| 630 |
+
|
| 631 |
+
- Follow PEP 8 style guidelines
|
| 632 |
+
- Add tests for new features
|
| 633 |
+
- Update documentation for API changes
|
| 634 |
+
- Ensure all tests pass before submitting PR
|
| 635 |
+
|
| 636 |
+
---
|
| 637 |
+
|
| 638 |
+
## π License
|
| 639 |
+
|
| 640 |
+
MIT License β see `LICENSE` file for details.
|
| 641 |
+
|
| 642 |
+
---
|
| 643 |
+
|
| 644 |
+
## π Acknowledgments
|
| 645 |
+
|
| 646 |
+
* **Meta** for CodeLLaMA base model
|
| 647 |
+
* **Hugging Face** for Transformers + PEFT libraries
|
| 648 |
+
* **The Linux kernel community** for open access to commit data
|
| 649 |
+
* **Microsoft** for introducing LoRA technique
|
| 650 |
+
* **University of Washington** for QLoRA research
|
| 651 |
+
|
| 652 |
+
---
|
| 653 |
+
|
| 654 |
+
## π References
|
| 655 |
+
|
| 656 |
+
* [CodeLLaMA (Meta, 2023)](https://arxiv.org/abs/2308.12950)
|
| 657 |
+
* [QLoRA (Dettmers et al., 2023)](https://arxiv.org/abs/2305.14314)
|
| 658 |
+
* [LoRA (Hu et al., 2021)](https://arxiv.org/abs/2106.09685)
|
| 659 |
+
* [Automated Program Repair: A Survey](https://ieeexplore.ieee.org/document/8449519)
|
| 660 |
+
|
| 661 |
+
---
|
| 662 |
+
|
| 663 |
+
## π Support
|
| 664 |
+
|
| 665 |
+
For questions, issues, or contributions:
|
| 666 |
+
- Open an issue on GitHub
|
| 667 |
+
- Check the project documentation
|
| 668 |
+
- Review the evaluation results in `evaluate/output/`
|
| 669 |
+
|
| 670 |
+
---
|
| 671 |
+
|
| 672 |
+
## π Version History
|
| 673 |
+
|
| 674 |
+
- **v1.0.0**: Initial release with QLoRA training
|
| 675 |
+
- **v1.1.0**: Added parallel dataset extraction
|
| 676 |
+
- **v1.2.0**: Improved evaluation metrics and documentation
|