braintools.trainer.save_checkpoint

braintools.trainer.save_checkpoint#

braintools.trainer.save_checkpoint(state, filepath, overwrite=True)[source]#

Save a checkpoint to disk.

Parameters:
  • state (Dict[str, Any]) – State dictionary to save.

  • filepath (str) – Path to save the checkpoint.

  • overwrite (bool) – Whether to overwrite existing checkpoint.

Returns:

Path where the checkpoint was saved.

Return type:

str

Examples

>>> import os, shutil, tempfile
>>> import jax.numpy as jnp
>>> import braintools
>>> tmp = tempfile.mkdtemp()
>>> state = {'weights': jnp.ones((2, 3)), 'epoch': 10}
>>> path = braintools.trainer.save_checkpoint(
...     state, os.path.join(tmp, 'run', 'checkpoint.ckpt'))
>>> os.path.relpath(path, tmp)
'run/checkpoint.ckpt'
>>> os.path.exists(path)
True
>>> shutil.rmtree(tmp)