fix(checkpointing): re-raise fatal checkpointing errors in non-elastic mode - #4927
fix(checkpointing): re-raise fatal checkpointing errors in non-elastic mode#4927RexBearIU wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies the checkpoint error handler in checkpointing.py to only raise a StopTraining exception when elastic training is enabled, and otherwise re-raise the original error. The reviewer suggests using elastic_utils.elastic_enabled(config) instead of checking config.elastic_enabled directly to ensure consistency and avoid unexpected behavior when the job is not running in an elastic environment.
| """Handles checkpointing errors, when not in an elastic context.""" | ||
| raise exceptions.StopTraining(f"Checkpointing failed. {str(err)}") from err | ||
| if config.elastic_enabled: | ||
| raise exceptions.StopTraining(f"Checkpointing failed. {str(err)}") from err | ||
| raise err |
There was a problem hiding this comment.
Using config.elastic_enabled directly can lead to unexpected behavior if the configuration flag is set to True but the job is not actually running in an elastic environment (e.g., when the Pathways backend is not used). To ensure that we only raise StopTraining when elastic training is actually active, we should use elastic_utils.elastic_enabled(config) instead. This also keeps the behavior consistent with other elastic checks in the codebase.
| """Handles checkpointing errors, when not in an elastic context.""" | |
| raise exceptions.StopTraining(f"Checkpointing failed. {str(err)}") from err | |
| if config.elastic_enabled: | |
| raise exceptions.StopTraining(f"Checkpointing failed. {str(err)}") from err | |
| raise err | |
| """Handles checkpointing errors.""" | |
| if elastic_utils.elastic_enabled(config): | |
| raise exceptions.StopTraining(f"Checkpointing failed. {str(err)}") from err | |
| raise err |
There was a problem hiding this comment.
This is a valid suggestion. Can you please do this?
There was a problem hiding this comment.
Done! Updated _checkpoint_error_handler to use elastic_utils.elastic_enabled(config) and added comprehensive unit test coverage in tests/unit/checkpointing_test.py and tests/unit/train_state_nnx_checkpoint_test.py to verify error propagation in both elastic and non-elastic modes.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
dd2ba00 to
58366ef
Compare
58366ef to
f1aab5b
Compare
Description
In standard (non-elastic) training, when checkpointing encounters an unexpected runtime or I/O failure,
_checkpoint_error_handlerpreviously converted the exception intoexceptions.StopTraining(...).In
train.py, allStopTrainingexceptions are treated as graceful completions (_job_completed_gracefully = True), which causes the Python process to exit with status code0(success). This silently masks fatal checkpointing failures from upstream orchestration tools (such as Airflow DAGs, SLURM scripts, and CI runners), causing subsequent pipeline stages (like evaluation or decode) to fail cryptically with missing checkpoint errors.Fix
_checkpoint_error_handlerinsrc/maxtext/common/checkpointing.pyto checkif elastic_utils.elastic_enabled(config):before raisingexceptions.StopTraining. This ensures thatStopTrainingis only raised when elastic training is actually active (both Pathways backend used andconfig.elastic_enabledenabled).tests/unit/checkpointing_test.pyandtests/unit/train_state_nnx_checkpoint_test.pyto verify error re-raising in non-elastic mode andStopTrainingraising in elastic mode.Tests
codespell,pylint,pyink,mdformat,yamllint,actionlint(all passed)python3 -m pytest tests/unit/checkpointing_test.py(14 tests passed)python3 -m pytest tests/unit/train_state_nnx_checkpoint_test.py(22 tests passed)python3 -m pytest tests/unit/elastic_utils_test.py(43 tests passed)Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.