Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
e31a0a50
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e31a0a50
编写于
8月 17, 2022
作者:
Z
zyfncg
提交者:
GitHub
8月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine eager_gen for amp (#45211)
上级
e51ea538
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
29 addition
and
55 deletion
+29
-55
paddle/fluid/eager/auto_code_generator/final_state_generator/eager_gen.py
...er/auto_code_generator/final_state_generator/eager_gen.py
+29
-55
未找到文件。
paddle/fluid/eager/auto_code_generator/final_state_generator/eager_gen.py
浏览文件 @
e31a0a50
...
@@ -428,20 +428,6 @@ CHECK_NAN_AND_INF_TEMPLATE = \
...
@@ -428,20 +428,6 @@ CHECK_NAN_AND_INF_TEMPLATE = \
""" if (FLAGS_check_nan_inf) {{ egr::CheckTensorHasNanOrInf("{}", {}); }}
""" if (FLAGS_check_nan_inf) {{ egr::CheckTensorHasNanOrInf("{}", {}); }}
"""
"""
# This list contains ops that do not need to generate amp logic
# All optimizer ops in this list
no_amp_list
=
[
'adam_'
,
'adam'
,
'adamw_'
,
'adamw'
,
'average_accumulates'
,
'average_accumulates_'
,
'decayed_adagrad_'
,
'decayed_adagrad'
,
'dgc_momentum_'
,
'dgc_momentum'
,
'distributed_fused_lamb_'
,
'distributed_fused_lamb'
,
'dpsgd_'
,
'dpsgd'
,
'ftrl_'
,
'ftrl'
,
'lamb_'
,
'lamb'
,
'lars_momentum_'
,
'lars_momentum'
,
'merged_adam_'
,
'merged_adam'
,
'merged_momentum_'
,
'merged_momentum'
,
'momentum_'
,
'momentum'
,
'proximal_adagrad_'
,
'proximal_adagrad'
,
'proximal_gd_'
,
'proximal_gd'
,
'rmsprop_'
,
'rmsprop'
,
'sgd_'
,
'sgd'
,
'lamb_'
,
'lamb'
,
'assign_value_'
,
'sparse_momentum_'
,
'sparse_momentum'
,
'full_'
]
inplace_optional_out_type_map
=
{
inplace_optional_out_type_map
=
{
"Tensor"
:
"Tensor"
:
"paddle::optional<paddle::experimental::Tensor>&"
,
"paddle::optional<paddle::experimental::Tensor>&"
,
...
@@ -1126,15 +1112,13 @@ class DygraphForwardFunctionGenerator(DygraphFunctionGeneratorBase):
...
@@ -1126,15 +1112,13 @@ class DygraphForwardFunctionGenerator(DygraphFunctionGeneratorBase):
returns_str
=
f
"
{
returns_type_str
}
{{
{
returns_str
}
}}"
returns_str
=
f
"
{
returns_type_str
}
{{
{
returns_str
}
}}"
# Node Creation Pre-Processing
# Node Creation Pre-Processing
# 1. Get Input AutoGradMeta
if
not
self
.
is_forward_only
:
if
not
self
.
is_forward_only
:
# 1. Get Input AutoGradMeta
inputs_autograd_meta_list
=
[]
inputs_autograd_meta_list
=
[]
compute_require_grad_args_list
=
[
"trace_backward"
]
compute_require_grad_args_list
=
[
"trace_backward"
]
for
name
,
(
ttype
,
pos
)
in
forward_inputs_position_map
.
items
():
for
name
,
(
ttype
,
pos
)
in
forward_inputs_position_map
.
items
():
# Has corresponding grad output
# Has corresponding grad output
has_corresponding_grad_output
=
False
has_corresponding_grad_output
=
False
if
not
self
.
is_forward_only
:
for
_
,
(
_
,
corresponding_pos
,
for
_
,
(
_
,
corresponding_pos
,
_
)
in
backward_grad_outputs_map
.
items
():
_
)
in
backward_grad_outputs_map
.
items
():
if
pos
==
corresponding_pos
:
if
pos
==
corresponding_pos
:
...
@@ -1160,7 +1144,6 @@ class DygraphForwardFunctionGenerator(DygraphFunctionGeneratorBase):
...
@@ -1160,7 +1144,6 @@ class DygraphForwardFunctionGenerator(DygraphFunctionGeneratorBase):
compute_require_grad_args_list
)
compute_require_grad_args_list
)
# 2. Get Output AutoGradMeta
# 2. Get Output AutoGradMeta
if
not
self
.
is_forward_only
:
outputs_autograd_meta_list
=
[]
outputs_autograd_meta_list
=
[]
num_fwd_outputs
=
len
(
forward_outputs_position_map
.
keys
())
num_fwd_outputs
=
len
(
forward_outputs_position_map
.
keys
())
...
@@ -1200,11 +1183,8 @@ class DygraphForwardFunctionGenerator(DygraphFunctionGeneratorBase):
...
@@ -1200,11 +1183,8 @@ class DygraphForwardFunctionGenerator(DygraphFunctionGeneratorBase):
inplace_name
,
inplace_name
)
inplace_name
,
inplace_name
)
# Node Creation
# Node Creation
if
not
self
.
is_forward_only
:
self
.
GenerateNodeCreationCodes
()
self
.
GenerateNodeCreationCodes
()
node_creation_str
=
self
.
node_creation_str
node_creation_str
=
self
.
node_creation_str
else
:
node_creation_str
=
""
dygraph_event_str
=
f
"
{
indent
}
paddle::platform::RecordEvent dygraph_entrance_record_event(
\"
{
forward_api_name
}
dygraph
\"
, paddle::platform::TracerEventType::Operator, 1);
\n
"
dygraph_event_str
=
f
"
{
indent
}
paddle::platform::RecordEvent dygraph_entrance_record_event(
\"
{
forward_api_name
}
dygraph
\"
, paddle::platform::TracerEventType::Operator, 1);
\n
"
forward_function_name
=
GetDygraphForwardFunctionName
(
forward_api_name
)
forward_function_name
=
GetDygraphForwardFunctionName
(
forward_api_name
)
...
@@ -1230,7 +1210,15 @@ class DygraphForwardFunctionGenerator(DygraphFunctionGeneratorBase):
...
@@ -1230,7 +1210,15 @@ class DygraphForwardFunctionGenerator(DygraphFunctionGeneratorBase):
amp_autocast_list_str
,
amp_call_str
)
amp_autocast_list_str
,
amp_call_str
)
# Generate forward_definition_str and forward_declaration_str
# Generate forward_definition_str and forward_declaration_str
if
not
self
.
is_forward_only
:
if
self
.
is_forward_only
:
if
len
(
amp_tensors_vector_list
)
==
0
:
amp_logic_str
=
""
self
.
forward_definition_str
+=
FORWARD_ONLY_FUNCTION_TEMPLATE
.
format
(
returns_type_str
,
forward_function_name
,
inputs_args_definition_str
,
dygraph_event_str
,
amp_logic_str
,
forward_function_name
,
forward_call_str
,
get_outputs_str
,
returns_str
)
else
:
self
.
forward_definition_str
+=
FORWARD_FUNCTION_TEMPLATE
.
format
(
self
.
forward_definition_str
+=
FORWARD_FUNCTION_TEMPLATE
.
format
(
returns_type_str
,
forward_function_name
,
returns_type_str
,
forward_function_name
,
inputs_args_definition_str
,
dygraph_event_str
,
amp_logic_str
,
inputs_args_definition_str
,
dygraph_event_str
,
amp_logic_str
,
...
@@ -1239,20 +1227,6 @@ class DygraphForwardFunctionGenerator(DygraphFunctionGeneratorBase):
...
@@ -1239,20 +1227,6 @@ class DygraphForwardFunctionGenerator(DygraphFunctionGeneratorBase):
outputs_autograd_meta_str
,
compute_require_grad_args_str
,
outputs_autograd_meta_str
,
compute_require_grad_args_str
,
check_inplace_str
,
bump_inplace_version_str
,
node_creation_str
,
check_inplace_str
,
bump_inplace_version_str
,
node_creation_str
,
returns_str
)
returns_str
)
else
:
if
(
len
(
amp_tensors_vector_list
)
>
0
)
and
(
self
.
forward_api_name
not
in
no_amp_list
):
self
.
forward_definition_str
+=
FORWARD_ONLY_FUNCTION_TEMPLATE
.
format
(
returns_type_str
,
forward_function_name
,
inputs_args_definition_str
,
dygraph_event_str
,
amp_logic_str
,
forward_function_name
,
forward_call_str
,
get_outputs_str
,
returns_str
)
else
:
self
.
forward_definition_str
+=
FORWARD_ONLY_FUNCTION_TEMPLATE
.
format
(
returns_type_str
,
forward_function_name
,
inputs_args_definition_str
,
dygraph_event_str
,
" "
,
forward_function_name
,
forward_call_str
,
get_outputs_str
,
returns_str
)
self
.
forward_declaration_str
+=
f
"
{
returns_type_str
}
{
forward_function_name
}
(
{
inputs_args_declaration_str
}
);
\n
"
self
.
forward_declaration_str
+=
f
"
{
returns_type_str
}
{
forward_function_name
}
(
{
inputs_args_declaration_str
}
);
\n
"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录