2.4K Star 8.1K Fork 4.4K

GVPMindSpore / mindspore

 / 详情

Implement a new dynamic learning rate using operations in mindspore.ops

TODO
RFC 成员
创建于  
2020-12-09 21:39
name about labels
Task Use this template for task tracking kind/task

Task Description

  1. Reference:
  • Refer to the learning_rate_schedule module of mindspore, click learning_rate_schedule to the source code.
  • One of dynamic learing rate in learning_rate_schedule:
class CosineDecayLR(LearningRateSchedule):
    def __init__(self, min_lr, max_lr, decay_steps):
        super(CosineDecayLR, self).__init__()
        self.min_lr = min_lr
        self.max_lr = max_lr
        self.decay_steps = decay_steps
        self.math_pi = math.pi
        self.delta = 0.5 * (max_lr - min_lr)
        self.cos = P.Cos()
        self.min = P.Minimum()
        self.cast = P.Cast()

    def construct(self, global_step):
        p = self.cast(self.min(global_step, self.decay_steps), mstype.float32)
        return self.min_lr + self.delta * (1.0 + self.cos(self.math_pi * p / self.decay_steps))

LearningRateSchedule is subclass of nn.Cell.

  1. How to test the learning rate schedule
    The result of calling the learning_rate_schedule is the learning rate value at current step:
min_lr = 0.01
max_lr = 0.1
decay_steps = 4
global_steps = Tensor(2, mstype.int32)
cosine_decay_lr = CosineDecayLR(min_lr, max_lr, decay_steps)
result = cosine_decay_lr(global_steps)
print(result)
0.055
  1. How to use the learning rate schedule
    Users should pass the Cell instance cosine_decay_lr to a optimizer. Then, during the training process, the optimizer call cosine_decay_lr with global_step as input to get the current learning rate.
    global_step and invocation process described above are defined in the nn.Optimizer.
net = Net()
loss = nn.SoftmaxCrossEntropyWithLogits()
optim = nn.Momentum(net.trainable_params(), learning_rate=cosine_decay_lr)
model = Model(net, loss_fn=loss, optimizer=optim, metrics=None)

dataset = create_custom_dataset()
model.train(1, dataset)

Backend

  • GPU/CPU

Notes

Before developing the learning rate, you need to make sure that the operators provided by MindSpore meet your requirements. Click here to view the operators currently supported by MindSpore.

评论 (5)

wangnan39 创建了RFC
wangnan39 关联仓库设置为MindSpore/mindspore
展开全部操作日志

Hey wangnan39, Welcome to MindSpore Community.
All of the projects in MindSpore Community are maintained by @mindspore-ci-bot.
That means the developers can comment below every pull request or issue to trigger Bot Commands.
Please follow instructions at https://gitee.com/mindspore/community/blob/master/command.md to find the details.

wangnan39 修改了标题
wangnan39 修改了描述
wangnan39 任务类型RFC 修改为Task-Tracking
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 修改了描述
wangnan39 添加了
 
mindspore-contrib
标签
zhunaipan 负责人设置为wangnan39

请确认该issue最新状态~谢谢!@wangnan39

hello, @wangnan39 , Has this problem been resolved? If yes, please close this issue, thanks!
你好, @wangnan39 , 这个问题是否已经解决了呢? 如果是的,请关闭这个issue, 谢谢!

hello, @wangnan39 , Has this problem been resolved? If yes, please close this issue, thanks!
你好, @wangnan39 , 这个问题是否已经解决了呢? 如果是的,请关闭这个issue, 谢谢!

hello, @wangnan39 , Has this problem been resolved? If it is in progress, please change the status to WIP. If the issue was solved, please close this issue, thanks!
你好, @wangnan39 , 这个问题是否已经解决了呢? 如果正在进行中,请把issue状态设置为WIP;如果问题已解决,请关闭这个issue, 谢谢!

wangnan39 任务类型Task-Tracking 修改为RFC
wangnan39 里程碑设置为IT-用户编程-TODO

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(4)
5518576 mindspore ci 1587902139 7347090 simson wu 1585037194 8777557 test bot 1617846881
Python
1
https://gitee.com/mindspore/mindspore.git
git@gitee.com:mindspore/mindspore.git
mindspore
mindspore
mindspore

搜索帮助

53164aa7 5694891 3bd8fe86 5694891