๐Ÿ”ง Co-PatcheR: Collaborative Software Patching with Component(s)-specific Small Reasoning Models

May 28, 2025 ยท View on GitHub

๐Ÿ”ย Overview | ๐Ÿค–ย Models | ๐Ÿ› ๏ธย Installation | ๐Ÿš€ย Quick Start | ๐Ÿ“ย Citation

News

  • ๐Ÿš€ [May 2025] Co-PatcheR models and code are now available on Hugging Face!
  • ๐Ÿ“„ [May 2025] Co-PatcheR paper is available on arXiv!

Overview

๐Ÿ”ง Co-PatcheR: A Collaborative Software Patching System

Co-PatcheR introduces an approach to automated software patching through collaborative small reasoning models. Instead of using one large model for all tasks, we employ specialized 14B models for different components of the patching pipeline.

Key Innovations:

  • ๐ŸŽฏ Component-Specific Models: Dedicated models for localization, generation, and validation
  • ๐Ÿ“Š SOTA Performance: 46% resolved rate on SWE-bench-Verified

๐Ÿ—๏ธ Architecture Overview

Co-PatcheR usage consists of three specialized components:

  1. ๐Ÿ” Fault Localization: Identifies problematic code locations
  2. โšก Patch Generation: Generates multiple patch candidates
  3. ๐Ÿ›ก๏ธ Patch Validation: Validation through test case generation and execution

Models

ComponentModelHF CheckpointSize
Localization & GenerationCo-PatcheR-Loc-Gen๐Ÿค— UCSB-SURFI/Co-PatcheR-Loc-Gen-14B14B
Validation (w/ assertions)Co-PatcheR-Val-Assert๐Ÿค— UCSB-SURFI/Co-PatcheR-Val-assert-14B14B
Validation (w/o assertions)Co-PatcheR-Val-NoAssert๐Ÿค— UCSB-SURFI/Co-PatcheR-Val-no-assert-14B14B

Note: Both validation models (Co-PatcheR-Val-assert-14B and Co-PatcheR-Val-no-assert-14B) enhance the validation step, but for a simplified setup you can use just Co-PatcheR-Val-no-assert-14B with still good performance.

Performance on SWE-bench-Verified:

  • 46% resolved rate with 3ร—14B models
  • Least training resources among specialized patching models
  • Smallest model ensemble achieving SOTA performance

Installation

  1. Pull the Docker image:
docker pull 3rdn4/patchpilot_verified:v1
  1. Run the container:
docker run -it 3rdn4/patchpilot_verified:v1

๐Ÿ“ฆ From Source

  1. Clone the repository:
git clone git@github.com:ucsb-mlsec/Co-PatcheR.git
cd Co-PatcheR
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up environment:
export PYTHONPATH=$PYTHONPATH:$(pwd)

Quick Start

For SWE-Bench Verified, we need to checkout repositories and process files. To save time, you can download the preprocessed data:

# Download preprocessed repository structure
wget https://github.com/ucsb-mlsec/Co-PatcheR/releases/download/v1.0.0/verified_repo_structure.txt

# Export the location 
export PROJECT_STRUCTURE={path_to_downloaded_file}

We recommend deploying the Co-PatcheR models locally using vLLM:

export CUDA_VISIBLE_DEVICES=0,1
vllm serve UCSB-SURFI/Co-PatcheR-Loc-Gen-14B --tensor-parallel-size 2 --port 2952

๐ŸŽฏ 1. Fault Localization

Step 1: Initial Localization

python patchpilot/fl/localize.py \
    --file_level \
    --related_level \
    --fine_grain_line_level \
    --output_folder results/localization \
    --backend opensource \
    --model UCSB-SURFI/Co-PatcheR-Loc-Gen-14B \
    --top_n 5 \
    --compress \
    --context_window=20 \
    --temperature 0.7 \
    --match_partial_paths \
    --num_samples 4 \
    --num_threads 32 \
    --task_list_file swe_verify_tasks.txt \
    --benchmark verified \
    --port 2952

Step 2: Merge Localization Results

python patchpilot/fl/localize.py \
    --merge \
    --output_folder results/localization/merged \
    --start_file results/localization/loc_outputs.jsonl \
    --num_samples 4

โšก 2. Patch Generation

Generate patches based on merged localization results:

python patchpilot/repair/repair.py \
    --loc_file results/localization/merged/loc_all_merged_outputs.jsonl \
    --output_folder results/repair \
    --benchmark verified \
    --max_samples 20 \
    --batch_size 1 \
    --num_threads 32 \
    --backend opensource \
    --model UCSB-SURFI/Co-PatcheR-Loc-Gen-14B \
    --task_list_file swe_verify_tasks.txt \
    --port 2952

๐Ÿ›ก๏ธ 3. Patch Validation

Step 1: Generate Proof-of-Concepts (POCs)

python patchpilot/reproduce/reproduce.py \
    --reproduce_folder results/reproduce \
    --num_threads 24 \
    --task_list_file swe_verify_tasks.txt \
    --setup_map setup_result/verified_setup_map.json \
    --tasks_map setup_result/verified_tasks_map.json \
    --model UCSB-SURFI/Co-PatcheR-Val-no-assert-14B \
    --backend opensource \
    --benchmark verified \
    --num_samples 5 \
    --port 2952

Step 2: Verify POCs

python patchpilot/reproduce/verify.py \
    --verify_folder results/validation \
    --reproduce_folder results/reproduce \
    --patch_folder results/repair \
    --num_threads 32 \
    --task_list_file swe_verify_tasks.txt \
    --setup_map setup_result/verified_setup_map.json \
    --tasks_map setup_result/verified_tasks_map.json \
    --backend opensource \
    --model UCSB-SURFI/Co-PatcheR-Val-no-assert-14B \
    --port 2952

๐Ÿ”„ 4. Rerank Patches

Final step to rerank patches based on validation results:

python patchpilot/repair/rerank.py \
    --loc_file results/localization/merged/loc_all_merged_outputs.jsonl \
    --output_folder results/repair \
    --benchmark verified \
    --verify_folder results/verify \
    --setup_map setup_result/full_setup_map.json \
    --tasks_map setup_result/full_tasks_map.json \
    --num_threads 32 \
    --task_list_file swe_verify_tasks.txt \
    --sample_mod

๐Ÿ“‹ Complete Pipeline Summary

The complete Co-PatcheR pipeline follows this order:

  1. Localization โ†’ Issue localization
  2. Generation โ†’ Generate patch candidates
  3. Validation โ†’ Generate POCs + dynamic validation
  4. Rerank โ†’ Final ranking of patches

๐Ÿ“ Citation

If you find Co-PatcheR useful in your research, please cite our paper:

@article{tang2025copatcher,
  title={Co-PatcheR: Collaborative Software Patching with Component(s)-specific Small Reasoning Models},
  author={Tang, Yuheng and Li, Hongwei and Zhu, Kaijie and Yang, Michael and Ding, Yangruibo and Guo, Wenbo},
  journal={arXiv preprint arXiv:2505.18955},
  year={2025}
}

Made with โค๏ธ by the UCSB-SURFI Team