Coder Social home page Coder Social logo

Comments (2)

Tony-Y avatar Tony-Y commented on May 28, 2024

I don't know how to use pytorch_warmup inside pytorch-lightning. But you could use it by reading pytorch-lightning docs: Bring your own Custom Learning Rate Schedulers

import torch
import pytorch_warmup as warmup


def configure_optimizers(self):
    optimizer = torch.optim.AdamW(self.model..parameters(), lr=0.001, betas=(0.9, 0.999), weight_decay=0.01)
    num_steps = len(self.train_dataloader) * self.num_epochs # I don't know whether this line is correct or not.
    lr_scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=num_steps)  
    warmup_scheduler = warmup.UntunedLinearWarmup(optimizer)
    return [optimizer], [{"scheduler": (lr_scheduler, warmup_scheduler), "interval": "step"}]


def lr_scheduler_step(self, scheduler, optimizer_idx, metric):
    lr_scheduler, warmup_scheduler = scheduler
    with warmup_scheduler.dampening():
            lr_scheduler.step()

from pytorch_warmup.

Tony-Y avatar Tony-Y commented on May 28, 2024

I have just done it on Colab:
PyTorch Lightning with pytorch_warmup.ipynb

from pytorch_warmup.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.