Skip to content
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

Merged
merged 4 commits into from
Aug 21, 2023

Conversation

Candy2Tang
Copy link
Contributor

@Candy2Tang Candy2Tang commented Aug 13, 2023

PR types

Others

PR changes

Docs

Description

对应tracking issue: #55629
预览链接:

  • en: 生成中...
  • zh: 生成中...

@paddle-bot
Copy link

paddle-bot bot commented Aug 13, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added contributor External developers status: proposed labels Aug 13, 2023
@paddle-bot
Copy link

paddle-bot bot commented Aug 13, 2023

✅ This PR's description meets the template requirements!
Please wait for other CI results.

@Candy2Tang Candy2Tang changed the title [xdoctest][task 109] test=docs_preview [xdoctest][task 109] Reformat example code with google style in python/paddle/optimizer/lr.py Aug 13, 2023
python/paddle/optimizer/lr.py Show resolved Hide resolved
python/paddle/optimizer/lr.py Outdated Show resolved Hide resolved
python/paddle/optimizer/lr.py Outdated Show resolved Hide resolved
python/paddle/optimizer/lr.py Outdated Show resolved Hide resolved
python/paddle/optimizer/lr.py Outdated Show resolved Hide resolved
python/paddle/optimizer/lr.py Outdated Show resolved Hide resolved
python/paddle/optimizer/lr.py Outdated Show resolved Hide resolved

>>> paddle.enable_static()
>>> base_lr = 0.1
>>> sgd_optimizer = fluid.optimizer.SGD(
Copy link
Member

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 Show resolved Hide resolved
Comment on lines 2777 to 2798
.. 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]
Copy link
Member

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 或者自行编译才能在本地测试运行

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这几个迁移过来的似乎主要都是用于静态图下的,在动态图下就是直接调用同文件上方的同功能动态图API了,将这几个统一成静态图的写法用于跟上方的API做区分会不会好些?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那就麻烦 @Candy2Tang 统一用静态图写法来写吧,不需要改成动态图写法了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SigureMo 抱歉,今天刚有空统一来修复。想问下这个文档样例是要改成静态图的么?我有一些疑问,这个api 并不是放到 static 目录下,为什么要改成静态图形式呀?paddle不是主推的动态图么?

Copy link
Contributor

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区分。

@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Aug 14, 2023
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow 🐾

@luotao1 luotao1 merged commit e79133e into PaddlePaddle:develop Aug 21, 2023
BeingGod pushed a commit to BeingGod/Paddle that referenced this pull request Sep 9, 2023
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants