[fix] Pass all fsdp_config values to accelerate via environment variables…#7962
[fix] Pass all fsdp_config values to accelerate via environment variables…#7962tzteyang wants to merge 1 commit intomodelscope:mainfrom
Conversation
…bles Previously only FSDP_VERSION was set from fsdp_config, causing other settings like state_dict_type to be ignored. This fix maps all relevant fsdp_config keys to their corresponding environment variables that accelerate reads. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary of ChangesHello @tzteyang, 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 addresses a crucial bug in the system's FSDP configuration management. It rectifies an oversight where only the FSDP version was being propagated to the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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.
Code Review
This pull request fixes an issue where FSDP configurations other than fsdp_version were not being passed to accelerate. The change correctly iterates through a mapping of configuration keys to environment variables, ensuring all relevant settings are applied. This is a solid fix that improves the FSDP integration.
I've added one suggestion to make the implementation slightly more robust by using dict.get() and checking for None values.
As a minor style point, you could also consider defining fsdp_env_mapping as a module-level constant since it's static and doesn't need to be recreated on each call to _init_fsdp.
Previously only FSDP_VERSION was set from fsdp_config, causing other settings like state_dict_type to be ignored. This fix maps all relevant fsdp_config keys to their corresponding environment variables that accelerate reads.
PR type
PR information
Problem
When using FSDP2 training with the following key arguments:
swift sft \ --fsdp fsdp2 \ --save_only_model true \ ...Attempted to fix this by setting
state_dict_type: FULL_STATE_DICTinswift/config/fsdp2.json, but the error persisted.After investigation, found that while swift correctly parses the
fsdp_configfrom JSON config files, onlyfsdp_versionwas being passed to accelerate (v1.12.0) via environment variable. Other config values likestate_dict_type,reshard_after_forward, etc. were ignored.Accelerate reads these settings from environment variables (see
accelerate/utils/launch.py:309-328), not from the config dict directly.Solution
Following the same pattern used for
fsdp_version, map all relevantfsdp_configkeys to their corresponding environment variables:fsdp_versionFSDP_VERSIONstate_dict_typeFSDP_STATE_DICT_TYPEreshard_after_forwardFSDP_RESHARD_AFTER_FORWARDauto_wrap_policyFSDP_AUTO_WRAP_POLICYcpu_ram_efficient_loadingFSDP_CPU_RAM_EFFICIENT_LOADINGExperiment results
Tested FSDP2 training with
state_dict_type: FULL_STATE_DICTandsave_only_model: trueon Qwen3-4B - training completed successfully without the previous incompatibility error.