Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
d2404da7
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看板
未验证
提交
d2404da7
编写于
1月 21, 2021
作者:
V
Void Main
提交者:
GitHub
1月 21, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Build praser for Hcom* operators (#30627)
Build praser for Hcom* operators
上级
f9c97dd7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
155 addition
and
3 deletion
+155
-3
python/paddle/distributed/fleet/meta_optimizers/ascend/ascend_optimizer.py
...tributed/fleet/meta_optimizers/ascend/ascend_optimizer.py
+7
-1
python/paddle/distributed/fleet/meta_optimizers/ascend/ascend_parser.py
...distributed/fleet/meta_optimizers/ascend/ascend_parser.py
+137
-1
python/paddle/fluid/transpiler/ascend_transpiler.py
python/paddle/fluid/transpiler/ascend_transpiler.py
+11
-1
未找到文件。
python/paddle/distributed/fleet/meta_optimizers/ascend/ascend_optimizer.py
浏览文件 @
d2404da7
...
...
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
os
import
paddle.fluid.framework
as
framework
from
paddle.fluid.optimizer
import
Optimizer
import
paddle.fluid.core
as
core
...
...
@@ -151,7 +152,12 @@ class AscendOptimizer(Optimizer):
config
=
{
"ge.exec.deviceId"
:
str
(
fleet
.
rank_in_node
()),
"ge.graphRunMode"
:
"1"
,
"ge.exec.precision_mode"
:
"must_keep_origin_dtype"
"ge.exec.precision_mode"
:
"must_keep_origin_dtype"
,
# if multi mode
"ge.exec.rankTableFile"
:
os
.
getenv
(
"RANK_TABLE_FILE"
),
"ge.exec.rankId"
:
str
(
fleet
.
worker_index
()),
"ge.exec.isUseHcom"
:
"1"
,
"ge.exec.deployMode"
:
"0"
,
}
print
(
"ge_initialize config:"
,
config
)
core
.
ge_initialize
(
config
)
...
...
python/paddle/distributed/fleet/meta_optimizers/ascend/ascend_parser.py
浏览文件 @
d2404da7
...
...
@@ -34,7 +34,14 @@ registerd_op = {
"relu_grad"
:
"ReluGradParser"
,
"softmax_with_cross_entropy_grad"
:
"SoftmaxWithCrossEntropyGradParser"
,
"truncated_gaussian_random"
:
"TruncatedNormalParser"
,
"sgd"
:
"SGDParser"
"sgd"
:
"SGDParser"
,
"c_allgather"
:
"AllGatherParser"
,
"c_allreduce_sum"
:
"AllReduceSumParser"
,
"c_allreduce_max"
:
"AllReduceMaxParser"
,
"c_broadcast"
:
"BroadcastParser"
,
"c_reduce_scatter"
:
"ReduceScatterParser"
,
"c_send"
:
"SendParser"
,
"c_receive"
:
"ReceiveParser"
}
global_cnt
=
-
1
global_input_cnt
=
-
1
...
...
@@ -522,6 +529,135 @@ class TruncatedNormalParser(AscendParserBase):
)
return
[
truncated_normal
],
[[
0
]]
#[assign]
class
AllGatherParser
(
AscendParserBase
):
def
__init__
(
self
,
graph
,
var2geop
):
super
(
AllGatherParser
,
self
).
__init__
(
graph
,
var2geop
)
self
.
parser_name
=
"c_allgather"
def
_apply
(
self
):
x
=
self
.
_get_ge_input
(
self
.
op
.
input_arg_names
[
0
])
rank_size
=
self
.
op
.
attr
(
"rank_size"
)
group
=
self
.
op
.
attr
(
"group"
)
allgather
=
core
.
GEOperatorFactory
.
create_operator
(
"allgather"
+
self
.
_accumulated_op_id
(),
"HcomAllGather"
).
set_input
(
"x"
,
x
).
set_attr_int32
(
"rank_size"
,
rank_size
).
set_attr_string
(
"group"
,
group
)
return
[
allgather
],
[[
0
]]
class
AllReduceParser
(
AscendParserBase
):
def
__init__
(
self
,
graph
,
var2geop
,
reduction
):
super
(
AllReduceParser
,
self
).
__init__
(
graph
,
var2geop
)
self
.
parser_name
=
"c_allreduce_"
+
reduction
self
.
reduction
=
reduction
def
_apply
(
self
):
x
=
self
.
_get_ge_input
(
self
.
op
.
input_arg_names
[
0
])
reduction
=
self
.
reduction
group
=
"hccl_world_group"
#self.op.attr("group")
fusion
=
None
#self.op.attr("fusion")
fusion_id
=
None
#self.op.attr("fusion_id")
allreduce
=
core
.
GEOperatorFactory
.
create_operator
(
"allreduce"
+
self
.
_accumulated_op_id
(),
"HcomAllReduce"
).
set_input
(
"x"
,
x
).
set_attr_string
(
"reduction"
,
reduction
).
set_attr_string
(
"group"
,
group
)
if
fusion
is
not
None
:
allreduce
.
set_attr_int32
(
"fusion"
,
fusion
)
if
fusion_id
is
not
None
:
allreduce
.
set_attr_int32
(
"fusion_id"
,
fusion_id
)
return
[
allreduce
],
[[
0
]]
class
AllReduceSumParser
(
AllReduceParser
):
def
__init__
(
self
,
graph
,
var2geop
):
super
(
AllReduceSumParser
,
self
).
__init__
(
graph
,
var2geop
,
'sum'
)
class
AllReduceMaxParser
(
AllReduceParser
):
def
__init__
(
self
,
graph
,
var2geop
):
super
(
AllReduceMaxParser
,
self
).
__init__
(
graph
,
var2geop
,
'max'
)
class
BroadcastParser
(
AscendParserBase
):
def
__init__
(
self
,
graph
,
var2geop
):
super
(
BroadcastParser
,
self
).
__init__
(
graph
,
var2geop
)
self
.
parser_name
=
"c_broadcast"
def
_apply
(
self
):
x
=
self
.
_get_ge_input
(
self
.
op
.
input_arg_names
[
0
])
root_rank
=
self
.
op
.
attr
(
"root_rank"
)
group
=
self
.
op
.
attr
(
"group"
)
broadcast
=
core
.
GEOperatorFactory
.
create_operator
(
"broadcast"
+
self
.
_accumulated_op_id
(),
"HcomBroadcast"
).
set_input
(
"x"
,
x
).
set_attr_int32
(
"root_rank"
,
root_rank
).
set_attr_string
(
"group"
,
group
)
return
[
broadcast
],
[[
0
]]
class
ReduceScatterParser
(
AscendParserBase
):
def
__init__
(
self
,
graph
,
var2geop
):
super
(
ReduceScatterParser
,
self
).
__init__
(
graph
,
var2geop
)
self
.
parser_name
=
"c_reduce_scatter"
def
_apply
(
self
):
x
=
self
.
_get_ge_input
(
self
.
op
.
input_arg_names
[
0
])
reduction
=
self
.
op
.
attr
(
"reduction"
)
group
=
self
.
op
.
attr
(
"group"
)
rank_size
=
self
.
op
.
attr
(
"rank_size"
)
reduce_scatter
=
core
.
GEOperatorFactory
.
create_operator
(
"reducescatter"
+
self
.
_accumulated_op_id
(),
"HcomReduceScatter"
).
set_input
(
"x"
,
x
).
set_attr_string
(
"reduction"
,
reduction
).
set_attr_string
(
"group"
,
group
).
set_attr_int32
(
"rank_size"
,
rank_size
)
return
[
reduce_scatter
],
[[
0
]]
class
SendParser
(
AscendParserBase
):
def
__init__
(
self
,
graph
,
var2geop
):
super
(
SendParser
,
self
).
__init__
(
graph
,
var2geop
)
self
.
parser_name
=
"c_send"
def
_apply
(
self
):
x
=
self
.
_get_ge_input
(
self
.
op
.
input_arg_names
[
0
])
sr_tag
=
self
.
op
.
attr
(
"sr_tag"
)
dest_rank
=
self
.
op
.
attr
(
"dest_rank"
)
group
=
self
.
op
.
attr
(
"group"
)
send
=
core
.
GEOperatorFactory
.
create_operator
(
"send"
+
self
.
_accumulated_op_id
(),
"HcomSend"
).
set_input
(
"x"
,
x
).
set_attr_int32
(
"sr_tag"
,
sr_tag
).
set_attr_int32
(
"dest_rank"
,
dest_rank
).
set_attr_string
(
"group"
,
group
)
return
[
send
],
[[
0
]]
class
ReceiveParser
(
AscendParserBase
):
def
__init__
(
self
,
graph
,
var2geop
):
super
(
ReceiveParser
,
self
).
__init__
(
graph
,
var2geop
)
self
.
parser_name
=
"c_receive"
def
_apply
(
self
):
x
=
self
.
_get_ge_input
(
self
.
op
.
input_arg_names
[
0
])
sr_tag
=
self
.
op
.
attr
(
"sr_tag"
)
src_rank
=
self
.
op
.
attr
(
"src_rank"
)
group
=
self
.
op
.
attr
(
"group"
)
shape
=
self
.
op
.
attr
(
"shape"
)
dtype
=
self
.
op
.
attr
(
"dtype"
)
receive
=
core
.
GEOperatorFactory
.
create_operator
(
"receive"
+
self
.
_accumulated_op_id
(),
"HcomReceive"
).
set_input
(
"x"
,
x
).
set_attr_int32
(
"sr_tag"
,
sr_tag
).
set_attr_int32
(
"src_rank"
,
src_rank
).
set_attr_string
(
"group"
,
group
).
set_attr_vec_int32
(
"shape"
,
shape
).
set_attr_int32
(
"dtype"
,
dtype
)
return
[
receive
],
[[
0
]]
class
ScaleParser
(
AscendParserBase
):
def
__init__
(
self
,
graph
,
var2geop
):
super
(
ScaleParser
,
self
).
__init__
(
graph
,
var2geop
)
...
...
python/paddle/fluid/transpiler/ascend_transpiler.py
浏览文件 @
d2404da7
...
...
@@ -15,6 +15,7 @@
from
.
import
collective
from
..
import
core
OpRole
=
core
.
op_proto_and_checker_maker
.
OpRole
from
paddle.distributed
import
fleet
class
AscendTranspiler
(
collective
.
Collective
):
def
__init__
(
self
,
startup_program
,
main_program
):
...
...
@@ -49,13 +50,22 @@ class AscendTranspiler(collective.Collective):
ring_id
=
(
ring_id
+
1
)
%
self
.
nrings
block
.
_insert_op
(
offset
+
1
,
type
=
'
allreduce
'
,
type
=
'
c_allreduce_sum
'
,
inputs
=
{
'X'
:
grad
},
outputs
=
{
'Out'
:
grad
},
attrs
=
{
'ring_id'
:
ring_id
,
self
.
op_role_key
:
OpRole
.
Backward
})
block
.
_insert_op
(
offset
+
2
,
type
=
'scale'
,
inputs
=
{
'X'
:
grad
},
outputs
=
{
'Out'
:
grad
},
attrs
=
{
'scale'
:
1.0
/
fleet
.
worker_num
(),
self
.
op_role_key
:
OpRole
.
Backward
})
if
grad
is
None
:
return
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录