[Trainer] Move sort and rotate checkpoints to standalone functions (#43736)
* move the standalone functions
* update
* style
* update to logger.warning
* Apply repo consistency fixes
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>