Skip to content

Conversation

@saurabh111233212
Copy link
Contributor

when the ref policy is corrupted or fails to materialize, the resuming a job crashes. This fixes that

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @saurabh111233212, 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 stability of job resumption by introducing error handling for the reference policy loading process. Previously, a corrupted or unmaterializable reference policy checkpoint would lead to a job crash. With this change, the system will now catch loading errors, log a warning, and continue execution using the base weights, ensuring more resilient operation.

Highlights

  • Robustness in Reference Policy Loading: Implemented a try-except block to gracefully handle OSError and RuntimeError during the loading of the reference policy checkpoint.
  • Job Resumption Stability: Prevents job crashes when the reference policy is corrupted or fails to materialize, allowing the system to proceed with base weights and log a warning.
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
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 try-except block to gracefully handle failures when loading the reference policy checkpoint, preventing job crashes due to corrupted or missing files. The change is correct and improves the robustness of the training resumption process. I've added one suggestion to make the exception handling even more robust and to ensure consistency with other parts of the code.

Comment on lines +779 to +792
try:
state_dict = torch.load(self.ref_policy_checkpoint_path, map_location=self.device)
if hasattr(self.ref_policy, "module"):
# If wrapped by DeepSpeed
self.ref_policy.module.load_state_dict(state_dict)
else:
self.ref_policy.load_state_dict(state_dict)
except (OSError, RuntimeError) as err:
logger.warning(
f"{self.rank=}: Failed to load reference policy from "
f"{self.ref_policy_checkpoint_path}: {err}. Proceeding with base weights."
)
else:
self.ref_policy.load_state_dict(state_dict)
logger.info(f"{self.rank=}: Loaded reference policy checkpoint from {self.ref_policy_checkpoint_path}")
logger.info(f"{self.rank=}: Loaded reference policy checkpoint from {self.ref_policy_checkpoint_path}")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The try-except block is a great addition for robustness. I have a couple of suggestions to make it even more robust:

  1. Broader Exception Handling: The current except (OSError, RuntimeError) might not catch all possible file corruption errors from torch.load, such as pickle.UnpicklingError or zipfile.BadZipFile. Since loading the reference policy is a best-effort operation, it would be safer to catch a broader Exception to prevent any loading-related crash.

  2. Consistent weights_only parameter: Earlier in this file (lines 625-636), torch.load is monkey-patched with weights_only=False to handle _pickle.UnpicklingError. For consistency and to prevent similar issues, especially as the default for weights_only may change in future PyTorch versions, it's a good practice to explicitly set weights_only=False in this torch.load call as well.

Here is a suggested change that incorporates these points.

Suggested change
try:
state_dict = torch.load(self.ref_policy_checkpoint_path, map_location=self.device)
if hasattr(self.ref_policy, "module"):
# If wrapped by DeepSpeed
self.ref_policy.module.load_state_dict(state_dict)
else:
self.ref_policy.load_state_dict(state_dict)
except (OSError, RuntimeError) as err:
logger.warning(
f"{self.rank=}: Failed to load reference policy from "
f"{self.ref_policy_checkpoint_path}: {err}. Proceeding with base weights."
)
else:
self.ref_policy.load_state_dict(state_dict)
logger.info(f"{self.rank=}: Loaded reference policy checkpoint from {self.ref_policy_checkpoint_path}")
logger.info(f"{self.rank=}: Loaded reference policy checkpoint from {self.ref_policy_checkpoint_path}")
try:
state_dict = torch.load(self.ref_policy_checkpoint_path, map_location=self.device, weights_only=False)
if hasattr(self.ref_policy, "module"):
# If wrapped by DeepSpeed
self.ref_policy.module.load_state_dict(state_dict)
else:
self.ref_policy.load_state_dict(state_dict)
except Exception as err:
logger.warning(
f"{self.rank=}: Failed to load reference policy from "
f"{self.ref_policy_checkpoint_path}: {err}. Proceeding with base weights."
)
else:
logger.info(f"{self.rank=}: Loaded reference policy checkpoint from {self.ref_policy_checkpoint_path}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants