Production checkpoint management for Kaggle and ephemeral training environments
Project description
kaggle-ckpt
Production checkpoint management for Kaggle and other ephemeral training environments.
Kaggle notebooks wipe /kaggle/temp between sessions and cap /kaggle/working at
roughly 20 GB. kaggle-ckpt handles the lifecycle for you: fast atomic saves during
training, configurable retention so you don't blow the disk quota, and a single call
at the end to promote your best model (plus metrics, logs, and config) into persistent
storage.
Features
- Automatic
/kaggle/temp(fast, ephemeral) →/kaggle/working(persistent) promotion - Atomic saves via PID-scoped temp files, so a crash mid-write never corrupts a checkpoint
- Configurable retention: keep the best, the last, and/or the last N periodic checkpoints
- Exponential Moving Average (EMA) of model weights, with serialization built in
- Robust state-dict loading that auto-handles
DataParallel'smodule.prefix - Kaggle / Colab / local environment auto-detection with local fallback paths
- Framework-agnostic: works with raw PyTorch, Lightning, Hugging Face, etc.
Install
pip install kaggle-ckpt
Quickstart
from kaggle_ckpt import CheckpointManager, CheckpointConfig
cfg = CheckpointConfig("my_experiment", monitor="val_macro_f1", mode="max")
ckpt = CheckpointManager(cfg)
for epoch in range(1, num_epochs + 1):
train_metrics = train_one_epoch(...)
val_metrics = validate(...)
state = {
"epoch": epoch,
"model": model.state_dict(),
"optimizer": optimizer.state_dict(),
}
ckpt.save_epoch(epoch, state, metrics=val_metrics)
# At the end of training, promote everything to /kaggle/working
ckpt.copy_final_artifacts(
metrics=test_metrics,
train_log=ckpt.metrics.get_history(),
class_names=class_names,
config_dict=config,
)
Loading a checkpoint later
from kaggle_ckpt import CheckpointManager, CheckpointConfig
ckpt = CheckpointManager(CheckpointConfig("my_experiment"))
checkpoint = ckpt.load_best()
ckpt.load_model_weights(model, checkpoint=checkpoint, use_ema=True)
EMA
from kaggle_ckpt import EMA
ema = EMA(model, decay=0.9998)
for step in training_loop:
optimizer.step()
ema.update()
ema.apply_shadow()
validate(model)
ema.restore()
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kaggle_ckpt-0.1.0.tar.gz.
File metadata
- Download URL: kaggle_ckpt-0.1.0.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bedf43d3d6091848967f41f059381c2e1438f496cbdea03328a48c3b287c11d
|
|
| MD5 |
115afe0f84d85b63608095ae9d5332c1
|
|
| BLAKE2b-256 |
8075520c1f48d7d28a7e85ea37ecc514aacbf08193f7db7f423c7c3b5751611f
|
File details
Details for the file kaggle_ckpt-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kaggle_ckpt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7805b8d50d475e4b9efad84c8a9fdbd997f6dbf9f9e279643111e3c298e55a8a
|
|
| MD5 |
b9432ee94bd77def10d6429fb0cb5d7e
|
|
| BLAKE2b-256 |
a47a1adf3e2e3b8b6a32fb6bf41a0ffe268376178cfe2a39c0b79991c41c151b
|