Require checkpoint on Beaker restarts for DPO and GRPO training#1469
Require checkpoint on Beaker restarts for DPO and GRPO training#1469finbarrtimbers wants to merge 1 commit intomainfrom
Conversation
Summary of ChangesHello @finbarrtimbers, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the robustness of DPO and GRPO training workflows on Beaker by preventing job restarts from initiating without a valid checkpoint. This change is crucial for avoiding wasted computational resources, accidental fresh starts, and ensuring proper resumption of interrupted training processes, thereby improving the reliability and efficiency of large-scale model training. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable safety measure by ensuring that Beaker job restarts for DPO and GRPO training can only proceed if a checkpoint exists. This prevents wasted compute and accidental fresh starts. The implementation is solid, with new utility functions in utils.py and their integration into the respective training scripts. The addition of unit tests for these new utilities is also a great practice. I've identified a minor opportunity for refactoring in open_instruct/grpo_fast.py to simplify the checkpoint existence check, which will improve code clarity and efficiency.
| utils.ensure_beaker_restart_has_checkpoint( | ||
| checkpoint_path if checkpoint_path and os.path.exists(checkpoint_path) else None, | ||
| checkpoint_name="GRPO checkpoint state", | ||
| ) | ||
| if ( | ||
| args.checkpoint_state_dir | ||
| and os.path.exists(args.checkpoint_state_dir) | ||
| and checkpoint_path | ||
| and os.path.exists(checkpoint_path) | ||
| ): |
There was a problem hiding this comment.
The logic to check for the checkpoint's existence is a bit complex and performs a redundant os.path.exists() check. You can simplify this by checking for existence once, storing the result in a variable, and reusing it. This will make the code more readable and slightly more efficient by avoiding a repeated filesystem access.
checkpoint_exists = checkpoint_path and os.path.exists(checkpoint_path)
utils.ensure_beaker_restart_has_checkpoint(
checkpoint_path if checkpoint_exists else None,
checkpoint_name="GRPO checkpoint state",
)
if checkpoint_exists:There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c57b94c74f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| checkpoint_path = os.path.join(args.checkpoint_state_dir, "global_0", "state.pt") | ||
| if os.path.exists(checkpoint_path): | ||
| checkpoint_state = torch.load(checkpoint_path, map_location="cpu", weights_only=False) | ||
| logger.info(f"Loaded checkpoint state from {checkpoint_path}") | ||
| data_prep_actor_state = checkpoint_state.get("data_prep_actor_state") | ||
| if data_prep_actor_state: | ||
| # Use trainer's authoritative training_step for DataPreparationActor. | ||
| # iter_dataloader state may be ahead but that's ok (prompts are shuffled, training is stochastic) | ||
| data_prep_actor_state["training_step"] = checkpoint_state.get("training_step", 0) | ||
| utils.ensure_beaker_restart_has_checkpoint( | ||
| checkpoint_path if checkpoint_path and os.path.exists(checkpoint_path) else None, | ||
| checkpoint_name="GRPO checkpoint state", |
There was a problem hiding this comment.
Validate GRPO restarts using the checkpoint format we load
This restart guard is keyed to global_0/state.pt, but GRPO resume logic actually restores through self.model.load_checkpoint(args.checkpoint_state_dir, ...) in PolicyTrainerRayProcess.from_pretrained, which uses the checkpoint tag structure under checkpoint_state_dir (and utils.calibrate_checkpoint_state_dir also manages global_step* tags). On Beaker run number > 1, jobs with a valid DeepSpeed checkpoint directory but no global_0/state.pt will now raise here and abort instead of resuming, so this can block legitimate restarts.
Useful? React with 👍 / 👎.
Motivation
Description
get_beaker_run_number()andensure_beaker_restart_has_checkpoint()helpers toopen_instruct/utils.pyto parseBEAKER_RUN_NUMBERand enforce checkpoint requirements for restarts.open_instruct/dpo.py) that verifiesargs.output_dircontains a checkpoint before continuing when Beaker run number > 1.open_instruct/dpo_tune_cache.pyright after resolvinglast_checkpoint_pathand before resume logic runs.open_instruct/grpo_fast.py) that verifies the presence ofglobal_0/state.ptbefore attempting to restore checkpoint state on Beaker restarts.open_instruct/test_utils.pyto exerciseget_beaker_run_number()andensure_beaker_restart_has_checkpoint(), and updateCHANGELOG.mdwith the PR link.Testing
make style && make quality, which completed successfully after minor auto-format fixes and static checks.uv run pytest -q open_instruct/test_utils.py -k BeakerRunNumber, which passed (5 passed).Codex Task