def _sort_callbacks(trainer: Trainer):
    """Sort callback so that checkpoint saving callbacks go first.

    Args:
        trainer (Trainer): Trainer object
    """

    def _sort_key(c: Callback) -> int:
        # CheckpointSaver goes before HuggingFaceCheckpointer because the blocking time is shortest while upload is async.
        if isinstance(c, CheckpointSaver):
            return 1
        if isinstance(c, HuggingFaceCheckpointer):
            return 2
        return 0

    trainer.state.callbacks = sorted(trainer.state.callbacks, key=_sort_key)
Sort callback so that checkpoint saving callbacks go first.

    Args:
        trainer (Trainer): Trainer object
    
llmfoundry/command_utils/train.py