Repository navigation
Releases
Infinite Training 2.2.0
Adds a PyTorch backend. Backward compatible: the Keras API is unchanged and no existing checkpoint needs converting.
TorchTrainer
PyTorch has no fit, so you hand over the training step and the trainer calls it once per round:
from infinite_training import TorchTrainer, Target
def step() -> dict[str, float]:
optimizer.zero_grad()
loss = loss_fn(model(x), y)
loss.backward()
optimizer.step()
return {"loss": loss.item()}
trainer = TorchTrainer(model=model, target=Target("loss", True, 1e-4), timeout=60)
trainer.train(step)
predictions, best_loss = trainer.predict_best(x)Everything around the step — the Target, the round loop, the timeout, Ctrl+C handling, checkpointing and resume — is shared with the Keras trainer. One round is one call to your step function, so you choose the granularity at which the target and timeout are checked.
There is no compile(): the shadow copy holding the best weights is built in the constructor, so inference works straight away.
Install
pip install "infinite-training[torch]"
Checkpoints are NumPy state dicts rather than torch.save archives, so a checkpoint written on a GPU resumes on a CPU with no device map, and stays readable without PyTorch installed.
Backends are now imported lazily
import infinite_training no longer imports TensorFlow, and referencing TorchTrainer never imports it either — one framework installed is enough. Asking for a trainer whose framework is missing raises an ImportError that names the extra:
TorchTrainer requires torch, which is not installed.
Install it with: pip install 'infinite-training[torch]'
TensorFlow remains a hard dependency for the whole 2.x line, so no existing pip install infinite-training breaks. It moves to the [tensorflow] extra in 3.0.0. A torch-only user can opt out today with pip install --no-deps infinite-training plus numpy torch.
Heads up if you install both frameworks
The default PyTorch wheel bundles CUDA libraries that clash with the ones TensorFlow loads, and importing both into one process can segfault the interpreter. This is not specific to this package — import tensorflow; import torch is enough to trigger it on Linux. If you need both, install the CPU build:
pip install torch --index-url https://download.pytorch.org/whl/cpu
The lazy imports mean you will not hit this while using a single backend.
Also in this release
- The loop, target and timeout bookkeeping, value history and checkpoint paths moved into an internal
_basemodule shared by both backends. No public name changed. examples/mnist_torch.py, the PyTorch counterpart of the Keras MNIST example.- 93 tests, 38 of them new, plus a CI job that installs each framework on its own and runs the suite to keep the lazy-import claim honest.
Full changelog: https://github.com/vyncint/infinite-training/blob/main/CHANGELOG.md
Infinite Training 2.1.0
Backward compatible with 2.0.0: existing code keeps working and warns where an
API has been renamed.
Fixed
Target(target_value=0)is now honoured. The default was selected with
target_value or <bound>, so a falsy0/0.0was replaced by an unreachable
bound and the session could never stop on that target.last_valueno longer raisesAttributeErrorwhen read before training, or
after an interrupt during the first round. It is derived from the persisted
value history, so it also survives a restart.Target()is no longer used as a default argument value, which meant every
trainer built without an explicit target shared one mutable instance.- Calling
train()or an inference method beforecompile()now raises a clear
RuntimeErrorinstead ofAttributeError: 'InfiniteTrainer' object has no attribute 'best_model'. - A target naming a metric that is absent from the training history now raises a
RuntimeErrorlisting the available keys, instead of a bareKeyError. When
the missing key starts withval_, the message points atvalidation_data. - Checkpoint parent directories are created automatically; previously a path
such asruns/exp1/best.npyfailed unless the directory already existed. - Restored checkpoint values are converted back to Python floats and plain
weight lists rather than being left as zero-dimensional object arrays. KeyboardInterruptis logged instead of silently swallowed.requires-pythoncorrected from>=3.9to>=3.10. TensorFlow has required
3.10 or newer since 2.16, so the old floor advertised an uninstallable
combination.
Added
InfiniteTrainer, the new name forInfinityTraining.rounds_completedproperty.save()as a public method for checkpointing on demand.Target.is_improvement(),Target.is_reached()and
Target.worst_possible_value, so the comparison rules live with the target.__version__and__all__exports.- A CI workflow running lint, tests on Python 3.10-3.12, and a packaging check
on every push and pull request. Previously tests ran only when a release was
published. - The publish workflow verifies that the release tag matches the packaged
version. CONTRIBUTING.md,CHANGELOG.md, and a rewrittenREADME.mdwith an API
reference, a resume guide and a security note.- Test suite covering targets, stop conditions, persistence and resume,
error handling, and the deprecation shims (55 tests, up from 3).
Changed
- The package is split into
target.py,trainer.pyand_storage.py. Public
imports are unchanged:from infinite_training import InfiniteTrainer, Target. - Type hints use
floatrather thannp.doublefor scalar values. - Progress and stop reasons are reported through the
loggingmodule. run.pymoved toexamples/mnist.pyand no longer ships inside the wheel.- Packaging declares its packages explicitly, so
testsis no longer picked up
by auto-discovery.
Removed
- The unused
polarsruntime dependency.
Deprecated
The following still work and will be removed in 3.0.0:
| Deprecated | Replacement |
|---|---|
InfinityTraining |
InfiniteTrainer |
optimize_weight |
best_weights |
last_weight |
last_weights |
optimize_value |
best_value |
list_value |
value_history |
optimize_model |
best_model |
predict_optimize() |
predict_best() |
optimize_weight_path= |
best_weights_path= |
last_weight_path= |
last_weights_path= |
optimize_value_path= |
best_value_path= |
list_value_path= |
value_history_path= |
Full changelog: https://github.com/vyncint/infinite-training/blob/main/CHANGELOG.md
Compare: v2.0.0...v2.1.0
Infinite Training 2.0.0
Full Changelog: v1.0.0...v2.0.0