Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
b54ee044
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
1 年多 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b54ee044
编写于
12月 20, 2021
作者:
Z
zhangbo9674
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Accelerate dynamic graph amp training
上级
7732a69f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
13 addition
and
7 deletion
+13
-7
ppcls/engine/engine.py
ppcls/engine/engine.py
+2
-0
ppcls/engine/train/train.py
ppcls/engine/train/train.py
+7
-6
ppcls/optimizer/optimizer.py
ppcls/optimizer/optimizer.py
+4
-1
未找到文件。
ppcls/engine/engine.py
浏览文件 @
b54ee044
...
...
@@ -250,6 +250,8 @@ class Engine(object):
self
.
scaler
=
paddle
.
amp
.
GradScaler
(
init_loss_scaling
=
self
.
scale_loss
,
use_dynamic_loss_scaling
=
self
.
use_dynamic_loss_scaling
)
if
self
.
config
[
'AMP'
][
'use_pure_fp16'
]
is
True
:
self
.
model
=
paddle
.
amp
.
decorate
(
models
=
self
.
model
,
level
=
'O2'
)
self
.
max_iter
=
len
(
self
.
train_dataloader
)
-
1
if
platform
.
system
(
)
==
"Windows"
else
len
(
self
.
train_dataloader
)
...
...
ppcls/engine/train/train.py
浏览文件 @
b54ee044
...
...
@@ -41,14 +41,15 @@ def train_epoch(engine, epoch_id, print_batch_step):
# image input
if
engine
.
amp
:
with
paddle
.
amp
.
auto_cast
(
custom_black_list
=
{
"flatten_contiguous_range"
,
"greater_than"
}):
amp_level
=
'O1'
if
engine
.
config
[
'AMP'
][
'use_pure_fp16'
]
is
True
:
amp_level
=
'O2'
with
paddle
.
amp
.
auto_cast
(
custom_black_list
=
{
"flatten_contiguous_range"
,
"greater_than"
},
level
=
amp_level
):
out
=
forward
(
engine
,
batch
)
loss_dict
=
engine
.
train_loss_func
(
out
,
batch
[
1
])
else
:
out
=
forward
(
engine
,
batch
)
loss_dict
=
engine
.
train_loss_func
(
out
,
batch
[
1
])
loss_dict
=
engine
.
train_loss_func
(
out
,
batch
[
1
])
# step opt and lr
if
engine
.
amp
:
...
...
@@ -58,7 +59,7 @@ def train_epoch(engine, epoch_id, print_batch_step):
else
:
loss_dict
[
"loss"
].
backward
()
engine
.
optimizer
.
step
()
engine
.
optimizer
.
clear_grad
()
engine
.
optimizer
.
clear_grad
(
set_to_zero
=
True
)
engine
.
lr_sch
.
step
()
# below code just for logging
...
...
ppcls/optimizer/optimizer.py
浏览文件 @
b54ee044
...
...
@@ -36,13 +36,15 @@ class Momentum(object):
momentum
,
weight_decay
=
None
,
grad_clip
=
None
,
multi_precision
=
False
):
multi_precision
=
True
,
use_multi_tensor
=
True
):
super
().
__init__
()
self
.
learning_rate
=
learning_rate
self
.
momentum
=
momentum
self
.
weight_decay
=
weight_decay
self
.
grad_clip
=
grad_clip
self
.
multi_precision
=
multi_precision
self
.
use_multi_tensor
=
use_multi_tensor
def
__call__
(
self
,
model_list
):
# model_list is None in static graph
...
...
@@ -54,6 +56,7 @@ class Momentum(object):
weight_decay
=
self
.
weight_decay
,
grad_clip
=
self
.
grad_clip
,
multi_precision
=
self
.
multi_precision
,
use_multi_tensor
=
self
.
use_multi_tensor
,
parameters
=
parameters
)
return
opt
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录