Code Monkey home page Code Monkey logo

pytorch-lightning-sam-callback's Introduction

pytorch-lightning-sam-callback

Build Version Downloads Contributors Issues Codecov MIT

pytorch-lightning-sam-callback is an implementation of SAM using pytorch-lightning's Callback API. This project is motivated to integrate SAM with LightningModels without any modifications.

Features

  • SAM implementation
  • Provided as pytorch-lightning's Callback API

Features

  • Mixed Precision Training is not supported

Installation

$ pip install pytorch-lightning-sam-callback

Example

import torch
from torch.utils.data import DataLoader, Dataset
from pytorch_lightning import LightningModule, Trainer

from pytorch_lightning_sam_callback import SAM


class RandomDataset(Dataset):
    def __init__(self, size, num_samples):
        self.data = torch.randn(num_samples, size)

    def __getitem__(self, index):
        return self.data[index]

    def __len__(self):
        return len(self.data)


class BoringModel(LightningModule):
    def __init__(self):
        super().__init__()
        self.layer = torch.nn.Linear(32, 2)

    def forward(self, x):
        return self.layer(x)

    def training_step(self, batch, batch_idx):
        return self(batch).mean()

    def configure_optimizers(self):
        return torch.optim.SGD(self.layer.parameters(), lr=0.1)


model = BoringModel()
trainer = Trainer(max_epochs=3, callbacks=[SAM()])
trainer.fit(model, train_dataloaders=DataLoader(RandomDataset(32, 64), batch_size=2))

Training Result

training_loss validation_loss

See Also

License

MIT

pytorch-lightning-sam-callback's People

Contributors

ar90n avatar pre-commit-ci[bot] avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pytorch-lightning-sam-callback's Issues

Loss is NaN after adding the callback

I added the callback, trained with precision 16 and I get the following output during training.

Screenshot 2022-08-14 at 22 48 50

Training without the callback just gives values for the loss function.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency isort to v5.13.2
  • chore(deps): update dependency pytest to v7.4.4
  • chore(deps): update actions/cache action to v4
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-python action to v5
  • chore(deps): update actions/upload-artifact action to v4
  • chore(deps): update codecov/codecov-action action to v4
  • chore(deps): update dependency flake8 to v7
  • chore(deps): update dependency pytest to v8
  • chore(deps): update release-drafter/release-drafter action to v6
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci-testing.yml
  • actions/checkout v3
  • actions/setup-python v4
  • actions/cache v3
  • actions/upload-artifact v3
  • codecov/codecov-action v3
.github/workflows/publish.yml
  • actions/checkout v3
  • actions/setup-python v4
.github/workflows/release-drafter.yml
  • release-drafter/release-drafter v5
pep621
pyproject.toml
  • poetry-core >=1.0.0
poetry
pyproject.toml
  • python ^3.7
  • pytorch-lightning ^1.6.0
  • torch ^1.8.0
  • poethepoet ^0.19.0
  • pyright ^1.1.238
  • pytest ^7.1.1
  • pytest-cov ^3.0.0
  • pytest-xdist ^2.5.0
  • pytest-black ^0.3.12
  • pre-commit ^2.18.1
  • conventional-commit ^0.4.2
  • isort ^5.10.1
  • flake8 ^4.0.1
  • commitizen ^2.27.0
  • torchvision ^0.12.0
  • lightning-bolts ^0.6.0

  • Check this box to trigger a request for Renovate to run again on this repository

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.