Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
d5634eb4
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d5634eb4
编写于
5月 29, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
5月 29, 2020
浏览文件
操作
浏览文件
下载
差异文件
!1510 seperate auto_parallel and stand_alone when init initializer data
Merge pull request !1510 from yihuaijie/dev
上级
8316f736
d36af3d8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
20 deletion
+36
-20
mindspore/common/api.py
mindspore/common/api.py
+11
-8
mindspore/common/parameter.py
mindspore/common/parameter.py
+14
-6
mindspore/nn/cell.py
mindspore/nn/cell.py
+11
-6
未找到文件。
mindspore/common/api.py
浏览文件 @
d5634eb4
...
...
@@ -327,16 +327,19 @@ class _Executor:
raise
TypeError
(
'Parameters need OrderedDict type, but got {}'
.
format
(
type
(
params
)))
def
_params_init_data
(
self
,
obj
,
params
):
def
_params_init_data
(
self
,
obj
,
params
,
auto_parallel_mode
=
False
):
"""Init parameters' data."""
if
params
is
not
None
:
for
key
,
param
in
params
.
items
():
if
key
not
in
obj
.
parameter_layout_dict
:
logger
.
info
(
"Layout dict does not contain the key %s."
,
key
)
if
not
auto_parallel_mode
:
param
.
init_data
()
elif
key
not
in
obj
.
parameter_layout_dict
:
logger
.
info
(
"Layout dict does not contain the key %s."
,
key
)
param
.
init_data
(
set_sliced
=
True
)
else
:
layout
=
obj
.
parameter_layout_dict
[
key
]
param
.
init_data
(
layout
)
obj
.
init_parameters_data
()
param
.
init_data
(
layout
,
set_sliced
=
True
)
obj
.
init_parameters_data
(
auto_parallel_mode
=
auto_parallel_mode
)
def
compile
(
self
,
obj
,
*
args
,
phase
=
'predict'
,
params
=
None
,
do_convert
=
True
,
auto_parallel_mode
=
False
):
"""
...
...
@@ -383,11 +386,11 @@ class _Executor:
if
not
do_convert
:
return
phase
,
True
if
auto_parallel_mode
and
"train"
in
phase
:
if
auto_parallel_mode
:
obj
.
parameter_layout_dict
=
self
.
_executor
.
get_parameter_layout
(
phase
)
self
.
_params_init_data
(
obj
,
params
)
self
.
_params_init_data
(
obj
,
params
,
auto_parallel_mode
)
if
not
enable_debug_runtime
or
enable_ge
:
if
auto_parallel_mode
and
"train"
in
phase
:
if
auto_parallel_mode
:
obj
.
load_parameter_slice
(
params
)
# set parallel inputs in sink mode
...
...
mindspore/common/parameter.py
浏览文件 @
d5634eb4
...
...
@@ -99,6 +99,10 @@ class Parameter:
"""Get slice status of the parameter."""
return
self
.
_sliced
@
sliced
.
setter
def
sliced
(
self
,
sliced_
):
self
.
_sliced
=
sliced_
@
property
def
is_init
(
self
):
"""Get init status of the parameter."""
...
...
@@ -211,15 +215,18 @@ class Parameter:
self
.
default_input
=
data
def
init_data
(
self
,
layout
=
None
):
def
init_data
(
self
,
layout
=
None
,
set_sliced
=
False
):
"""
Init data of the parameter.
Args:
layout (list[list[int]]): parameter slice layout [dev_mat, tensor_map, slice_shape].
dev_mat (list[int]): device matrix.
tensor_map (list[int]): tensor map.
slice_shape (list[int]): shape of slice.
layout (list[list[int]]): Parameter slice layout [dev_mat, tensor_map, slice_shape].
- dev_mat (list[int]): Device matrix.
- tensor_map (list[int]): Tensor map.
- slice_shape (list[int]): Shape of slice.
set_sliced (bool): True if should set parameter sliced after init the data of initializer.
Default: False.
"""
if
not
isinstance
(
self
.
default_input
,
MetaTensor
):
return
...
...
@@ -235,7 +242,8 @@ class Parameter:
self
.
default_input
=
self
.
init_mode
.
to_tensor
()
self
.
init_mode
=
None
self
.
_sliced
=
True
if
set_sliced
:
self
.
sliced
=
True
class
ParameterTuple
(
tuple
):
...
...
mindspore/nn/cell.py
浏览文件 @
d5634eb4
...
...
@@ -264,11 +264,12 @@ class Cell:
logger
.
info
(
"layout dict does not contain the key %s"
,
key
)
continue
if
self
.
parameters_dict
()[
key
].
sliced
:
logger
.
info
(
"Param %s is
from initializer,
already sliced."
,
key
)
logger
.
info
(
"Param %s is already sliced."
,
key
)
continue
layout
=
self
.
parameter_layout_dict
[
key
]
new_tensor
=
_load_tensor_by_layout
(
tensor
,
layout
)
self
.
parameters_dict
()[
key
].
set_parameter_data
(
new_tensor
)
self
.
parameters_dict
()[
key
].
sliced
=
True
elif
isinstance
(
params
,
OrderedDict
):
for
key
in
params
:
tensor
=
params
[
key
].
data
...
...
@@ -276,11 +277,12 @@ class Cell:
logger
.
info
(
"layout dict does not contain the key %s"
,
key
)
continue
if
params
[
key
].
sliced
:
logger
.
info
(
"Param %s is
from initializer,
already sliced."
,
key
)
logger
.
info
(
"Param %s is already sliced."
,
key
)
continue
layout
=
self
.
parameter_layout_dict
[
key
]
new_tensor
=
_load_tensor_by_layout
(
tensor
,
layout
)
params
[
key
].
set_parameter_data
(
new_tensor
)
params
[
key
].
sliced
=
True
else
:
raise
TypeError
(
'Parameters need OrderedDict type, but got {}'
.
format
(
type
(
params
)))
...
...
@@ -435,14 +437,17 @@ class Cell:
"""
raise
NotImplementedError
def
init_parameters_data
(
self
,
recurse
=
True
):
def
init_parameters_data
(
self
,
recurse
=
True
,
auto_parallel_mode
=
False
):
"""Init parameters' data."""
for
param
in
self
.
get_parameters
(
expand
=
recurse
):
if
param
.
name
not
in
self
.
parameter_layout_dict
:
logger
.
info
(
"Layout dict does not contain the key %s."
,
param
.
name
)
if
not
auto_parallel_mode
:
param
.
init_data
()
elif
param
.
name
not
in
self
.
parameter_layout_dict
:
logger
.
info
(
"Layout dict does not contain the key %s."
,
param
.
name
)
param
.
init_data
(
set_sliced
=
True
)
else
:
layout
=
self
.
parameter_layout_dict
[
param
.
name
]
param
.
init_data
(
layout
)
param
.
init_data
(
layout
,
set_sliced
=
True
)
def
parameters_dict
(
self
,
recurse
=
True
):
"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录