Skip to content

FSDP2 gloo tests: stub every helper the trainer wrapper calls, not a fixed list - #14518

Merged
danielhanchen merged 1 commit into
mainfrom
fix/fsdp2-harness-stub-new-helpers
Oct 21, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix/fsdp2-harness-stub-new-helpers

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Problem

The Repo tests (CPU, fsdp2) shard fails on main: 11 tests across the gloo files that wrap Trainer.__init__ with _install_wrapped_trainer_init from tests/test_fsdp2_native_trainer_args_gloo.py (for example #14494). Every rank crashes the same way:

File "unsloth/models/_utils.py", line 5615, in _unsloth_trainer_init
    _size_auto_checkpoint_skip_for_trainer(self)
NameError: name '_size_auto_checkpoint_skip_for_trainer' is not defined

The harness runs the real _unsloth_trainer_init source from _utils.py in a namespace that stubs the helpers it calls. That list is written out by hand. #14404 added a call to _size_auto_checkpoint_skip_for_trainer, which is not in the list. The product is fine: the helper is defined at module level in _utils.py.

Fix

Test only. The explicit stubs stay. On top of them, every free function _unsloth_trainer_init calls that the namespace does not provide is stubbed as well. Builtins, and names the wrapper binds itself (assignments and in-function imports), are excluded. The next helper added to the wrapper cannot take the shard down this way again.

Verification

CPU torch 2.10, peft 0.21.2, accelerate 1.15.0, unsloth-zoo main. Files run: test_fsdp2_native_optim_reentry_gloo.py, test_fsdp2_native_trainer_fsdp_clip_gloo.py, test_fsdp2_native_subclass_optimizer_gloo.py and test_fsdp2_native_trainer_args_gloo.py.

  • main: 5 failed, 12 passed (the NameError above).
  • With this change: 17 passed.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T13:50:13.005044Z 9bf373b Manual request
🔒 Security Review ⚠️ Failed 2026-10-21T13:49:09.967379Z
We couldn’t complete this review. Comment @codex security review to try again.
9bf373b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 9bf373bc48

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit ab26545 into main Oct 21, 2026
@danielhanchen
danielhanchen deleted the fix/fsdp2-harness-stub-new-helpers branch October 21, 2026 13:56
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