Skip to main content

A Warmup Scheduler for Pytorch

Project description

Warmup Scheduler Pytorch

Tests codecov PyPI version shields.io PyPI license PyPI pyversions

Description

A Warmup Scheduler for Pytorch to make the warmup learning rate change at the beginning of training.

setup

Notice: need to install pytorch>=1.1.0 manually.
The official website of pytorch is: https://pytorch.org/

Then install as follows:

pip install warmup_scheduler_pytorch

Usage

Detail to see example.py file.

import torch

from torch.optim import SGD  # example
from torch.optim.lr_scheduler import CosineAnnealingLR  # example

from warmup_scheduler_pytorch import WarmUpScheduler

model = Model()
optimizer = SGD(model.parameters(), lr=0.1)
lr_scheduler = CosineAnnealingLR(optimizer, T_max=100, eta_min=0.01)
data_loader = torch.utils.data.DataLoader(...)
warmup_scheduler = WarmUpScheduler(optimizer, lr_scheduler,
                                   len_loader=len(data_loader),
                                   warmup_steps=100,
                                   warmup_start_lr=0.01,
                                   warmup_mode='linear')
epochs = 100
for epoch in range(epochs):
    for batch_data in data_loader:
        output = model(...)
        # loss = loss_fn(output, ...)
        # loss.backward()
        optimizer.step()
        optimizer.zero_grad()
        warmup_scheduler.step()

    # lr_scheduler.step() is no longer needed

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

warmup_scheduler_pytorch-0.1.1.tar.gz (4.9 kB view hashes)

Uploaded Source

Built Distribution

warmup_scheduler_pytorch-0.1.1-py3-none-any.whl (5.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page