Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScheduleFree AdamW Support #184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions extensions_built_in/sd_trainer/SDTrainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def before_dataset_load(self):

def hook_before_train_loop(self):
super().hook_before_train_loop()


if self.train_config.optimizer == 'schedulefree':
self.optimizer.train()

if self.train_config.do_prior_divergence:
self.do_prior_prediction = True
Expand Down
7 changes: 7 additions & 0 deletions toolkit/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ def get_optimizer(
optimizer = torch.optim.Adam(params, lr=float(learning_rate), eps=1e-6, **optimizer_params)
elif lower_type == 'adamw':
optimizer = torch.optim.AdamW(params, lr=float(learning_rate), eps=1e-6, **optimizer_params)
elif lower_type == 'schedulefree':
print("Using ScheduleFree optimizer")
try:
from schedulefree import AdamWScheduleFree
except ImportError:
raise ImportError("Please install schedulefree to use ScheduleFree optimizer -> pip install schedulefree")
optimizer = AdamWScheduleFree(params, lr=learning_rate, **optimizer_params)
elif lower_type == 'lion':
try:
from lion_pytorch import Lion
Expand Down