Skip to content

feat(fsdp): expose fsdp's min_num_params for SIZE_BASED_WRAP in config .yml#3710

Open
thad0ctor wants to merge 3 commits into
axolotl-ai-cloud:mainfrom
thad0ctor:fix/fsdp2-size-based-wrap
Open

feat(fsdp): expose fsdp's min_num_params for SIZE_BASED_WRAP in config .yml#3710
thad0ctor wants to merge 3 commits into
axolotl-ai-cloud:mainfrom
thad0ctor:fix/fsdp2-size-based-wrap

Conversation

@thad0ctor

@thad0ctor thad0ctor commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Description

The SIZE_BASED_WRAP auto-wrap policy is selectable via fsdp_config.auto_wrap_policy, but there was no way to set its parameter threshold from the config, it was only configurable through env variable. This adds a min_num_params field toFSDPConfig and wires it through to the FSDP_MIN_NUM_PARAMS env var for Accelerate.

Motivation and Context

FSDP only honors a size threshold when FSDP_MIN_NUM_PARAMS is set (> 0); otherwise it reads the default of 0 and set_auto_wrap_policy() silently drops the policy to None unless manually setting ENV variables.

Axolotl'ssetup_fsdp_envs() exported every other FSDP knob but never this one, so selecting auto_wrap_policy: SIZE_BASED_WRAP resulted in no modules being wrapped.

How has this been tested?

  • Unit: setup_fsdp_envs() exports FSDP_MIN_NUM_PARAMS when min_num_params is set, and leaves it unset otherwise (no behavior change for existing configs).
  • Contract: with the field set, Accelerate's plugin picks up min_num_params=100000000 and set_auto_wrap_policy(model) yields an active size-based policy bound to that threshold; with the field unset, the plugin
    reads 0 and the policy resolves to None (confirming the field is required).
  • Environment: Python 3.12, transformers==5.9.0, accelerate==1.13.0, local venv.

AI Usage Disclaimer

Opus 4.8 assisted with diagnosing and fix

Types of changes

  • New feature (non-breaking change which adds functionality)

Summary by CodeRabbit

  • New Features

    • Added support for min_num_params configuration in FSDP settings to control the minimum parameter count threshold for automatic module wrapping during distributed training.
  • Documentation

    • Updated documentation clarifying that min_num_params is required when the SIZE_BASED_WRAP auto-wrap policy is enabled; otherwise the policy will be ignored.

Wire the FSDP_MIN_NUM_PARAMS env var from YAML so the size-based
auto-wrap policy can be configured without setting the env var manually.
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Complex PR? Review this PR in Change Stack to move by importance, not file order.

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 189f593c-5e9e-4b6e-b8ca-95ee6315c871

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds support for the min_num_params FSDP configuration parameter. It introduces a new optional field to the FSDPConfig schema, wires the value to the FSDP_MIN_NUM_PARAMS environment variable during setup, and documents that the parameter must be provided when using the SIZE_BASED_WRAP auto-wrap policy.

Changes

FSDP min_num_params Support

Layer / File(s) Summary
Schema, environment setup, and documentation
src/axolotl/utils/schemas/fsdp.py, src/axolotl/utils/trainer.py, docs/multi-gpu.qmd
FSDPConfig adds optional min_num_params field; setup_fsdp_envs exports FSDP_MIN_NUM_PARAMS environment variable when configured; documentation clarifies this parameter is required for SIZE_BASED_WRAP policy.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • axolotl-ai-cloud/axolotl#3170: Both PRs modify the FSDPConfig Pydantic schema in src/axolotl/utils/schemas/fsdp.py; this PR adds min_num_params field to the existing configuration structure.

Suggested reviewers

  • NanoCode012
  • winglian
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: exposing the min_num_params field for SIZE_BASED_WRAP in the FSDP configuration, which is the core objective of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/axolotl/utils/schemas/fsdp.py`:
- Around line 69-72: FSDPConfig's schema must validate that when
auto_wrap_policy == "SIZE_BASED_WRAP" the min_num_params field is set to a
positive integer; update the Pydantic schema in
src/axolotl/utils/schemas/fsdp.py by adding a validator (e.g., a `@root_validator`
or `@validator` referencing FSDPConfig, auto_wrap_policy, and min_num_params) that
raises a ValueError if auto_wrap_policy == "SIZE_BASED_WRAP" and (min_num_params
is None or min_num_params <= 0), ensuring invalid combinations are rejected at
schema validation time.

In `@src/axolotl/utils/trainer.py`:
- Around line 617-618: The current truthy check on
cfg.fsdp_config.min_num_params will skip explicit falsy values like 0; change
the condition in trainer.py to test for None explicitly (use "is not None" on
cfg.fsdp_config.min_num_params) so FSDP_MIN_NUM_PARAMS is exported whenever the
config provides a value (including 0), and keep the assignment to
os.environ["FSDP_MIN_NUM_PARAMS"] = str(cfg.fsdp_config.min_num_params) intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a72c8dc3-6bed-4398-8a77-b40ac8c479eb

📥 Commits

Reviewing files that changed from the base of the PR and between 69f6d8b and 66a51f2.

📒 Files selected for processing (3)
  • docs/multi-gpu.qmd
  • src/axolotl/utils/schemas/fsdp.py
  • src/axolotl/utils/trainer.py

Comment thread src/axolotl/utils/schemas/fsdp.py
Comment thread src/axolotl/utils/trainer.py
@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/axolotl/utils/trainer.py 0.00% 2 Missing ⚠️
src/axolotl/utils/schemas/fsdp.py 85.71% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

thad0ctor added 2 commits June 5, 2026 17:36
The new FSDPConfig validator requires min_num_params when
auto_wrap_policy is SIZE_BASED_WRAP, so the existing migration
fixture now needs the field to pass validation.
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