-
Notifications
You must be signed in to change notification settings - Fork 976
Add FSDP2 example #6411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FSDP2 example #6411
Conversation
update faq.
Fixed the inconsistencies between the Chinese and English documentation.
Update link to sequence parallel example
add fsdp2 example
Summary of ChangesHello @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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| "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) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \ | |
| --gradient_accumulation_steps $((16 / nproc_per_node)) \ |
modify fsdp2 config
PR type
PR information
Write the detail information belongs to this PR.
Add example for fsdp2.
Experiment results
Paste your experiment result here(if needed).