-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[xdoctest][task 109] Reformat example code with google style in python/paddle/optimizer/lr.py #56225
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
✅ This PR's description meets the template requirements! |
python/paddle/optimizer/lr.py
Outdated
|
||
>>> paddle.enable_static() | ||
>>> base_lr = 0.1 | ||
>>> sgd_optimizer = fluid.optimizer.SGD( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fluid API 即将退场,这里的 fluid.optimizer.SGD
可以使用 paddle.optimizer.SGD
代替,两者参数可能略有不同,可能需要稍微调整下,辛苦修改一下~后面的几个 API 同样~
另外,如果不需要开启 paddle.enable_static()
的话,就不要开启了
@Difers 迁移 API 时可以注意一下文档也修改下
python/paddle/optimizer/lr.py
Outdated
.. code-block:: python | ||
|
||
import paddle.fluid as fluid | ||
|
||
boundaries = [100, 200] | ||
lr_steps = [0.1, 0.01, 0.001] | ||
learning_rate = fluid.layers.piecewise_decay(boundaries, lr_steps) #case1, 1D-Tensor | ||
#learning_rate = 0.1 #case2, single-value | ||
warmup_steps = 50 | ||
start_lr = 1. / 3. | ||
end_lr = 0.1 | ||
decayed_lr = fluid.layers.linear_lr_warmup(learning_rate, | ||
warmup_steps, start_lr, end_lr) | ||
|
||
place = fluid.CPUPlace() | ||
exe = fluid.Executor(place) | ||
exe.run(fluid.default_startup_program()) | ||
out, = exe.run(fetch_list=[decayed_lr.name]) | ||
print(out) | ||
# case1: [0.33333334] | ||
# case2: [0.33333334] | ||
>>> import paddle.fluid as fluid | ||
>>> paddle.enable_static() | ||
>>> boundaries = [100, 200] | ||
>>> lr_steps = [0.1, 0.01, 0.001] | ||
>>> learning_rate = fluid.layers.piecewise_decay(boundaries, lr_steps) #case1, 1D-Tensor | ||
>>> # learning_rate = 0.1 # case2, single-value | ||
>>> warmup_steps = 50 | ||
>>> start_lr = 0.1 | ||
>>> end_lr = 1. / 3. | ||
>>> decayed_lr = fluid.layers.linear_lr_warmup( | ||
... learning_rate, | ||
... warmup_steps, | ||
... start_lr, | ||
... end_lr) | ||
>>> place = fluid.CPUPlace() | ||
>>> exe = fluid.Executor(place) | ||
>>> exe.run(fluid.default_startup_program()) | ||
>>> out, = exe.run(fetch_list=[decayed_lr.name]) | ||
>>> print(out) | ||
[0.1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
整体加一个缩进吧
以及 fluid API 需要替换
@Difers,确认一下这个 API 是否是动静统一?如果是的话,麻烦 @Candy2Tang 用动态图写法重写一下吧~应该比现在的会更简洁些~
@Candy2Tang 注意下这几个 API 是 @Difers 三天前刚从 fluid 迁移出来的(#55986),所以需要最新版 Nightly build 或者自行编译才能在本地测试运行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这几个迁移过来的似乎主要都是用于静态图下的,在动态图下就是直接调用同文件上方的同功能动态图API了,将这几个统一成静态图的写法用于跟上方的API做区分会不会好些?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那就麻烦 @Candy2Tang 统一用静态图写法来写吧,不需要改成动态图写法了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SigureMo 抱歉,今天刚有空统一来修复。想问下这个文档样例是要改成静态图的么?我有一些疑问,这个api 并不是放到 static 目录下,为什么要改成静态图形式呀?paddle不是主推的动态图么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Candy2Tang 你好,这部分api(autoincreased_step_counter...linear_lr_warmup)是几天前从fluid目录迁移出来的#55986,当时考虑到这部分api与optimizer/lr.py中的api功能相似,因此迁移到了这里,同时可以看出这部分api在动态图时实际是调用原lr中的功能相似的api,主要是在静态图中发挥作用,因此建议改为静态图形式,且方便于原lr.py中动态图api区分。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTMeow 🐾
…n/paddle/optimizer/lr.py (PaddlePaddle#56225) * [xdoctest][task 109] test=docs_preview * fix whitespace test=docs_preview * Apply suggestions from code review * fix indent and legacy fluid apis --------- Co-authored-by: Nyakku Shigure <sigure.qaq@gmail.com>
PR types
Others
PR changes
Docs
Description
对应tracking issue: #55629
预览链接: