Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
6ae58936
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看板
提交
6ae58936
编写于
8月 26, 2020
作者:
Y
yangzhenzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test cases
上级
8e04ce04
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
7 deletion
+37
-7
tests/ut/python/parallel/test_loss_scale.py
tests/ut/python/parallel/test_loss_scale.py
+27
-0
tests/ut/python/parallel/test_split_grad_sens.py
tests/ut/python/parallel/test_split_grad_sens.py
+10
-7
未找到文件。
tests/ut/python/parallel/test_loss_scale.py
浏览文件 @
6ae58936
...
...
@@ -164,6 +164,20 @@ class Net(nn.Cell):
out
=
self
.
mean
(
out
,
-
1
)
return
out
class
Net2
(
nn
.
Cell
):
def
__init__
(
self
):
super
(
Net2
,
self
).
__init__
()
self
.
matmul
=
P
.
MatMul
()
self
.
relu
=
P
.
ReLU
()
self
.
matmul_weight
=
Parameter
(
Tensor
(
np
.
ones
([
64
,
64
]),
dtype
=
ms
.
float32
),
name
=
"weight"
)
def
construct
(
self
,
x
,
b
):
out
=
self
.
matmul
(
x
,
self
.
matmul_weight
)
out
=
self
.
relu
(
out
)
return
out
def
test_loss_scale
():
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
)
context
.
set_auto_parallel_context
(
parallel_mode
=
ParallelMode
.
SEMI_AUTO_PARALLEL
,
device_num
=
8
)
...
...
@@ -175,3 +189,16 @@ def test_loss_scale():
net
=
TrainOneStepWithLossScaleCell
(
net
,
opt
,
update_cell
)
model
=
Model
(
network
=
net
)
model
.
train
(
2
,
dataset
,
dataset_sink_mode
=
False
)
def
test_loss_scale2
():
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
save_graphs
=
True
)
context
.
set_auto_parallel_context
(
parallel_mode
=
ParallelMode
.
SEMI_AUTO_PARALLEL
,
device_num
=
8
)
predict
=
Tensor
(
np
.
ones
([
64
,
64
]),
dtype
=
ms
.
float32
)
label
=
Tensor
(
np
.
ones
([
64
,]),
dtype
=
ms
.
int32
)
dataset
=
DatasetLenet
(
predict
,
label
)
net
=
Net2
()
opt
=
Momentum
(
filter
(
lambda
x
:
x
.
requires_grad
,
net
.
get_parameters
()),
0.01
,
0.9
)
net
=
nn
.
TrainOneStepWithLossScaleCell
(
net
,
opt
,
update_cell
)
model
=
Model
(
network
=
net
)
model
.
train
(
2
,
dataset
,
dataset_sink_mode
=
False
)
tests/ut/python/parallel/test_split_grad_sens.py
浏览文件 @
6ae58936
...
...
@@ -109,11 +109,9 @@ def test_grad_sens_parameter_type():
out
=
self
.
matmul2
(
out
,
b
)
return
out
context
.
set_auto_parallel_context
(
device_num
=
8
,
global_rank
=
0
)
context
.
set_auto_parallel_context
(
parallel_mode
=
"semi_auto_parallel"
)
strategy1
=
((
4
,
2
),
(
2
,
1
))
strategy2
=
((
2
,
4
),
(
4
,
1
))
context
.
set_auto_parallel_context
(
parallel_mode
=
"semi_auto_parallel"
,
device_num
=
64
,
global_rank
=
0
)
strategy1
=
((
8
,
1
),
(
1
,
8
))
strategy2
=
((
8
,
8
),
(
8
,
1
))
net
=
GradWrap
(
Net
(
strategy1
,
strategy2
))
x
=
Tensor
(
np
.
ones
([
128
,
32
]),
dtype
=
ms
.
float32
)
...
...
@@ -121,9 +119,14 @@ def test_grad_sens_parameter_type():
b
=
Tensor
(
np
.
ones
([
64
,
64
]),
dtype
=
ms
.
float32
)
sens
=
Tensor
(
np
.
ones
([
128
,
64
]),
dtype
=
ms
.
float32
)
# net(x, y, b, sens)
net
.
set_auto_parallel
()
_executor
.
compile
(
net
,
x
,
y
,
b
,
sens
)
_executor
.
compile
(
net
,
x
,
y
,
b
,
sens
,
phase
=
'train'
,
auto_parallel_mode
=
True
)
x_layout
=
[[
8
,
8
],
[
1
,
-
1
],
[
16
,
32
],
[
0
],
[
1
]]
y_layout
=
[[
8
,
8
],
[
-
1
,
0
],
[
32
,
8
],
[
0
],
[
1
]]
b_layout
=
[[
8
,
8
],
[
0
,
-
1
],
[
8
,
64
],
[
0
],
[
1
]]
sens_layout
=
[[
8
,
8
],
[
1
,
-
1
],
[
16
,
64
],
[
0
],
[
1
]]
expect_dict
=
{
'x'
:
x_layout
,
'y'
:
y_layout
,
'b'
:
b_layout
,
'sens'
:
sens_layout
}
assert
net
.
parameter_layout_dict
==
expect_dict
def
test_grad_sens_tensor_type
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录