• Stars
    star
    326
  • Rank 129,027 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A LARS implementation in PyTorch

torchlars

PyPI Build Status

A LARS implementation in PyTorch.

from torchlars import LARS
optimizer = LARS(optim.SGD(model.parameters(), lr=0.1))

What is LARS?

LARS (Layer-wise Adaptive Rate Scaling) is an optimization algorithm designed for large-batch training published by You, Gitman, and Ginsburg, which calculates the local learning rate per layer at each optimization step. According to the paper, when training ResNet-50 on ImageNet ILSVRC (2016) classification task with LARS, the learning curve and the best top-1 accuracy stay similar to that of the baseline (training with batch size 256 without LARS) even if the batch size is scaled up to 32K.

Large Batch Training of Convolutional Networks

Originally, LARS is formulated in terms of SGD optimizer and extension to other optimizers was not mentioned in the paper. In contrast, torchlars implements LARS as a wrapper which can take any optimizers including SGD as the base.

Additionally, LARS of torchlars is designed to more consider operation in the CUDA environment compared to existing implementations. Thanks to this, you can see only the little speed loss appears compared to just using SGD, in an environment where CPU to GPU synchronization does not occur.

Usage

Currently, torchlars requires the following environments:

  • Linux
  • Python 3.6+
  • PyTorch 1.1+
  • CUDA 10+

To use torchlars, install it via PyPI:

$ pip install torchlars

To use LARS, simply wrap your base optimizer with torchlars.LARS. LARS inherits torch.optim.Optimizer, so you can simply use LARS as optimizer on your code. After then, when you call step method of LARS, LARS automatically calculates local learning rate before running base optimizer such as SGD or Adam

The example code below shows how to use LARS using SGD as base optimizer.

from torchlars import LARS

base_optimizer = optim.SGD(model.parameters(), lr=0.1)
optimizer = LARS(optimizer=base_optimizer, eps=1e-8, trust_coef=0.001)

output = model(input)
loss = loss_fn(output, target)
loss.backward()

optimizer.step()

Benchmarking

ResNet-50 on ImageNet classification

Batch Size LR policy lr warm-up epoch Best Top-1 accuracy, %
256 poly(2) 0.2 N/A 90 73.79
8k LARS+poly(2) 12.8 5 90 73.78
16K LARS+poly(2) 25.0 5 90 73.36
32K LARS+poly(2) 29.0 5 90 72.26

Above image and table show the reproduced performance benchmark on ResNet-50, as reported in Table 4 and Figure 5 of the paper.

The cyan line represents the baseline result, which is training result with batch size 256, and others represent training result of 8K, 16K, 32K respectively. As you see, every result shows a similar learning curve and best top-1 accuracy.

Most experimental conditions are similar to used in the paper, but we slightly change some conditions like learning rate to observe comparable results as proposed by the LARS paper.

Note: We refer log file provided by paper to obtain above hyper-parameters.

Authors and Licensing

torchlars project is developed by Chunmyong Park at Kakao Brain, with Heungsub Lee, Myungryong Jeong, Woonhyuk Baek, and Chiheon Kim's help. It is distributed under Apache License 2.0.

Citation

If you apply this library to any project and research, please cite our code:

@misc{torchlars,
  author       = {Park, Chunmyong and Lee, Heungsub and Jeong, Myungryong and
                  Baek, Woonhyuk and Kim, Chiheon},
  title        = {torchlars, {A} {LARS} implementation in {PyTorch}},
  howpublished = {\url{https://github.com/kakaobrain/torchlars}},
  year         = {2019}
}

More Repositories

1

fast-autoaugment

Official Implementation of 'Fast AutoAugment' in PyTorch.
Python
1,587
star
2

nerf-factory

An awesome PyTorch NeRF library
Python
1,265
star
3

pororo

PORORO: Platform Of neuRal mOdels for natuRal language prOcessing
Python
1,252
star
4

coyo-dataset

COYO-700M: Large-scale Image-Text Pair Dataset
Python
1,062
star
5

kogpt

KakaoBrain KoGPT (Korean Generative Pre-trained Transformer)
Python
1,000
star
6

torchgpipe

A GPipe implementation in PyTorch
Python
776
star
7

karlo

Python
679
star
8

rq-vae-transformer

The official implementation of Autoregressive Image Generation using Residual Quantization (CVPR '22)
Jupyter Notebook
669
star
9

mindall-e

PyTorch implementation of a 1.3B text-to-image generation model trained on 14 million image-text pairs
Python
630
star
10

word2word

Easy-to-use word-to-word translations for 3,564 language pairs.
Python
350
star
11

g2pm

A Neural Grapheme-to-Phoneme Conversion Package for Mandarin Chinese Based on a New Open Benchmark Dataset
Python
326
star
12

kor-nlu-datasets

KorNLI and KorSTS: New Benchmark Datasets for Korean Natural Language Understanding
283
star
13

trident

A performance library for machine learning applications.
Python
176
star
14

autoclint

A specially designed light version of Fast AutoAugment
Python
170
star
15

sparse-detr

PyTorch Implementation of Sparse DETR
Python
150
star
16

hotr

Official repository for HOTR: End-to-End Human-Object Interaction Detection with Transformers (CVPR'21, Oral Presentation)
Python
132
star
17

kortok

The code and models for "An Empirical Study of Tokenization Strategies for Various Korean NLP Tasks" (AACL-IJCNLP 2020)
Python
114
star
18

bassl

Python
113
star
19

scrl

PyTorch Implementation of Spatially Consistent Representation Learning(SCRL)
Python
108
star
20

flame

Official implementation of the paper "FLAME: Free-form Language-based Motion Synthesis & Editing"
Python
103
star
21

brain-agent

Brain Agent for Large-Scale and Multi-Task Agent Learning
Python
92
star
22

helo-word

Team Kakao&Brain's Grammatical Error Correction System for the ACL 2019 BEA Shared Task
Python
88
star
23

jejueo

Jejueo Datasets for Machine Translation and Speech Synthesis
Python
74
star
24

solvent

Python
66
star
25

noc

Jupyter Notebook
44
star
26

cxr-clip

Python
43
star
27

expgan

Python
41
star
28

autowu

Official repository for Automated Learning Rate Scheduler for Large-Batch Training (8th ICML Workshop on AutoML)
Python
39
star
29

nvs-adapter

Python
33
star
30

ginr-ipc

The official implementation of Generalizable Implicit Neural Representations with Instance Pattern Composers(CVPR’23 highlight).
Python
30
star
31

coyo-vit

ViT trained on COYO-Labeled-300M dataset
Python
28
star
32

irm-empirical-study

An Empirical Study of Invariant Risk Minimization
Python
28
star
33

coyo-align

ALIGN trained on COYO-dataset
Python
25
star
34

magvlt

The official implementation of MAGVLT: Masked Generative Vision-and-Language Transformer (CVPR'23)
Python
23
star
35

hqtransformer

Locally Hierarchical Auto-Regressive Modeling for Image Generation (HQ-Transformer)
Jupyter Notebook
21
star
36

CheXGPT

Python
18
star
37

learning-loss-for-tta

"Learning Loss for Test-Time Augmentation (NeurIPS 2020)"
Python
9
star
38

stg

Official implementation of Selective Token Generation (COLING'22)
Jupyter Notebook
8
star
39

leco

Official implementation of LECO (NeurIPS'22)
Python
6
star
40

bc-hyperopt-example

brain cloud hyperopt example (mnist)
Python
3
star