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
Mac commited on
Commit Β·
5de6ff4
1
Parent(s): bf46039
Push evaluation results and update readme
Browse filesFiles changed (3)
27 unmodified lines28293031323331 unmodified lines656667686970711 unmodified line7374757677784 unmodified lines8384858687888911 unmodified lines1011021031041051061 unmodified line1081091101111121131141151161171181191201211221231241251261271281294 unmodified lines1341351361371381391401411421431441451461471481491501511521531541551565 unmodified lines1621631641651661671681691701711721731741751765 unmodified lines1821831841851861871881891901912 unmodified lines19419519627 unmodified lines- **Generating Git patches** in response to bug-prone code- **Evaluating results** using BLEU, ROUGE, and human inspection---## π§ Model Configuration31 unmodified lines"diff codes": "Git diff showing the fix"}}````* **File**: `training_data_100k.jsonl` (100,000 samples)1 unmodified line## π Quick Start### Install dependencies```bash4 unmodified lines```bashcd dataset_builderpython extract_linux_bugfixes.pypython format_for_training.py```11 unmodified linespython evaluate_linux_bugfix_model.py```---## π Project Structure1 unmodified line```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```---4 unmodified lines* π§ **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)---5 unmodified lines* Gradient checkpointing* Mixed precision (bfloat16)* Gradient accumulation---## π€ Contributing1. Fork this repo2. Create a branch3. Add your feature or fix4. Submit a PR π---5 unmodified lines## π Acknowledgments* Meta for CodeLLaMA* Hugging Face for Transformers + PEFT* The Linux kernel community for open access to commit data* Microsoft for introducing LoRA---2 unmodified lines* [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)27 unmodified lines282930313233343536373839404142434445464748495051525331 unmodified lines858687888990911 unmodified line939495969798991001011021031041054 unmodified lines11011111211311411511611 unmodified lines1281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631 unmodified line1651661671681691701711721731741751761771781791801811821831841851861871881891901914 unmodified lines1961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262275 unmodified lines2332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872885 unmodified lines2942952962972982993003013023033042 unmodified lines30730830931031131231331431531631731831932032132232332432532632727 unmodified lines- **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 Configuration31 unmodified lines"diff codes": "Git diff showing the fix"}}```* **File**: `training_data_100k.jsonl` (100,000 samples)1 unmodified line## π Quick Start### Prerequisites- Python 3.8+- CUDA-compatible GPU (recommended)- 16GB+ RAM- 50GB+ disk space### Install dependencies```bash4 unmodified lines```bashcd dataset_builderpython extract_linux_bugfixes_parallel.pypython format_for_training.py```11 unmodified linespython 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:```cif (!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 Structure1 unmodified line```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```---4 unmodified lines* π§ **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---5 unmodified lines* 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---5 unmodified lines## π 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---2 unmodified lines* [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
1234567891011121314151617181920212223242526272829303132333435# compute_metrics.py
import json
from pathlib import Path
import sacrebleu
from rouge_score import rouge_scorer, scoring
# === Config ===
RESULTS_FILE = "./output/eval_results.json"
assert Path(RESULTS_FILE).exists(), f"File not found: {RESULTS_FILE}"
# === Load data ===
with open(RESULTS_FILE, "r", encoding="utf-8") as f:
data = json.load(f)
references = [entry["reference"] for entry in data]
predictions = [entry["prediction"] for entry in data]
# === Compute BLEU ===
bleu = sacrebleu.corpus_bleu(predictions, [references])
print("β
BLEU Score:", bleu.score)
# === Compute ROUGE ===
scorer = rouge_scorer.RougeScorer(["rouge1", "rouge2", "rougeL"], use_stemmer=True)
aggregator = scoring.BootstrapAggregator()
for pred, ref in zip(predictions, references):
scores = scorer.score(ref, pred)
aggregator.add_scores(scores)
rouge_result = aggregator.aggregate()
print("\nβ
ROUGE Scores:")
for k, v in rouge_result.items():
print(f"{k}: P={v.mid.precision:.4f}, R={v.mid.recall:.4f}, F1={v.mid.fmeasure:.4f}")
README.md+158-27
evaluate/compute_metrics.pyAdded+35
evaluate/output/eval_results.json