Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
5e041966
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看板
提交
5e041966
编写于
5月 08, 2020
作者:
X
Xiaoda Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add a new vritualdataset cell for three inputs
上级
e6273ce3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
57 addition
and
2 deletion
+57
-2
mindspore/nn/wrap/__init__.py
mindspore/nn/wrap/__init__.py
+3
-2
mindspore/nn/wrap/cell_wrapper.py
mindspore/nn/wrap/cell_wrapper.py
+30
-0
tests/ut/python/parallel/test_virtual_dataset_3_input.py
tests/ut/python/parallel/test_virtual_dataset_3_input.py
+24
-0
未找到文件。
mindspore/nn/wrap/__init__.py
浏览文件 @
5e041966
...
...
@@ -18,7 +18,7 @@ Wrap cells for networks.
Use the Wrapper to combine the loss or build the training steps.
"""
from
.cell_wrapper
import
TrainOneStepCell
,
WithLossCell
,
WithGradCell
,
WithEvalCell
,
DataWrapper
,
\
ParameterUpdate
,
GetNextSingleOp
ParameterUpdate
,
GetNextSingleOp
,
VirtualDatasetCellTriple
from
.loss_scale
import
TrainOneStepWithLossScaleCell
,
DynamicLossScaleUpdateCell
,
FixedLossScaleUpdateCell
from
.grad_reducer
import
DistributedGradReducer
...
...
@@ -33,5 +33,6 @@ __all__ = [
"DistributedGradReducer"
,
"ParameterUpdate"
,
"DynamicLossScaleUpdateCell"
,
"FixedLossScaleUpdateCell"
"FixedLossScaleUpdateCell"
,
"VirtualDatasetCellTriple"
]
mindspore/nn/wrap/cell_wrapper.py
浏览文件 @
5e041966
...
...
@@ -278,6 +278,36 @@ class _VirtualDatasetCell(Cell):
return
self
.
_backbone
(
data_
,
label_
)
class
VirtualDatasetCellTriple
(
Cell
):
"""
Wrap the network with virtual dataset to convert data parallel layout to model parallel layout.
VirtualDatasetCellTriple is a virtual Primitive, it does not exist in the final executing graph. Inputs and outputs
of VirtualDatasetCellTriple are distributed in data parallel pattern, tensor redistribution Primitives is inserted
dynamically during the graph compile process.
Note:
Only used in semi auto parallel and auto parallel mode. There are three inputs, as contrary to two inputs in
_VirtualDatasetCell.
Args:
backbone (Cell): The target network to wrap.
Examples:
>>> net = Net()
>>> net = VirtualDatasetCellTriple(net)
"""
def
__init__
(
self
,
backbone
):
super
(
VirtualDatasetCellTriple
,
self
).
__init__
(
auto_prefix
=
False
)
self
.
_backbone
=
backbone
self
.
_virtual_dataset
=
_VirtualDataset
()
def
construct
(
self
,
a
,
b
,
c
):
a_
,
b_
,
c_
=
self
.
_virtual_dataset
(
a
,
b
,
c
)
return
self
.
_backbone
(
a_
,
b_
,
c_
)
class
WithEvalCell
(
Cell
):
r
"""
Cell that returns loss, output and label for evaluation.
...
...
tests/ut/python/parallel/test_virtual_dataset_3_input.py
浏览文件 @
5e041966
...
...
@@ -21,6 +21,7 @@ import mindspore as ms
from
mindspore.common.api
import
_executor
from
mindspore.ops
import
composite
as
C
from
mindspore.ops.operations.comm_ops
import
_VirtualDataset
from
mindspore.nn.wrap.cell_wrapper
import
VirtualDatasetCellTriple
from
mindspore
import
context
...
...
@@ -73,6 +74,29 @@ def test_virtual_dataset_3_input():
net
.
set_auto_parallel
()
_executor
.
compile
(
net
,
x
,
y
,
b
)
def
test_virtualdataset_cell_3_inputs
():
class
Net
(
nn
.
Cell
):
def
__init__
(
self
,
strategy0
,
strategy1
,
strategy2
,
strategy3
):
super
().
__init__
()
self
.
matmul1
=
P
.
MatMul
().
set_strategy
(
strategy1
)
self
.
matmul2
=
P
.
MatMul
().
set_strategy
(
strategy2
)
self
.
gelu
=
P
.
Gelu
().
set_strategy
(
strategy3
)
def
construct
(
self
,
x
,
y
,
b
):
out
=
self
.
gelu
(
self
.
matmul1
(
x
,
y
))
out
=
self
.
matmul2
(
out
,
b
)
return
out
net
=
GradWrap
(
VirtualDatasetCellTriple
(
NetWithLoss
(
Net
(
None
,
None
,
None
,
None
))))
context
.
set_context
(
save_graphs
=
True
)
context
.
set_auto_parallel_context
(
parallel_mode
=
"auto_parallel"
)
context
.
set_auto_parallel_context
(
device_num
=
8
,
global_rank
=
0
)
x
=
Tensor
(
np
.
ones
([
128
,
32
]),
dtype
=
ms
.
float32
)
y
=
Tensor
(
np
.
ones
([
32
,
64
]),
dtype
=
ms
.
float32
)
b
=
Tensor
(
np
.
ones
([
64
,
2048
]),
dtype
=
ms
.
float32
)
net
.
set_auto_parallel
()
_executor
.
compile
(
net
,
x
,
y
,
b
)
if
__name__
==
'__main__'
:
test_virtual_dataset_3_input
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录