braintools.trainer.load_checkpoint

braintools.trainer.load_checkpoint#

braintools.trainer.load_checkpoint(filepath, map_location=None)[source]#

Load a checkpoint from disk.

Parameters:
  • filepath (str) – Path to the checkpoint file.

  • map_location (str | None) – Device to map tensors to (not used in JAX, included for API compatibility).

Returns:

Loaded state dictionary.

Return type:

Dict[str, Any]

Examples

>>> import os, shutil, tempfile
>>> import jax.numpy as jnp
>>> import braintools
>>> tmp = tempfile.mkdtemp()
>>> path = os.path.join(tmp, 'checkpoint.ckpt')
>>> _ = braintools.trainer.save_checkpoint(
...     {'weights': jnp.arange(3.0), 'epoch': 10}, path)
>>> state = braintools.trainer.load_checkpoint(path)
>>> state['epoch']
10
>>> state['weights']
Array([0., 1., 2.], dtype=float32)
>>> shutil.rmtree(tmp)