MCPcopy Create free account
hub / github.com/apple/axlearn / save

Method save

axlearn/common/checkpointer_orbax.py:494–529  ·  view source on GitHub ↗

See `BaseCheckpointer.save` for details. Checkpoint saving is handled by `orbax` checkpoint manager.

(
        self,
        *,
        step: int,
        state: Nested[Tensor],
        evaler_summaries: Optional[Dict[str, Any]] = None,
    )

Source from the content-addressed store, hash-verified

492 # pylint: disable-next=redefined-builtin
493 def ckpt_dir(self, step: int, dir: Optional[str] = None) -> str:
494 """Obtains the checkpoint dir for the given step."""
495 if dir is None:
496 dir = self._manager.directory
497 return str(ocp.step.build_step_path(dir, self._name_format, step))
498
499 def save(
500 self,
501 *,
502 step: int,
503 state: Nested[Tensor],
504 evaler_summaries: Optional[Dict[str, Any]] = None,
505 ):
506 """See `BaseCheckpointer.save` for details.
507
508 Checkpoint saving is handled by `orbax` checkpoint manager.
509 """
510 spec = self._get_spec(step=step, state=state)
511 assert self._eval_summaries is None, self._eval_summaries
512 self._eval_summaries = copy.deepcopy(evaler_summaries or {})
513
514 try:
515 # Note that save() waits for prior serialization to finish.
516 self._manager.save(
517 step=step,
518 # The input iterator is saved as part of `save_tf_savables`.
519 args=ocp.args.Composite(
520 index=ocp.args.JsonSave(spec["index"]),
521 # TODO(markblee): Investigate save_args for chunk_byte_size and
522 # ocdbt_target_data_file_size:
523 # https://orbax.readthedocs.io/en/latest/optimized_checkpointing.html#custom-chunk-sizes
524 # https://orbax.readthedocs.io/en/latest/optimized_checkpointing.html#customizing-data-file-size
525 state=ocp.args.PyTreeSave(item=state),
526 ),
527 )
528 # Exit early after pre-emption, equivalent to sys.exit():
529 # https://orbax.readthedocs.io/en/latest/preemption_checkpointing.html
530 if self._manager.reached_preemption(step):
531 self._manager.wait_until_finished()
532 raise SystemExit(f"Exiting after saving checkpoint at {step=} due to pre-emption.")

Callers

nothing calls this directly

Calls 2

_get_specMethod · 0.95
wait_until_finishedMethod · 0.45

Tested by

no test coverage detected