Skip to content

[feat] Add DeepSpeed ZeRO-3 LoRA checkpoint save support#10124

Open
kimberlykang wants to merge 1 commit intohiyouga:mainfrom
kimberlykang:feat/deepspeed-zero3-lora-save
Open

[feat] Add DeepSpeed ZeRO-3 LoRA checkpoint save support#10124
kimberlykang wants to merge 1 commit intohiyouga:mainfrom
kimberlykang:feat/deepspeed-zero3-lora-save

Conversation

@kimberlykang
Copy link

@kimberlykang kimberlykang commented Jan 22, 2026

  • Override save_model() for PEFT adapter with ZeRO-3 compatibility
  • Use direct all_gather on ds_tensor to avoid GatheredParameters INFLIGHT issues
  • Add _save_checkpoint() to measure checkpoint saving time
  • Handle both DeepSpeed and non-DeepSpeed PEFT saves

What does this PR do?

Fixes # (issue)

Before submitting

- Override save_model() for PEFT adapter with ZeRO-3 compatibility
- Use direct all_gather on ds_tensor to avoid GatheredParameters INFLIGHT issues
- Add _save_checkpoint() to measure checkpoint saving time
- Handle both DeepSpeed and non-DeepSpeed PEFT saves
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kimberlykang, 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 significantly enhances the model saving capabilities within the training framework, specifically targeting LoRA adapters used with DeepSpeed ZeRO-3. It introduces a robust mechanism to correctly gather and save partitioned LoRA parameters, bypassing previous compatibility issues. Additionally, it improves observability by measuring and logging the time taken for checkpoint saves, ensuring a more efficient and reliable training workflow for large language models.

Highlights

  • DeepSpeed ZeRO-3 LoRA Checkpoint Saving: Implemented a custom save_model method to correctly save LoRA adapters when using DeepSpeed ZeRO-3, addressing compatibility issues with partitioned parameters.
  • Direct all_gather for ZeRO-3: Resolved GatheredParameters INFLIGHT issues by directly using torch.distributed.all_gather on ds_tensor to reconstruct partitioned LoRA parameters across ranks.
  • Checkpoint Saving Time Measurement: Overrode the _save_checkpoint method to include logging of the duration taken for each checkpoint saving operation, providing performance insights.
  • Unified PEFT Save Handling: The save_model override now gracefully handles saving for both DeepSpeed-enabled and non-DeepSpeed PEFT models, as well as falling back to default behavior for non-PEFT models.
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 support for saving LoRA checkpoints with DeepSpeed ZeRO-3, which is a great addition. The implementation correctly gathers partitioned parameters before saving. It also adds a useful feature to time and log the duration of checkpoint saving.

My review includes two main points:

  1. A high-severity issue regarding device placement during parameter gathering, which could impact performance.
  2. A medium-severity suggestion to refactor the model saving logic to reduce code duplication and improve maintainability.

Overall, the changes are valuable and address an important compatibility issue. Addressing the feedback will make the implementation more robust and maintainable.

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.

1 participant