The plumbing to ship it: persist, export, serve, log, reproduce.
Persistence
Save and load the model with its scalers and conformal calibration intact.
save() / load() round-trip the weights, the fitted scalers, and the conformal calibration together, so a reloaded model forecasts and calibrates exactly as before. Weights are stored on CPU, so a model trained on a GPU loads on any machine. Checkpoints record the library version and refuse incompatible ones.
model.save('m.pt'); APDTFlowForecaster.load('m.pt', device='auto') TorchScript export
Export grid-forecast inference to TorchScript.
Trace the grid-forecast path into a TorchScript module for lean, Python-optional serving. (predict_at and predict_when stay in the Python API.)
model.export_torchscript('model.pt') FastAPI serving
Serve forecasts over HTTP with a small FastAPI app.
A small, ready-to-adapt FastAPI app that exposes forecast endpoints over HTTP — a starting point for your own service.
uvicorn serve_api:app
see example: serve_api.py →
GPU & device selection
device='auto' picks CUDA, then Apple MPS, then CPU; move a fitted model with .to().
Training, conformal calibration, predict, predict_at, predict_when and fleet scoring all run on the selected device, and checkpoints are stored on CPU so a GPU-trained model loads anywhere. On NVIDIA GPUs each training step is replayed as a CUDA graph; measured on a laptop, the GPU trains 4 to 7 times faster than the CPU, while single-window calls stay faster on the CPU.
APDTFlowForecaster(device='auto'); model.to('cpu') ℹ Benchmark table, hardware and when a GPU helps: docs/gpu_and_performance.md.
Reproducible runs
One call for deterministic seeding across NumPy and PyTorch.
set_seed() seeds Python, NumPy and PyTorch and turns on deterministic mode, so the same inputs give the same model.
from apdtflow import set_seed; set_seed(0) Experiment logging
Stream epoch metrics to MLflow or Weights & Biases.
fit() accepts a log_callback(epoch, metrics) hook that drops straight into MLflow or Weights & Biases for live training curves.
model.fit(df, log_callback=lambda e, m: mlflow.log_metrics(m, step=e)) sklearn-compatible
get_params / set_params for pipelines and hyperparameter search.
get_params / set_params follow the scikit-learn estimator contract, so APDTFlow slots into Pipelines and hyperparameter search.
model.get_params(); model.set_params(num_epochs=30) Typed
Ships a py.typed marker for full static type checking.
A py.typed marker ships inline type information for editors and type checkers.
import apdtflow # PEP 561 typed Command line
Train and forecast straight from the terminal.
apdtflow train and apdtflow infer cover CSV-in / forecast-out workflows without writing any Python.
apdtflow train --csv_file data.csv --value_col y --device auto