Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b808979b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
b808979b
编写于
10月 15, 2020
作者:
K
Kaipeng Deng
提交者:
GitHub
10月 15, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
step lr_scheduler on epoch end in hapi/model.py fit (#27730)
* step lr_scheduler on epoch end in hapi/model.py fit. test=develop
上级
d17681dc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
53 addition
and
1 deletion
+53
-1
python/paddle/hapi/model.py
python/paddle/hapi/model.py
+5
-0
python/paddle/tests/test_model.py
python/paddle/tests/test_model.py
+48
-1
未找到文件。
python/paddle/hapi/model.py
浏览文件 @
b808979b
...
...
@@ -1461,6 +1461,11 @@ class Model(object):
cbks
.
on_end
(
'eval'
,
eval_logs
)
# step learning rate scheduler on each epcoh end
if
isinstance
(
self
.
_optimizer
.
_learning_rate
,
paddle
.
optimizer
.
lr
.
LRScheduler
):
self
.
_optimizer
.
_learning_rate
.
step
()
cbks
.
on_end
(
'train'
,
logs
)
self
.
_test_dataloader
=
None
...
...
python/paddle/tests/test_model.py
浏览文件 @
b808979b
...
...
@@ -33,7 +33,7 @@ from paddle.nn.layer.loss import CrossEntropyLoss
from
paddle.metric
import
Accuracy
from
paddle.vision.datasets
import
MNIST
from
paddle.vision.models
import
LeNet
from
paddle.io
import
DistributedBatchSampler
from
paddle.io
import
DistributedBatchSampler
,
Dataset
from
paddle.hapi.model
import
prepare_distributed_context
from
paddle.fluid.dygraph.jit
import
declarative
from
paddle.fluid.dygraph.dygraph_to_static.program_translator
import
ProgramTranslator
...
...
@@ -295,6 +295,15 @@ class MyModel(paddle.nn.Layer):
return
y
class
MyDataset
(
Dataset
):
def
__getitem__
(
self
,
idx
):
return
np
.
random
.
random
(
size
=
(
20
,)).
astype
(
np
.
float32
),
\
np
.
random
.
randint
(
0
,
10
,
size
=
(
1
,)).
astype
(
np
.
int64
)
def
__len__
(
self
):
return
40
class
TestModelFunction
(
unittest
.
TestCase
):
def
set_seed
(
self
,
seed
=
1024
):
paddle
.
manual_seed
(
seed
)
...
...
@@ -599,6 +608,44 @@ class TestModelFunction(unittest.TestCase):
shutil
.
rmtree
(
save_dir
)
class
TestModelWithLRScheduler
(
unittest
.
TestCase
):
def
test_fit
(
self
):
def
make_optimizer
(
parameters
=
None
):
base_lr
=
1e-3
momentum
=
0.9
weight_decay
=
5e-4
boundaries
=
[
5
,
8
]
values
=
[
base_lr
*
(
0.1
**
i
)
for
i
in
range
(
len
(
boundaries
)
+
1
)]
learning_rate
=
paddle
.
optimizer
.
lr
.
PiecewiseDecay
(
boundaries
=
boundaries
,
values
=
values
)
learning_rate
=
paddle
.
optimizer
.
lr
.
LinearWarmup
(
learning_rate
=
learning_rate
,
warmup_steps
=
4
,
start_lr
=
base_lr
/
5.
,
end_lr
=
base_lr
,
verbose
=
True
)
optimizer
=
paddle
.
optimizer
.
Momentum
(
learning_rate
=
learning_rate
,
weight_decay
=
weight_decay
,
momentum
=
momentum
,
parameters
=
parameters
)
return
optimizer
device
=
paddle
.
set_device
(
'cpu'
)
fluid
.
enable_dygraph
(
device
)
net
=
MyModel
()
inputs
=
[
InputSpec
([
None
,
20
],
'float32'
,
'x'
)]
labels
=
[
InputSpec
([
None
,
1
],
'int64'
,
'label'
)]
optim
=
make_optimizer
(
net
.
parameters
())
model
=
Model
(
net
,
inputs
,
labels
)
model
.
prepare
(
optimizer
=
optim
,
loss
=
CrossEntropyLoss
(
reduction
=
"sum"
))
dataset
=
MyDataset
()
model
.
fit
(
dataset
,
dataset
,
batch_size
=
4
,
epochs
=
10
,
num_workers
=
0
)
paddle
.
enable_static
()
class
TestRaiseError
(
unittest
.
TestCase
):
def
test_input_without_name
(
self
):
net
=
MyModel
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录