Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
0c037d2d
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
0c037d2d
编写于
4月 15, 2021
作者:
F
fangshuixun007
提交者:
GitHub
4月 15, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix test sync_with_cpp (#32212)
fix test sync_with_cpp (#32212)
上级
e6bc358d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
22 addition
and
15 deletion
+22
-15
python/paddle/fluid/contrib/mixed_precision/fp16_utils.py
python/paddle/fluid/contrib/mixed_precision/fp16_utils.py
+15
-5
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+1
-4
python/paddle/fluid/optimizer.py
python/paddle/fluid/optimizer.py
+6
-6
未找到文件。
python/paddle/fluid/contrib/mixed_precision/fp16_utils.py
浏览文件 @
0c037d2d
...
...
@@ -116,7 +116,7 @@ def _insert_cast_op(block, op, idx, src_dtype, dest_dtype):
persistable
=
False
,
stop_gradient
=
in_var
.
stop_gradient
)
block
.
_insert_op
(
block
.
_insert_op
_without_sync
(
idx
,
type
=
"cast"
,
inputs
=
{
"X"
:
in_var
},
...
...
@@ -490,6 +490,7 @@ def rewrite_program(main_prog, amp_lists):
main_prog (Program): The main program for training.
"""
block
=
main_prog
.
global_block
()
block
.
_sync_with_cpp
()
ops
=
block
.
ops
white_op_set
=
set
()
black_op_set
=
set
()
...
...
@@ -578,6 +579,7 @@ def update_role_var_grad(main_prog, params_grads):
params_grads (list): A list of params and grads.
"""
block
=
main_prog
.
global_block
()
block
.
_sync_with_cpp
()
BACKWARD
=
core
.
op_proto_and_checker_maker
.
OpRole
.
Backward
OPTIMIZE
=
core
.
op_proto_and_checker_maker
.
OpRole
.
Optimize
for
p
,
g
in
params_grads
:
...
...
@@ -585,7 +587,7 @@ def update_role_var_grad(main_prog, params_grads):
if
g
.
dtype
==
core
.
VarDesc
.
VarType
.
FP32
and
op
.
type
==
'cast'
:
role
=
op
.
attr
(
'op_role'
)
if
role
&
int
(
BACKWARD
)
and
op
.
has_attr
(
'op_role_var'
):
op
.
desc
.
remove_attr
(
"op_role_var"
)
op
.
_
remove_attr
(
"op_role_var"
)
else
:
raise
ValueError
(
"The cast op {0} must be in BACKWARD role "
"and have op_role_var attr."
.
format
(
op
))
...
...
@@ -610,11 +612,19 @@ def update_role_var_grad(main_prog, params_grads):
raise
ValueError
(
"The cast op {0}'s output should not be"
"used by a non-optimize op, however, it"
"is used by {1}"
.
format
(
op
,
post_ops
[
0
]))
#add new op in the python and cpp at the same time
new_op_desc
=
block
.
desc
.
append_op
()
new_op_desc
.
copy_from
(
op
.
desc
)
new_op
=
framework
.
Operator
(
block
=
block
,
desc
=
new_op_desc
,
type
=
None
,
inputs
=
None
,
outputs
=
None
,
attrs
=
None
)
block
.
ops
.
append
(
new_op
)
op_idx
=
find_op_index
(
block
.
desc
,
op
.
desc
)
if
op_idx
==
-
1
:
raise
ValueError
(
"The op {0} is not in program"
.
format
(
op
))
block
.
desc
.
_remove_op
(
op_idx
,
op_idx
+
1
)
block
.
_sync_with_cpp
()
block
.
_remove_op
(
op_idx
,
sync
=
False
)
block
.
_sync_with_cpp
()
python/paddle/fluid/framework.py
浏览文件 @
0c037d2d
...
...
@@ -3239,10 +3239,7 @@ class Block(object):
Operator: the insert Operator.
"""
self
.
_sync_with_cpp
()
op_desc
=
self
.
desc
.
_insert_op
(
index
)
op
=
Operator
(
block
=
self
,
desc
=
op_desc
,
*
args
,
**
kwargs
)
self
.
ops
.
insert
(
index
,
op
)
return
op
return
self
.
_insert_op_without_sync
(
index
,
*
args
,
**
kwargs
)
def
_insert_op_without_sync
(
self
,
index
,
*
args
,
**
kwargs
):
"""
...
...
python/paddle/fluid/optimizer.py
浏览文件 @
0c037d2d
...
...
@@ -4352,7 +4352,7 @@ class PipelineOptimizer(object):
ring_id
=
self
.
_pp_ring_map
[
pair_key
]
if
self
.
schedule_mode
==
'F-then-B'
:
# F-then-B
block
.
_insert_op
(
block
.
_insert_op
_without_sync
(
index
=
index
+
extra_index_info
[
'index'
],
type
=
'send_v2'
,
inputs
=
{
'X'
:
var
},
...
...
@@ -4364,7 +4364,7 @@ class PipelineOptimizer(object):
'ring_id'
:
ring_id
})
extra_index_info
[
'index'
]
+=
1
block
.
_insert_op
(
block
.
_insert_op
_without_sync
(
index
=
index
+
extra_index_info
[
'index'
],
type
=
'recv_v2'
,
outputs
=
{
'Out'
:
[
var
]},
...
...
@@ -4379,7 +4379,7 @@ class PipelineOptimizer(object):
})
extra_index_info
[
'index'
]
+=
1
elif
self
.
schedule_mode
==
'1F1B'
:
# 1F1B
block
.
_insert_op
(
block
.
_insert_op
_without_sync
(
index
=
index
+
extra_index_info
[
'index'
],
type
=
'c_sync_calc_stream'
,
inputs
=
{
'X'
:
[
var
]},
...
...
@@ -4389,7 +4389,7 @@ class PipelineOptimizer(object):
self
.
_op_role_key
:
op_role
,
})
extra_index_info
[
'index'
]
+=
1
block
.
_insert_op
(
block
.
_insert_op
_without_sync
(
index
=
index
+
extra_index_info
[
'index'
],
type
=
'send_v2'
,
inputs
=
{
'X'
:
var
},
...
...
@@ -4409,7 +4409,7 @@ class PipelineOptimizer(object):
else
:
insert_index
=
index
new_op_role
=
self
.
_op_role
.
Backward
block
.
_insert_op
(
block
.
_insert_op
_without_sync
(
index
=
insert_index
+
extra_index_info
[
'index'
],
type
=
'c_sync_comm_stream'
,
inputs
=
{
'X'
:
[
var
]},
...
...
@@ -4424,7 +4424,7 @@ class PipelineOptimizer(object):
var_shape
=
list
(
var
.
shape
)
var_shape
[
0
]
=
self
.
micro_batch_size
if
var_shape
[
0
]
<
0
else
var_shape
[
0
]
block
.
_insert_op
(
block
.
_insert_op
_without_sync
(
index
=
index
+
extra_index_info
[
'index'
],
type
=
'recv_v2'
,
outputs
=
{
'Out'
:
[
var
]},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录