Skip to content

Conversation

@xvxuopop
Copy link
Contributor

What does this PR do?

When using fsdp2 and specifying disable_grandient_checkpointing as False, memory usage is abnormally high. This is modified to force disable_grandient_checkpointing to True when fsdp2 is detected, and to notify the user to set fsdp activation checkpointing in the fsdp config.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @xvxuopop, 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 resolves a critical memory consumption problem encountered when utilizing FSDP2 in conjunction with gradient checkpointing. It introduces a protective measure that automatically disables a specific gradient checkpointing setting when FSDP2 is active, thereby preventing excessive memory usage. Furthermore, it enhances user experience by providing clear guidance on how to correctly enable gradient checkpointing through FSDP's native configuration.

Highlights

  • FSDP2 Memory Fix: Addresses an issue where using FSDP2 with disable_gradient_checkpointing set to False led to abnormally high memory usage.
  • Automatic Gradient Checkpointing Disablement: When FSDP2 is detected, disable_gradient_checkpointing is now automatically forced to True to mitigate the memory issue.
  • User Guidance: A warning message is added to inform users about the automatic change and advise them to configure activation_gradient_checkpointing in the FSDP config if they intend to use gradient checkpointing.
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 addresses an issue of abnormally high memory usage when using FSDP v2 with gradient checkpointing. The proposed solution is to automatically disable gradient checkpointing when FSDP v2 is detected and inform the user. The implementation is straightforward, but I've identified a potential runtime error in how an environment variable is parsed. My review includes a suggestion to make the code more robust against invalid inputs.


if (
os.environ.get("ACCELERATE_USE_FSDP", "false").lower() == "true"
and int(os.environ.get("FSDP_VERSION", "1")) == 2
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The direct conversion of the FSDP_VERSION environment variable to an integer using int() can lead to a ValueError if the variable is set to a non-integer string (e.g., "2.0" or an empty string). This would cause the program to crash. It's safer to perform a direct string comparison to avoid this potential runtime error.

Suggested change
and int(os.environ.get("FSDP_VERSION", "1")) == 2
and os.environ.get("FSDP_VERSION", "1") == "2"

Copy link
Owner

@hiyouga hiyouga left a comment

Choose a reason for hiding this comment

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

Please add an example yaml file

@hiyouga hiyouga added the pending This problem is yet to be addressed label Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending This problem is yet to be addressed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants