A comprehensive framework for benchmarking Large Language Models on static code analysis and vulnerability detection tasks. This framework supports multiple LLM models, datasets, and evaluation metrics for binary and multi-class classification tasks.
git clone <your-repo-url>
cd llm4codesec-llm-benchmark
git submodule update --init --recursive
cp .default.env .env
Put your hugging face token in HF_TOKEN. You can get your token here
Your .env should looks like:
PYTHONPATH=src/
LOG_LEVEL=INFO
LOG_FORMAT='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
HF_TOKEN='hf_blabla...'
PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
Watch carefully for any warning/errors logs! You might get wrong results in case of incorrect configuration
./build_docker.sh
./run_full_benchmark.sh
./build_docker.sh
alias run_benchmark="docker-compose run --rm llm4codesec-benchmark python"
# CASTLE experiments
run_benchmark entrypoints/run_setup_castle_dataset.py
for plan in small_models_binary small_models_multiclass large_models_binary large_models_multiclass; do
run_benchmark entrypoints/run_castle_experiments.py --plan $plan
done
# CVEFixes experiments
run_benchmark entrypoints/prepare_cvefixes_datasets.py \
--database-path datasets_processed/cvefixes/CVEfixes.db \
--languages C Java Python
for plan in small_models_binary small_models_multiclass large_models_binary large_models_multiclass; do
run_benchmark entrypoints/run_cvefixes_benchmark.py --plan $plan
done
Check for actual instruction here
Use docker cuda ready VPC image. For example in selectel
./build_docker.sh
pip install poetry
poetry install
poetry env activate
python src/entrypoints/run_castle_experiments.py --plan quick_test
python src/entrypoints/run_cvefixes_benchmark.py \
--plan basic_evaluation \
--sample-limit 100 \
--output-dir results/cvefixes_test
python src/entrypoints/run_jitvul_benchmark.py \
--plan basic_evaluation \
--sample-limit 100 \
--output-dir results/jitvul_test
import json
import pandas as pd
# Load results
with open('./results/benchmark_report_20241203_143022.json', 'r') as f:
results = json.load(f)
# Print summary
print(f"Model: {results['benchmark_info']['model_name']}")
print(f"Accuracy: {results['metrics']['accuracy']:.4f}")
print(f"F1-Score: {results['metrics']['f1_score']:.4f}")
# Load predictions for detailed analysis
predictions_df = pd.read_csv('./results/predictions_20241203_143022.csv')
print(predictions_df.groupby(['true_label', 'predicted_label']).size())
Additional documentation can be found in docs/ directory
If you use this framework in your research, please cite:
@misc{llm4codesec-benchmark,
title={LLM Code Security Benchmark Framework},
author={Your Name},
year={2024},
url={https://github.com/your-repo}
}
109 commits
Jupyter Notebook
93.6%
Python
6.1%
A comprehensive framework for benchmarking Large Language Models on static code analysis and vulnerability detection tasks. This framework supports multiple LLM models, datasets, and evaluation metrics for binary and multi-class classification tasks.
git clone <your-repo-url>
cd llm4codesec-llm-benchmark
git submodule update --init --recursive
cp .default.env .env
Put your hugging face token in HF_TOKEN. You can get your token here
Your .env should looks like:
PYTHONPATH=src/
LOG_LEVEL=INFO
LOG_FORMAT='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
HF_TOKEN='hf_blabla...'
PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
Watch carefully for any warning/errors logs! You might get wrong results in case of incorrect configuration
./build_docker.sh
./run_full_benchmark.sh
./build_docker.sh
alias run_benchmark="docker-compose run --rm llm4codesec-benchmark python"
# CASTLE experiments
run_benchmark entrypoints/run_setup_castle_dataset.py
for plan in small_models_binary small_models_multiclass large_models_binary large_models_multiclass; do
run_benchmark entrypoints/run_castle_experiments.py --plan $plan
done
# CVEFixes experiments
run_benchmark entrypoints/prepare_cvefixes_datasets.py \
--database-path datasets_processed/cvefixes/CVEfixes.db \
--languages C Java Python
for plan in small_models_binary small_models_multiclass large_models_binary large_models_multiclass; do
run_benchmark entrypoints/run_cvefixes_benchmark.py --plan $plan
done
Check for actual instruction here
Use docker cuda ready VPC image. For example in selectel
./build_docker.sh
pip install poetry
poetry install
poetry env activate
python src/entrypoints/run_castle_experiments.py --plan quick_test
python src/entrypoints/run_cvefixes_benchmark.py \
--plan basic_evaluation \
--sample-limit 100 \
--output-dir results/cvefixes_test
python src/entrypoints/run_jitvul_benchmark.py \
--plan basic_evaluation \
--sample-limit 100 \
--output-dir results/jitvul_test
import json
import pandas as pd
# Load results
with open('./results/benchmark_report_20241203_143022.json', 'r') as f:
results = json.load(f)
# Print summary
print(f"Model: {results['benchmark_info']['model_name']}")
print(f"Accuracy: {results['metrics']['accuracy']:.4f}")
print(f"F1-Score: {results['metrics']['f1_score']:.4f}")
# Load predictions for detailed analysis
predictions_df = pd.read_csv('./results/predictions_20241203_143022.csv')
print(predictions_df.groupby(['true_label', 'predicted_label']).size())
Additional documentation can be found in docs/ directory
If you use this framework in your research, please cite:
@misc{llm4codesec-benchmark,
title={LLM Code Security Benchmark Framework},
author={Your Name},
year={2024},
url={https://github.com/your-repo}
}
109 commits
Jupyter Notebook
93.6%
Python
6.1%