Skip to content

Require checkpoint on Beaker restarts for DPO and GRPO training#1469

Open
finbarrtimbers wants to merge 1 commit intomainfrom
codex/add-checkpoint-check-for-run-number
Open

Require checkpoint on Beaker restarts for DPO and GRPO training#1469
finbarrtimbers wants to merge 1 commit intomainfrom
codex/add-checkpoint-check-for-run-number

Conversation

@finbarrtimbers
Copy link
Copy Markdown
Collaborator

Motivation

  • Prevent Beaker job restarts (run number > 1) from proceeding without an existing checkpoint to avoid wasted compute, accidental fresh starts, and failed/resumed training.

Description

  • Add get_beaker_run_number() and ensure_beaker_restart_has_checkpoint() helpers to open_instruct/utils.py to parse BEAKER_RUN_NUMBER and enforce checkpoint requirements for restarts.
  • Add a restart-check guard in the DPO entrypoint (open_instruct/dpo.py) that verifies args.output_dir contains a checkpoint before continuing when Beaker run number > 1.
  • Add the same guard to open_instruct/dpo_tune_cache.py right after resolving last_checkpoint_path and before resume logic runs.
  • Add a restart-check guard in the GRPO entrypoint (open_instruct/grpo_fast.py) that verifies the presence of global_0/state.pt before attempting to restore checkpoint state on Beaker restarts.
  • Add unit tests in open_instruct/test_utils.py to exercise get_beaker_run_number() and ensure_beaker_restart_has_checkpoint(), and update CHANGELOG.md with the PR link.

Testing

  • Ran make style && make quality, which completed successfully after minor auto-format fixes and static checks.
  • Ran uv run pytest -q open_instruct/test_utils.py -k BeakerRunNumber, which passed (5 passed).

Codex Task

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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

  • Beaker Restart Safety: Introduced new utility functions, get_beaker_run_number() and ensure_beaker_restart_has_checkpoint(), to manage and enforce checkpoint requirements for Beaker job restarts.
  • DPO Training Integration: Integrated the restart safety check into the DPO training entrypoint (open_instruct/dpo.py) to verify the presence of an existing checkpoint when a Beaker job restarts.
  • DPO Cache Tuning Integration: Applied the restart safety check within open_instruct/dpo_tune_cache.py to ensure a checkpoint exists after resolving the last checkpoint path during a Beaker restart.
  • GRPO Training Integration: Implemented a restart safety guard in the GRPO training entrypoint (open_instruct/grpo_fast.py) to confirm the existence of global_0/state.pt before attempting to restore checkpoint state on Beaker restarts.
  • Unit Tests: Added comprehensive unit tests in open_instruct/test_utils.py to validate the functionality of the new Beaker utility functions.

🧠 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
  • CHANGELOG.md
    • Added restart safety checks for Beaker run number > 1 to require existing checkpoints in DPO and GRPO training entrypoints.
Activity
  • The author ran make style && make quality, which completed successfully after minor auto-format fixes and static checks.
  • The author ran uv run pytest -q open_instruct/test_utils.py -k BeakerRunNumber, which passed with 5 tests.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +2119 to +2128
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)
):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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:

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines 2118 to +2121
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",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@hamishivi hamishivi closed this Apr 8, 2026
@finbarrtimbers finbarrtimbers reopened this Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants