Comments (9)
Do you want one like an LR scheduler with warmup provided by Hugging Face?
from pytorch_warmup.
I'm sorry for misunderstanding your request. You have to combine a global-step and epoch LR scheduler, but it could not be as easy as it sounds. I don't know such example codes, but I'll let you know if I find.
from pytorch_warmup.
I made sample code: https://gist.github.com/Tony-Y/49d6cffa21e60095fdf9b1bec31cdbaa
for batch_idx, (data, target) in enumerate(progressbar(train_loader)):
...
extra_params["global_step"] += 1
if extra_params["global_step"] <= extra_params["warmup_period"]:
with warmup_scheduler.dampening():
pass
elif (extra_params["global_step"] - extra_params["warmup_period"]) % len(train_loader) == 0:
lr_scheduler.step()
from pytorch_warmup.
I revised the code: https://gist.github.com/Tony-Y/1aa2196ce161d8a4da90cf027ec0f260
New code:
class EpochSchedulerWithWarmup:
def __init__(self, warmup_period, every_n_steps, steps_per_epoch, warmup_scheduler, lr_scheduler):
self.global_step = 0
self.warmup_period = warmup_period
self.every_n_steps = every_n_steps
self.steps_per_epoch = steps_per_epoch
self.warmup_scheduler = warmup_scheduler
self.lr_scheduler = lr_scheduler
def step(self):
self.global_step += 1
if self.global_step <= self.warmup_period and self.global_step % self.every_n_steps == 0:
with self.warmup_scheduler.dampening():
pass
elif (self.global_step - self.warmup_period) % self.steps_per_epoch == 0:
self.lr_scheduler.step()
Usage:
lr_scheduler = torch.optim.lr_scheduler.MultiStepLR(optimizer, milestones=[num_epochs//3], gamma=0.1)
warmup_scheduler = warmup.UntunedLinearWarmup(optimizer)
lr_scheduler_with_warmup = EpochSchedulerWithWarmup(
warmup_period=2000, every_n_steps=1,
steps_per_epoch=len(dataloader),
warmup_scheduler=warmup_scheduler,
lr_scheduler=lr_scheduler)
for epoch in range(1,num_epochs+1):
for iter, batch in enumerate(dataloader):
optimizer.zero_grad()
loss = ...
loss.backward()
optimizer.step()
lr_scheduler_with_warmup.step()
Does this code resolve your issue?
from pytorch_warmup.
EpochSchedulerWithWarmup
has a bug. Its step()
should be:
def step(self):
self.global_step += 1
if self.global_step <= self.warmup_period:
if self.global_step % self.every_n_steps == 0:
with self.warmup_scheduler.dampening():
pass
elif (self.global_step - self.warmup_period) % self.steps_per_epoch == 0:
self.lr_scheduler.step()
from pytorch_warmup.
I checked every_n_steps
works well: https://gist.github.com/Tony-Y/6c79267cab84f3d0a2309f25a9123da4
I think this issue was resolved. Reopen this issue if not.
from pytorch_warmup.
Thank you very much for the kindly help. I will have a try.
from pytorch_warmup.
Thank you very much for the kindly help. I will have a try.
Thank you for all the help๏ผ They are very effective! the training process is stable now. thanks
from pytorch_warmup.
I'm happy to hear that.
from pytorch_warmup.
Related Issues (14)
- Unexpected keyword argument `warmup_period` HOT 1
- Why did my learning rate drop from the initial lr HOT 3
- UserWarning: Detected call of `lr_scheduler.step()` before `optimizer.step()` HOT 2
- My lr jumped from 0.01 to 0.0498 without any linear signs. HOT 2
- About the learning rate in scheduler HOT 1
- Can the warmup_scheduler update the learning rate every epoch and not every batch? HOT 2
- Why is warmup better than RAdam? HOT 3
- difference of this library with hugging face HOT 3
- What is the decay rule of thumb? HOT 3
- UserWarning: The epoch parameter in `scheduler.step()` was not necessary and is being deprecated where possible. HOT 2
- no attribute named dampening HOT 1
- How to use in `pytorch-lightning`? HOT 2
- License file is not included in sdist HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytorch_warmup.