Skip to content

Forward mixed_precision_policy, ignored_modules and activation_checkpointing_offload from fsdp_config to the FSDP plugin - #50628

Open
amanzoni1 wants to merge 3 commits into
huggingface:mainfrom
amanzoni1:fsdp-config-plugin-options
Open

amanzoni1 wants to merge 3 commits into
huggingface:mainfrom
amanzoni1:fsdp-config-plugin-options

Conversation

@amanzoni1

@amanzoni1 amanzoni1 commented Nov 11, 2026 •

Copy link
Copy Markdown

🤗 Transformers CI

What does this PR do?

Follow-up to #42521, as suggested when it was closed.
TrainingArguments._process_fsdp_args copies a fixed set of keys from fsdp_config into the kwargs of Accelerate's FullyShardedDataParallelPlugin. Three valid plugin options are not in that set, so they are silently dropped when set through fsdp_config, while the same options work through an Accelerate config file:

  • mixed_precision_policy
  • ignored_modules
  • activation_checkpointing_offload (FSDP2, accelerate>=1.15.0)

This PR forwards them and documents them in the fsdp_config docstring. A mixed_precision_policy dict has its dtype strings converted to torch.dtype on a copy, so fsdp_config stays JSON serializable. activation_checkpointing_offload raises a clear error on Accelerate versions that don't have the option.

Repro

from transformers import TrainingArguments

args = TrainingArguments(
    output_dir="out",
    fsdp=True,
    fsdp_config={
        "mixed_precision_policy": {"param_dtype": "bf16", "reduce_dtype": "fp32", "output_dtype": "bf16"},
        "ignored_modules": "lm_head",
        "activation_checkpointing": True,
        "activation_checkpointing_offload": True,
    },
)
for key in ("mixed_precision_policy", "ignored_modules", "activation_checkpointing_offload"):
    print(key, "->", args.fsdp_plugin_args.get(key))

Before:

mixed_precision_policy -> None
ignored_modules -> None
activation_checkpointing_offload -> None

With this PR:

mixed_precision_policy -> {'param_dtype': torch.bfloat16, 'reduce_dtype': torch.float32, 'output_dtype': torch.bfloat16}
ignored_modules -> lm_head
activation_checkpointing_offload -> True

Who can review?

@SunMarc @ArthurZucker

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution 🤗!

CI Security Gate — waiting for maintainer approval

CI is approved automatically only for authors who already have a contribution merged in this repository. A maintainer will review this PR and approve CI to run on it.

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think we need the unitest here

@amanzoni1

Copy link
Copy Markdown
Author

Removed the unit tests, thanks.

This branch has not been deployed

No deployments
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