Skip to content

Conversation

@slin000111
Copy link
Collaborator

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

Write the detail information belongs to this PR.

Add example for fsdp2.

Experiment results

Paste your experiment result here(if needed).

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @slin000111, 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 introduces a comprehensive example for leveraging FSDP2 (Fully Sharded Data Parallel v2) in multi-GPU training environments. It provides a ready-to-use Accelerate configuration that enables advanced FSDP2 features such as parameter offloading and activation checkpointing, alongside a shell script to execute a LoRA fine-tuning task on a large language model. The aim is to offer a practical demonstration of efficient distributed training setups.

Highlights

  • FSDP2 Example Addition: A new example demonstrating FSDP2 (Fully Sharded Data Parallel v2) for multi-GPU training has been added to the repository.
  • FSDP2 Configuration: A new Accelerate configuration file (fsdp2_offload.json) is introduced, setting up FSDP2 with features like parameter offloading, CPU RAM efficient loading, and activation checkpointing.
  • LoRA Training Script: A train.sh script is included to launch a LoRA fine-tuning process using the specified FSDP2 configuration, targeting the Qwen/Qwen2.5-7B-Instruct model.
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 adds a new example for training with FSDP version 2, including CPU offloading. The changes are good and provide a useful example. I have a few suggestions to make the example more robust and align with best practices. Specifically, I recommend using SHARDED_STATE_DICT to prevent potential out-of-memory issues when saving large models, and I've also suggested some minor improvements to the training script for clarity and modern shell syntax.

"fsdp_cpu_ram_efficient_loading": true,
"fsdp_offload_params": true,
"fsdp_reshard_after_forward": true,
"fsdp_state_dict_type": "FULL_STATE_DICT",
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Using FULL_STATE_DICT can lead to out-of-memory errors on the main process (rank 0) when saving checkpoints for very large models, as it gathers the entire model's state dictionary on one GPU. For an FSDP example, especially one using CPU offloading to handle large models, it's safer and more scalable to use SHARDED_STATE_DICT. This will save the model state dict in a sharded fashion, with each process saving its shard, thus avoiding memory bottlenecks on rank 0.

Suggested change
"fsdp_state_dict_type": "FULL_STATE_DICT",
"fsdp_state_dict_type": "SHARDED_STATE_DICT",

--gradient_checkpointing false \
--weight_decay 0.1 \
--target_modules all-linear \
--gradient_accumulation_steps $(expr 16 / $nproc_per_node) \
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For arithmetic operations in shell scripts, it's more modern and generally recommended to use the $((...)) syntax instead of $(expr ...). It's more efficient as it's a shell builtin and has a more natural syntax.

Suggested change
--gradient_accumulation_steps $(expr 16 / $nproc_per_node) \
--gradient_accumulation_steps $((16 / nproc_per_node)) \

@slin000111 slin000111 merged commit 3766407 into modelscope:main Nov 7, 2025
1 of 2 checks passed
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