question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exponential Shift does not effect some links after the links' lr are manually modified

See original GitHub issue
  • Conditions
    • Chainer version: 5.0.0b1
    • CuPy version: 5.0.0b1
    • OS/Platform: Ubuntu 16.04
    • CUDA/cuDNN version: 9.0

Problem

I tried to reproduce lr_mult in caffe, I multiply hyperparameter lr of some links. And I use ExponentialShift to multiply all lr in the model, but the modified link’s lr does not change. I tried with the code below, and conv1’s lr does not change and still remain to 0.03. I expected that conv1’s lr will be 0.15. Is this expected return for optimizer in Chainer?

import chainer


class ExampleModel(chainer.Chain):

    def __init__(self):
        super(ExampleModel, self).__init__()
        with self.init_scope():
            self.conv1 = chainer.links.Convolution2D(3, 10, 1, 1)
            self.conv2 = chainer.links.Convolution2D(10, 10, 1, 1)


def main():
    model = ExampleModel()
    optimizer = chainer.optimizers.MomentumSGD(lr=0.01)
    optimizer.setup(model)
    model.conv1.W.update_rule.hyperparam.lr *= 3
    print('Done: conv1 lr * 3')
    print('  conv1 lr: {}'.format(model.conv1.W.update_rule.hyperparam.lr))
    print('  conv2 lr: {}'.format(model.conv2.W.update_rule.hyperparam.lr))

    optimizer.lr *= 5
    print('Done: optimizer.lr * 5')
    print('  conv1 lr: {}'.format(model.conv1.W.update_rule.hyperparam.lr))
    print('  conv2 lr: {}'.format(model.conv2.W.update_rule.hyperparam.lr))


if __name__ == '__main__':
    main()

output

$ python example.py
Done: conv1 lr * 3
  conv1 lr: 0.03
  conv2 lr: 0.01
Done: optimizer.lr * 5
  conv1 lr: 0.03
  conv2 lr: 0.05

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
knorth55commented, Jul 17, 2019

Do not close this

1reaction
beam2dcommented, Jun 27, 2018

Chainer currently does not have a way to emulate lr_mult. It looks better to add support for it.

As a workaround, you can use multiple ExponentialShift extensions to modify lr of different parameters. For example, if you want to use x2 lr for some parameters, you can write:

optimizer.setup(model)
...
trainer.extend(extensions.ExponentialShift('lr', rate))
twice_lr = chainer.optimizer.Hyperparameter(optimizer.hyperparam)
twice_lr.lr = optimizer.lr * 2
for param in params_for_which_you_want_to_do_lr_mult:
    param.update_rule.hyperparam = chainer.optimizer.Hyperparameter(twice_lr)
trainer.extend(extensions.ExponentialShift('lr', rate, optimizer=twice_lr),
               name='my_exponential_shift'))  # name should be different from "ExponentialShift"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Batch normalization in 3 levels of understanding
It consists of normalizing activation vectors from hidden layers using the first and the second statistical moments (mean and variance) of the ...
Read more >
Chapter 14: SOLUTIONS TO TEXT PROBLEMS:
When a competitive firm doubles the amount it sells, the price remains the same, so its total revenue doubles. 2. The price faced...
Read more >
EC-Lab - Software User's Manual - MMRC
The equipment described in this manual has been designed in accordance with EN61010 and EN61326 and has been supplied in a safe condition....
Read more >
SARS-CoV-2 is associated with changes in brain ... - Nature
There is strong evidence of brain-related abnormalities in COVID-191–13. However, it remains unknown whether the impact of SARS-CoV-2 ...
Read more >
IBM Z Server Time Protocol Guide
STP uses a message-based protocol in which timekeeping information is passed over externally defined coupling links, such as Coupling Express LR ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found