Run this model with HF Jobs
Run Maaac/CodeLLaMA-Linux-BugFix on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/Maaac/CodeLLaMA-Linux-BugFix. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Maaac/CodeLLaMA-Linux-BugFix on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/Maaac/CodeLLaMA-Linux-BugFix. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/Maaac/CodeLLaMA-Linux-BugFix. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use Maaac/CodeLLaMA-Linux-BugFix with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use Maaac/CodeLLaMA-Linux-BugFix with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files1234567891011121314151617305 unmodified lines323324325---license: mittags:- codellama- linux- bugfix- lora- qlora- git-diffbase_model: codellama/CodeLLaMA-7b-Instruct-hfmodel_type: LlamaForCausalLMlibrary_name: peftpipeline_tag: text-generation---# CodeLLaMA-Linux-BugFix305 unmodified lines- **v1.0.0**: Initial release with QLoRA training- **v1.1.0**: Added parallel dataset extraction- **v1.2.0**: Improved evaluation metrics and documentation123456789101112131415161718192021222324252627282930313233343536373839404142305 unmodified lines348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676---license: mittags:- codellama- linux- bugfix- lora- qlora- git-diffbase_model: codellama/CodeLLaMA-7b-Instruct-hfmodel_type: LlamaForCausalLMlibrary_name: peftpipeline_tag: text-generationmodel-index:- name: CodeLLaMA-Linux-BugFixresults:- task:type: text-generationname: Bug-fix Patch Generationdataset:type: customname: Linux Kernel Bugfix Commitsconfig: linux-bugfix-prompt-completionsplit: testmetrics:- type: bleuvalue: 33.87name: BLEU- type: rouge1value: 0.4355name: ROUGE-1 F1- type: rouge2value: 0.3457name: ROUGE-2 F1- type: rougeLvalue: 0.3612name: ROUGE-L F1---# CodeLLaMA-Linux-BugFix305 unmodified lines- **v1.0.0**: Initial release with QLoRA training- **v1.1.0**: Added parallel dataset extraction- **v1.2.0**: Improved evaluation metrics and documentation=======---license: mittags:- codellama- linux- bugfix- lora- qlora- git-diffbase_model: codellama/CodeLLaMA-7b-Instruct-hfmodel_type: LlamaForCausalLMlibrary_name: peftpipeline_tag: text-generation---# CodeLLaMA-Linux-BugFixA 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.---## π― OverviewThis 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 inspectionThe model achieves strong performance in generating accurate Linux kernel bug fixes, making it a valuable tool for automated code review and bug detection.---## π Performance Results### Evaluation Metricsβ **BLEU Score**: 33.87β **ROUGE Scores**:- **ROUGE-1**: P=0.3775, R=0.7306, F1=0.4355- **ROUGE-2**: P=0.2898, R=0.6096, F1=0.3457- **ROUGE-L**: P=0.3023, R=0.6333, F1=0.3612These results demonstrate the model's ability to:- Generate syntactically correct Git diff patches- Maintain semantic similarity to reference fixes- Produce meaningful code changes that address the underlying bugs---## π§ 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---## π DatasetCustom dataset extracted from Linux kernel Git history.### Filtering CriteriaBug-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### Prerequisites- Python 3.8+- CUDA-compatible GPU (recommended)- 16GB+ RAM- 50GB+ disk space### Install dependencies```bashpip install -r requirements.txt```### 1. Build the Dataset```bashcd dataset_builderpython extract_linux_bugfixes_parallel.pypython format_for_training.py```### 2. Fine-tune the Model```bashcd trainpython train_codellama_qlora_linux_bugfix.py```### 3. Run Evaluation```bashcd evaluatepython evaluate_linux_bugfix_model.py```### 4. Use the Model```pythonfrom transformers import AutoTokenizer, AutoModelForCausalLMfrom peft import PeftModel# Load the fine-tuned modelmodel = AutoModelForCausalLM.from_pretrained("codellama/CodeLLaMA-7b-Instruct-hf")model = PeftModel.from_pretrained(model, "train/output/qlora-codellama-bugfix")tokenizer = AutoTokenizer.from_pretrained("codellama/CodeLLaMA-7b-Instruct-hf")# Generate a bug fixprompt = """Given the following original C code:if (!file->filter)return;Instruction: Fix the null pointer dereferenceReturn the diff that fixes it:"""inputs = tokenizer(prompt, return_tensors="pt")outputs = model.generate(**inputs, max_length=512, temperature=0.1)fix = tokenizer.decode(outputs[0], skip_special_tokens=True)print(fix)```---## π Project Structure```CodeLLaMA-Linux-BugFix/βββ dataset_builder/β βββ extract_linux_bugfixes_parallel.py # Parallel extraction of bug fixesβ βββ format_for_training.py # Format data for trainingβ βββ build_dataset.py # Main dataset builderβββ dataset/β βββ training_data_100k.jsonl # 100K training samplesβ βββ training_data_prompt_completion.jsonl # Formatted training dataβββ train/β βββ train_codellama_qlora_linux_bugfix.py # Main training scriptβ βββ train_codellama_qlora_simple.py # Simplified trainingβ βββ download_codellama_model.py # Model download utilityβ βββ output/β βββ qlora-codellama-bugfix/ # Trained model checkpointsβββ evaluate/β βββ evaluate_linux_bugfix_model.py # Evaluation scriptβ βββ test_samples.jsonl # Test datasetβ βββ output/ # Evaluation resultsβ βββ eval_results.csv # Detailed resultsβ βββ eval_results.json # JSON format resultsβββ requirements.txt # Python dependenciesβββ README.md # This fileβββ PROJECT_STRUCTURE.md # Detailed project overview```---## π§© 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* π **Strong Performance**: BLEU score of 33.87 with good ROUGE metrics* π **Production-ready**: Optimized for real-world deployment---## π Evaluation Metrics* **BLEU**: Translation-style match to reference diffs* **ROUGE**: Overlap in fix content and semantic similarity* **Human Evaluation**: Subjective patch quality assessment### Current Performance- **BLEU Score**: 33.87 (excellent for code generation tasks)- **ROUGE-1 F1**: 0.4355 (good semantic overlap)- **ROUGE-2 F1**: 0.3457 (reasonable bigram matching)- **ROUGE-L F1**: 0.3612 (good longest common subsequence)---## π§ͺ Use Cases* **Automated kernel bug fixing**: Generate fixes for common kernel bugs* **Code review assistance**: Help reviewers identify potential issues* **Teaching/debugging kernel code**: Educational tool for kernel development* **Research in automated program repair (APR)**: Academic research applications* **CI/CD integration**: Automated testing and fixing in development pipelines---## π¬ Technical Highlights### Memory & Speed Optimizations* 4-bit quantization (NF4)* Gradient checkpointing* Mixed precision (bfloat16)* Gradient accumulation* LoRA parameter efficiency### Training Efficiency* **QLoRA**: Reduces memory usage by ~75%* **4-bit quantization**: Further memory optimization* **Gradient checkpointing**: Trades compute for memory* **Mixed precision**: Faster training with maintained accuracy---## π οΈ Advanced Usage### Custom Training```bash# Train with custom parameterspython train_codellama_qlora_linux_bugfix.py \--learning_rate 1e-4 \--num_epochs 5 \--batch_size 32 \--lora_r 32 \--lora_alpha 16```### Evaluation on Custom Data```bash# Evaluate on your own test setpython evaluate_linux_bugfix_model.py \--test_file your_test_data.jsonl \--output_dir custom_eval_results```---## π€ Contributing1. Fork this repo2. Create a feature branch (`git checkout -b feature/amazing-feature`)3. Commit your changes (`git commit -m 'Add amazing feature'`)4. Push to the branch (`git push origin feature/amazing-feature`)5. Open a Pull Request π### Development Guidelines- Follow PEP 8 style guidelines- Add tests for new features- Update documentation for API changes- Ensure all tests pass before submitting PR---## π LicenseMIT License β see `LICENSE` file for details.---## π Acknowledgments* **Meta** for CodeLLaMA base model* **Hugging Face** for Transformers + PEFT libraries* **The Linux kernel community** for open access to commit data* **Microsoft** for introducing LoRA technique* **University of Washington** for QLoRA research---## π 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)* [Automated Program Repair: A Survey](https://ieeexplore.ieee.org/document/8449519)---## π SupportFor questions, issues, or contributions:- Open an issue on GitHub- Check the project documentation- Review the evaluation results in `evaluate/output/`---## π Version History- **v1.0.0**: Initial release with QLoRA training- **v1.1.0**: Added parallel dataset extraction- **v1.2.0**: Improved evaluation metrics and documentation
README.md+365-14