Skip to content

Add New lr scheduler - #1393

Merged
kohya-ss merged 8 commits into
kohya-ss:devfrom
sdbds:new_lr_scheduler
Sep 11, 2024
Merged

Add New lr scheduler#1393
kohya-ss merged 8 commits into
kohya-ss:devfrom
sdbds:new_lr_scheduler

Conversation

@sdbds

@sdbds sdbds commented Jun 28, 2024

Copy link
Copy Markdown
Contributor

Change Lr schedulers library from diffusers to transformers, they use same library but transformers had more lr schedulers.
Considering the community has always wanted custom learning rate, I think these newly added regulators will meet the demand.

Add inverse sqrt learning rate scheduler
image
new argument lr_scheduler_timescale,default to warms_up_steps

Add cosine with min lr scheduler
When set the num_steps=100, num_warmup_steps=10, lr=0.2, min_lr=0.01. The learning rate looks like:
image

new argument lr_scheduler_min_lr_ratio,default to 0 as cosine lr scheduler.

Add WSD scheduler
The ladder scheduler that so many people have been wanting.
image

new argument lr_decay_steps,
new argument lr_scheduler_min_lr_ratio,default to 0.

need update requirement transformers==4.41.2

@sdbds

sdbds commented Aug 30, 2024

Copy link
Copy Markdown
Contributor Author

Fix bugs now, i think it works well.
@kohya-ss

@kohya-ss

kohya-ss commented Sep 1, 2024

Copy link
Copy Markdown
Owner

Thank you! However, removing PIECEWISE_CONSTANT will likely impact users. I would like to update the code after merging so that it can be used, but it will take some time. I'd like to prioritize some other PRs. If you could fix this, that would be great.

@sdbds

sdbds commented Sep 1, 2024

Copy link
Copy Markdown
Contributor Author

Thank you! However, removing PIECEWISE_CONSTANT will likely impact users. I would like to update the code after merging so that it can be used, but it will take some time. I'd like to prioritize some other PRs. If you could fix this, that would be great.

OK,just keep diffusers import for backup using, use

name = SchedulerType(name) or DiffusersSchedulerType(name)
schedule_func = TYPE_TO_SCHEDULER_FUNCTION[name] or DIFFUSERS_TYPE_TO_SCHEDULER_FUNCTION[name]

to judge if using PIECEWISE_CONSTANT.
And i add parser type for input float with warmup and decay ratio, don't need to calculate training total steps.

@kohya-ss

kohya-ss commented Sep 9, 2024

Copy link
Copy Markdown
Owner

Sorry for bothering you again. Is there a reason to upgrade the version of the library other than transformers? It requires some more comprehensive testing, which takes time.

@sdbds

sdbds commented Sep 9, 2024

Copy link
Copy Markdown
Contributor Author

Sorry for bothering you again. Is there a reason to upgrade the version of the library other than transformers? It requires some more comprehensive testing, which takes time.

The main thing is to upgrade the transformers version, and after upgrading the transformers version the other two dependencies will also ask for an update, so it's three version updates.
Since the PR is older, I reviewed the latest three dependency update histories, and there don't seem to be any major bug fixes as well as disruptive changes.

@kohya-ss

kohya-ss commented Sep 9, 2024

Copy link
Copy Markdown
Owner

Thanks, I understand. Then it seems like there is no big problem. I've updated accelerate and transformers in the sd3 branch, so maybe I can match that. I'll do some checks and merge :)

Comment thread library/train_util.py
@kohya-ss
kohya-ss merged commit fd68703 into kohya-ss:dev Sep 11, 2024
@kohya-ss

Copy link
Copy Markdown
Owner

Sorry for the delay, I have merged this.

@kohya-ss kohya-ss mentioned this pull request Jan 17, 2025
nana0304 pushed a commit to nana0304/sd-scripts that referenced this pull request Jun 4, 2025
* add new lr scheduler

* fix bugs and use num_cycles / 2

* Update requirements.txt

* add num_cycles for min lr

* keep PIECEWISE_CONSTANT

* allow use float with warmup or decay ratio.

* Update train_util.py
nana0304 pushed a commit to nana0304/sd-scripts that referenced this pull request Jun 4, 2025
nana0304 pushed a commit to nana0304/sd-scripts that referenced this pull request Jun 4, 2025
nana0304 pushed a commit to nana0304/sd-scripts that referenced this pull request Jun 4, 2025
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.

2 participants