Skip to content

fix _no_split_modules subscript error for transformers v5#683

Merged
Maxusmusti merged 1 commit intomainfrom
fix/transformers-v5-no-split-modules-set
Feb 11, 2026
Merged

fix _no_split_modules subscript error for transformers v5#683
Maxusmusti merged 1 commit intomainfrom
fix/transformers-v5-no-split-modules-set

Conversation

@Maxusmusti
Copy link
Collaborator

@Maxusmusti Maxusmusti commented Feb 11, 2026

Summary

Fixes TypeError: 'set' object is not subscriptable when running FSDP training with transformers v5.x.

In transformers v5, _no_split_modules is now converted to a set during model initialization (post_init()), whereas it was previously a list. The code in get_fsdp_config() was using [0] to access the first element, which fails on sets.

Fix: Use next(iter(...)) to retrieve an element, which works with both sets and lists.

Test plan

  • Verified fix resolves the error in SFT validation script
  • Updated unit test mock to use a set to match transformers v5 behavior

Summary by CodeRabbit

  • Bug Fixes
    • Improved robustness of the FSDP wrap policy configuration during model acceleration.

@Maxusmusti Maxusmusti self-assigned this Feb 11, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

The pull request refactors container access patterns by replacing direct index-based retrieval with iterator-based retrieval for _no_split_modules, while updating the corresponding test fixture to use a set instead of a list, ensuring consistency between implementation and test.

Changes

Cohort / File(s) Summary
FSDP wrap policy accessor refactor
src/instructlab/training/accelerator.py
Replaced direct index access [0] with safe iterator-based retrieval next(iter(...)) for _no_split_modules to support non-list iterables.
Mock fixture update
tests/unit/test_accelerator.py
Changed _no_split_modules from list to set in mock_model fixture to align with refactored iterator-based accessor logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

one-approval

Poem

🐰 From indexed lists we hop away,
To iterators light and fleet!
Sets replace the ordered array,
A refactoring so neat!
Safer access, cleaner flow,
Now the code can better grow! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing a subscript error with _no_split_modules that occurs in transformers v5 due to the attribute being a set rather than a list.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/transformers-v5-no-split-modules-set

No actionable comments were generated in the recent review. 🎉

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

@mergify mergify bot added testing Relates to testing ci-failure labels Feb 11, 2026
Copy link
Member

@RobotSail RobotSail left a comment

Choose a reason for hiding this comment

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

LGTM

@mergify mergify bot added the one-approval label Feb 11, 2026
@Maxusmusti Maxusmusti merged commit c517712 into main Feb 11, 2026
14 of 18 checks passed
@Maxusmusti Maxusmusti deleted the fix/transformers-v5-no-split-modules-set branch February 11, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants