Skip to main content

RetrainOpt

Offline planning for when to retrain a model and how much data to use, balancing training cost and predictive loss.

RetrainOpt provides exact dynamic programming and surrogate-guided approximate search over a supplied timeline. It implements the offline core of Automated Retraining for Cost-Optimal ML (Jun Yang and Michael Mathioudakis, 2026). It is an algorithm library: deployment, online drift detection and experiment orchestration are outside its scope.

Install

Python 3.10 or later. The core has no mandatory third-party runtime dependencies.

python -m pip install retrainopt

Optional integrations:

python -m pip install 'retrainopt[sklearn]'
python -m pip install 'retrainopt[torch]'
python -m pip install 'retrainopt[botorch]'

Quick start

from retrainopt import PlannerConfig, RetrainingPlanner
from retrainopt.adapters import ArrayTimelineAdapter, PrototypeModelAdapter

timeline = ArrayTimelineAdapter(
    train_blocks=[
        [((0.0,), 0), ((1.0,), 1)],
        [((0.0,), 1), ((1.0,), 0)],
    ],
    eval_blocks=[
        [((0.1,), 0), ((0.9,), 1)],
        [((0.1,), 1), ((0.9,), 0)],
    ],
)
config = PlannerConfig(
    n_choices=(1.0,),       # Full block; integer 1 would mean one sample.
    initial_loss=1.0,      # Explicit initial baseline; no bootstrap fit.
    time_cost_weight=0.0,  # Ignore wall-clock noise in this small example.
    loss_cost_weight=1.0,
)
result = RetrainingPlanner(timeline, PrototypeModelAdapter(), config).plan("exact")
print([decision.action.value for decision in result.decisions])
print(result.total_cost)
# ['retrain', 'retrain']
# 0.0

Each train block is the complete available dataset at that time; blocks are not accumulated automatically. The planner can inspect the entire timeline, including evaluation blocks. These are optimization inputs, so the selected plan's cost is not an independent future-performance estimate.

Choosing a method

Method What it does
exact Measures every configured candidate and finds the minimum-cost schedule over that finite candidate set.
bayes, lightweight backend Uses a dependency-free nearest-neighbor heuristic to select candidates.
bayes, botorch backend Uses optional Gaussian-process surrogates for acquisition-guided search.

For bayes, estimated_total_cost is the surrogate estimate, while total_cost is measured for the selected schedule. Approximate search does not guarantee the global optimum. Sequence selection can train more models than bayes_candidates_per_iteration, which is a minimum target, not a hard budget.

PlanResult.training_cost is weighted training cost, loss_cost is raw summed loss, and weighted_loss_cost is the loss contribution to total_cost. Planning's exploratory fits are not part of the selected schedule's objective.

Documentation and examples

python examples/minimal_array_timeline.py
python examples/verify_exact_against_bruteforce.py
# After installing the corresponding extra:
python examples/sklearn_timeline.py
python examples/torch_timeline.py
python examples/botorch_timeline.py

Version 0.2 corrects acquisition composition and tightens public contracts. It does not replace the paper's frozen code or the separate canonical retrainopt-paper-repro pin ecml-pkdd-2026-camera-ready-retrainopt. Use CITATION.cff to cite this software and the paper.

Apache-2.0 licensed. Source and issues: github.com/yangjun42/retrainopt.

Metadata

Release files for retrainopt 0.2.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 retrainopt 0.2.0
File Size Uploaded
retrainopt-0.2.0.tar.gz 184.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for retrainopt 0.2.0
File Interpreter ABI Platform
retrainopt-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 223.2 kB

Release files / retrainopt-0.2.0.tar.gz

Download URL retrainopt-0.2.0.tar.gz
Size 184.7 kB
Tags Source
SHA-256 checksum
How to use checksums
bf766e3cff59202e5d580a5a16dc35820b2abd222425b08533010c32ab96f978
BLAKE2b-256 checksum
How to use checksums
406eafd395f1a3870cfc2676497bde1c1929d06b6d5dfed961d8ade527fbec8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 14, 2026.

Transparency log

Release files / retrainopt-0.2.0-py3-none-any.whl

Download URL retrainopt-0.2.0-py3-none-any.whl
Size 38.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
05b0cdabd04301247579baeee17312a774c373e01047032c7b759c7adf85446c
BLAKE2b-256 checksum
How to use checksums
2eaadd9bc021934d6b6e1dc53ff3ef668893c170ec0d2b4f423aa0325b81dce2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 14, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

This release

0.2.0 This release

2 release files

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