Skip to content

[fix] Pass all fsdp_config values to accelerate via environment variables…#7962

Open
tzteyang wants to merge 1 commit intomodelscope:mainfrom
tzteyang:fix/fsdp-config-env-vars
Open

[fix] Pass all fsdp_config values to accelerate via environment variables…#7962
tzteyang wants to merge 1 commit intomodelscope:mainfrom
tzteyang:fix/fsdp-config-env-vars

Conversation

@tzteyang
Copy link

@tzteyang tzteyang commented Feb 2, 2026

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

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

PR information

Problem

When using FSDP2 training with the following key arguments:

swift sft \
    --fsdp fsdp2 \
    --save_only_model true \
    ...
image

Attempted to fix this by setting state_dict_type: FULL_STATE_DICT in swift/config/fsdp2.json, but the error persisted.

After investigation, found that while swift correctly parses the fsdp_config from JSON config files, only fsdp_version was being passed to accelerate (v1.12.0) via environment variable. Other config values like state_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 relevant fsdp_config keys to their corresponding environment variables:

Config Key Environment Variable
fsdp_version FSDP_VERSION
state_dict_type FSDP_STATE_DICT_TYPE
reshard_after_forward FSDP_RESHARD_AFTER_FORWARD
auto_wrap_policy FSDP_AUTO_WRAP_POLICY
cpu_ram_efficient_loading FSDP_CPU_RAM_EFFICIENT_LOADING

Experiment results

Tested FSDP2 training with state_dict_type: FULL_STATE_DICT and save_only_model: true on Qwen3-4B - training completed successfully without the previous incompatibility error.

…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>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 accelerate library, causing other essential FSDP settings to be disregarded. By extending the mechanism to pass all relevant FSDP configuration keys as environment variables, the PR ensures that accelerate correctly interprets and applies the intended distributed training parameters, thereby resolving issues encountered during FSDP2 training with specific configurations.

Highlights

  • FSDP Configuration Propagation: The pull request enhances the handling of FSDP (Fully Sharded Data Parallel) configurations by ensuring that all relevant settings from fsdp_config are correctly passed to the accelerate library via environment variables. Previously, only FSDP_VERSION was being set, leading to other FSDP parameters being ignored.
  • Bug Fix for FSDP2 Training: This change resolves a critical bug where FSDP2 training with specific configurations, such as state_dict_type: FULL_STATE_DICT and save_only_model: true, would fail due to accelerate not receiving all necessary FSDP settings. The fix ensures proper communication of these settings, allowing successful training.

🧠 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 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 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.

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