Skip to main content

CTRAIN logo

CTRAIN

A training and evaluation library for certifiably robust neural networks.

MIT License · Documentation · Paper Artifacts

CTRAIN is a unified, modular, and comprehensive PyTorch framework for training certifiably robust neural networks and evaluating their robustness. It brings several leading certified training techniques behind a common wrapper interface, provides standard data loaders and model definitions, and connects training to adversarial, incomplete, and complete verification pipelines.

In addition to being a practical certified-training toolbox, CTRAIN now includes the multi-objective HPO procedure developed for the paper "Rethinking Evaluation Paradigms in IBP-based Certified Training". This procedure helps researchers tune certified training methods across the full natural-certified accuracy trade-off and compare methods by Pareto fronts instead of single hand-picked configurations.

The project is developed at the Chair for Artificial Intelligence Methodology at RWTH Aachen University.

🚀 Why CTRAIN?

Certified training research combines demanding optimization, bound computation, model design, and verification. CTRAIN packages these pieces into a reusable workflow: choose a training method, wrap a PyTorch model, train with certified objectives, and evaluate the resulting network with adversarial, incomplete, or complete verification.

The library is built for day-to-day experimentation as well as reproducible research. You can run a single certified training experiment in a few lines of code, use the same wrapper API across methods, and then scale up to multi-objective HPO when you need a principled view of the natural-certified accuracy trade-off.

✨ Highlights

  • Unified certified training wrappers for IBP-style methods built on auto_LiRPA.
  • Implementations of popular certified training methods, including IBP, CROWN-IBP, SABR, TAPS, STAPS, MTL-IBP, CC-IBP, Exp-IBP, and CC-Dist.
  • PyTorch-native model definitions, dataset loaders, and training utilities for easy integration into existing research code.
  • An experimental general output-property workflow with affine comparisons, conjunctions, disjunctions, and certified property training.
  • Adversarial evaluation with PGD, incomplete verification with IBP/CROWN variants, and complete verification through alpha-beta-CROWN.
  • Method-specific configuration spaces and a common wrapper API for training, evaluation, checkpointing, and HPO.
  • Multi-objective HPO for natural and certified accuracy using Optuna/BoTorch, as developed for our publication on Pareto-based evaluation of IBP-based certified training.
  • MIT-licensed project code.

📚 Supported Methods

Certified training:

Evaluation:

⚙️ Installation

Install the package from PyPI:

pip install CTRAIN

Some features such as complete verification with alpha-beta-CROWN require upstream packages that are not published on PyPI. Install them explicitly when you need those features:

ctrain-install-git-deps

For development from this repository:

git submodule init
git submodule update
pip install -e ".[dev]"
ctrain-install-git-deps

Tests

Run the CPU suite from the repository root after installing the development and Git dependencies:

python -m pytest -q

See tests/README.md for focused numerical checks, regression scripts, and optional CUDA and complete-verifier checks.

🧪 Quick Start

See the six runnable tutorials for training, evaluation, HPO, controller properties, ONNX/VNNLIB and MNIST arithmetic examples.

Train and evaluate a CNN7 model on CIFAR-10 with the Shi-style IBP wrapper:

from CTRAIN.model_definitions import CNN7_Shi
from CTRAIN.data_loaders import load_cifar10
from CTRAIN.model_wrappers import ShiIBPModelWrapper

train_loader, test_loader = load_cifar10(val_split=False)
input_shape = [3, 32, 32]

model = CNN7_Shi(in_shape=input_shape)
wrapped_model = ShiIBPModelWrapper(
    model=model,
    input_shape=input_shape,
    eps=2 / 255,
    num_epochs=160,
)

wrapped_model.train_model(train_loader)
std_acc, cert_acc, adv_acc = wrapped_model.evaluate(test_loader)

🎯 Pareto-based Evaluation of IBP-based Certified Training

MO-HPO Pareto-front motivation

Use the same wrapper interface for multi-objective HPO. The hpo method runs the Pareto-front optimisation procedure, stores the Optuna study and checkpoints, and returns all Pareto-optimal trial records:

from CTRAIN.model_definitions import CNN7_Shi
from CTRAIN.data_loaders import load_cifar10
from CTRAIN.model_wrappers import MTLIBPModelWrapper
import torch

train_loader, val_loader, test_loader = load_cifar10(
    batch_size=512,
    val_split=True,
)
input_shape = [3, 32, 32]

model = CNN7_Shi(in_shape=input_shape)
wrapped_model = MTLIBPModelWrapper(
    model=model,
    input_shape=input_shape,
    eps=2 / 255,
    num_epochs=160,
)

pareto_front = wrapped_model.hpo(
    train_loader=train_loader,
    val_loader=val_loader,
    budget_trials=100,
    eval_samples=10_000,
    output_dir="hpo_runs/cifar10_cnn7_mtl_ibp_2_255_seed0",
    min_cert_acc=0.40,
    min_nat_acc=0.60,
    seed=0,
    sampler="botorch",
)

chosen = max(pareto_front, key=lambda trial: trial["metrics"]["cert_acc"])
wrapped_model.load_state_dict(torch.load(chosen["checkpoint_path"]))
std_acc, cert_acc, adv_acc = wrapped_model.evaluate(test_loader)

The final, completely verified paper fronts are also available as published checkpoints. The runnable MTL-IBP example shows how to print a front from the manifest, select and download one model, and evaluate it on the CIFAR-10 test set with CTRAIN.

The paper-specific reproduction guide is in papers/rethinking_evaluation_paradigms/README.md.

🗂️ Project Structure

CTRAIN/
|-- CTRAIN/
|   |-- attacks/                 # PGD and related adversarial tools
|   |-- bound/                   # Bound computation backends
|   |-- complete_verification/   # alpha-beta-CROWN integration
|   |-- data_loaders/            # Dataset loading utilities
|   |-- eval/                    # Robustness evaluation
|   |-- model_definitions/       # CNN and ResNet architectures
|   |-- model_wrappers/          # Method-specific training wrappers and HPO
|   |-- train/                   # Certified/adversarial training internals
|   `-- util/                    # Shared utilities
|-- docs/                        # API docs and examples
`-- papers/
    `-- rethinking_evaluation_paradigms/
        |-- mo_hpo/              # Maintained paper reproduction entrypoints
        |-- submitit_experiments/ # Original SLURM/submitit experiment scripts
        |-- eval/                # Plotting, tables, and analyses
        `-- results/             # Paper result artifacts

📖 Documentation

The docs/ directory contains API documentation and examples, including certified training, model evaluation, and hyperparameter optimisation notebooks.

📝 Paper and Citation

If you use CTRAIN in your experiments, we kindly ask you to cite the following papers in which CTRAIN was developed:

Tool paper:

@inproceedings{KauHoo25,
	title        = {{CTRAIN} - A Training Library for Certifiably Robust Neural Networks},
	author       = {Kaulen, Konstantin and Hoos, Holger H},
	year         = {2025},
	booktitle    = {Proceedings of the 8th International Symposium on AI Verification (SAIV 2025)},
	pages        = {1--12}
}

For the multi-objective HPO workflow or the artifacts in papers/rethinking_evaluation_paradigms, please cite:

@inproceedings{KauEtAl26,
  title = {Rethinking Evaluation Paradigms in IBP-based Certified Training},
  author = {Kaulen, Konstantin and Shavit, Hadar and Hoos, Holger H},
  booktitle={Proceedings of the 43rd International Conference on Machine Learning (ICML 2026)},
  year="2026"
}

📄 License

This project is licensed under the MIT License.

CTRAIN incorporates alpha-beta-CROWN components and depends heavily on auto_LiRPA; those upstream components are developed by the Verified Intelligence team and are distributed under their respective licenses.

👥 Maintainers

CTRAIN was developed by Konstantin Kaulen at the Chair for Artificial Intelligence Methodology at RWTH Aachen University under the supervision of Prof. Holger H. Hoos. Konstantin Kaulen is the current core maintainer.

Contributions, issues, and pull requests are welcome.

Metadata

Release files for CTRAIN 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for CTRAIN 0.7.0
File Size Uploaded Provenance Actions
ctrain-0.7.0.tar.gz 1.0 MB With provenance Details for ctrain-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for CTRAIN 0.7.0
File Interpreter ABI Platform Actions
ctrain-0.7.0-py3-none-any.whl Python 3 none any Details for ctrain-0.7.0-py3-none-any.whl

Total release size: 2.4 MB

Release files / ctrain-0.7.0.tar.gz

Download URL ctrain-0.7.0.tar.gz
Size 1.0 MB
Tags Source
SHA-256 checksum
How to use checksums
0d31f53f7353a9d2b3b4449e9d2022f89ed4b9fe084a5fc045737c7ca07634be
BLAKE2b-256 checksum
How to use checksums
1779c3e1711f4f2bd5a5133a68ec81cb839f078eec08b9e5107e97eac558b2fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / ctrain-0.7.0-py3-none-any.whl

Download URL ctrain-0.7.0-py3-none-any.whl
Size 1.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
ed98d3af33f3d570bd8dfce129c0609e70964cb6d9f9ebcba1973f94b067fb81
BLAKE2b-256 checksum
How to use checksums
b3fef625c38d24fee704bfff79da66c0badb6cac390fd94777ab96cfcae5b1d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Security for CTRAIN 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ctrain-0.7.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page