Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2357,7 +2357,7 @@ def _inner_training_loop(
model = self.accelerator.prepare(self.model)
else:
if delay_optimizer_creation:
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.

cc @IlyasMoutawwakil as you wanted to remove this 👀

Copy link
Copy Markdown
Member

@IlyasMoutawwakil IlyasMoutawwakil Jul 1, 2025

Choose a reason for hiding this comment

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

yeah this fixes it too ! I honestly don't understand delay_optimizer_creation, like delay until when and why ? 😅 might make sense to explain it somewhere in the trainer

Copy link
Copy Markdown
Member

@IlyasMoutawwakil IlyasMoutawwakil Jul 1, 2025

Choose a reason for hiding this comment

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

you see why I removed it, is because currently we do create the optimizer here, and we need to prepare the fsdp model as well (otherwise fsdp fails), so the two branches of the if statement become the same

self.optimizer = self.accelerator.prepare(self.optimizer)
model = self.accelerator.prepare(self.model)
else:
model, self.optimizer = self.accelerator.prepare(self.model, self.optimizer)
else:
Expand Down