Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
d85d2f5a
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看板
提交
d85d2f5a
编写于
4月 28, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
4月 28, 2020
浏览文件
操作
浏览文件
下载
差异文件
!818 fix launch bug
Merge pull request !818 from wandongdong/master
上级
66cacb32
20c79c3f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
24 deletion
+18
-24
example/mobilenetv2_imagenet2012/launch.py
example/mobilenetv2_imagenet2012/launch.py
+12
-19
example/mobilenetv2_imagenet2012/train.py
example/mobilenetv2_imagenet2012/train.py
+6
-5
未找到文件。
example/mobilenetv2_imagenet2012/launch.py
浏览文件 @
d85d2f5a
...
@@ -15,7 +15,6 @@
...
@@ -15,7 +15,6 @@
"""launch train script"""
"""launch train script"""
import
os
import
os
import
sys
import
sys
import
subprocess
import
json
import
json
from
argparse
import
ArgumentParser
from
argparse
import
ArgumentParser
...
@@ -125,25 +124,19 @@ def main():
...
@@ -125,25 +124,19 @@ def main():
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
# spawn the processes
# spawn the processes
current_env
=
os
.
environ
.
copy
()
current_env
[
"RANK_SIZE"
]
=
str
(
args
.
nproc_per_node
)
if
args
.
nproc_per_node
>
1
:
current_env
[
"MINDSPORE_HCCL_CONFIG_PATH"
]
=
table_fn
processes
=
[]
cmds
=
[]
for
rank_id
in
range
(
0
,
args
.
nproc_per_node
):
for
rank_id
in
range
(
0
,
args
.
nproc_per_node
):
current_env
[
"RANK_ID"
]
=
str
(
rank_id
)
device_id
=
visible_devices
[
rank_id
]
current_env
[
"DEVICE_ID"
]
=
visible_devices
[
rank_id
]
device_dir
=
os
.
path
.
join
(
os
.
getcwd
(),
'device{}'
.
format
(
rank_id
))
cmd
=
[
sys
.
executable
,
"-u"
]
rank_process
=
'export RANK_SIZE={} && export RANK_ID={} && export DEVICE_ID={} && '
.
format
(
args
.
nproc_per_node
,
cmd
.
append
(
args
.
training_script
)
rank_id
,
device_id
)
cmd
.
extend
(
args
.
training_script_args
)
if
args
.
nproc_per_node
>
1
:
process
=
subprocess
.
Popen
(
cmd
,
env
=
current_env
)
rank_process
+=
'export MINDSPORE_HCCL_CONFIG_PATH={} && '
.
format
(
table_fn
)
processes
.
append
(
process
)
rank_process
+=
'export RANK_TABLE_FILE={} && '
.
format
(
table_fn
)
cmds
.
append
(
cmd
)
rank_process
+=
'rm -rf {dir} && mkdir {dir} && cd {dir} && python {script} '
.
format
(
dir
=
device_dir
,
for
process
,
cmd
in
zip
(
processes
,
cmds
):
script
=
args
.
training_script
process
.
wait
(
)
)
if
process
.
returncode
!=
0
:
rank_process
+=
' '
.
join
(
args
.
training_script_args
)
+
' > log{}.log 2>&1 &'
.
format
(
rank_id
)
raise
subprocess
.
CalledProcessError
(
returncode
=
process
.
returncode
,
cmd
=
cmd
)
os
.
system
(
rank_process
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
example/mobilenetv2_imagenet2012/train.py
浏览文件 @
d85d2f5a
...
@@ -23,6 +23,7 @@ from lr_generator import get_lr
...
@@ -23,6 +23,7 @@ from lr_generator import get_lr
from
config
import
config
from
config
import
config
from
mindspore
import
context
from
mindspore
import
context
from
mindspore
import
Tensor
from
mindspore
import
Tensor
from
mindspore
import
nn
from
mindspore.model_zoo.mobilenet
import
mobilenet_v2
from
mindspore.model_zoo.mobilenet
import
mobilenet_v2
from
mindspore.parallel._auto_parallel_context
import
auto_parallel_context
from
mindspore.parallel._auto_parallel_context
import
auto_parallel_context
from
mindspore.nn.optim.momentum
import
Momentum
from
mindspore.nn.optim.momentum
import
Momentum
...
@@ -110,16 +111,17 @@ class Monitor(Callback):
...
@@ -110,16 +111,17 @@ class Monitor(Callback):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
if
run_distribute
:
if
run_distribute
:
context
.
set_context
(
enable_hccl
=
True
)
context
.
set_auto_parallel_context
(
device_num
=
rank_size
,
parallel_mode
=
ParallelMode
.
DATA_PARALLEL
,
context
.
set_auto_parallel_context
(
device_num
=
rank_size
,
parallel_mode
=
ParallelMode
.
DATA_PARALLEL
,
parameter_broadcast
=
True
,
mirror_mean
=
True
)
parameter_broadcast
=
True
,
mirror_mean
=
True
)
auto_parallel_context
().
set_all_reduce_fusion_split_indices
([
140
])
auto_parallel_context
().
set_all_reduce_fusion_split_indices
([
140
])
init
()
init
()
else
:
context
.
set_context
(
enable_hccl
=
False
)
epoch_size
=
config
.
epoch_size
epoch_size
=
config
.
epoch_size
net
=
mobilenet_v2
(
num_classes
=
config
.
num_classes
)
net
=
mobilenet_v2
(
num_classes
=
config
.
num_classes
)
net
.
add_flags_recursive
(
fp16
=
True
)
for
_
,
cell
in
net
.
cells_and_names
():
if
isinstance
(
cell
,
nn
.
Dense
):
cell
.
add_flags_recursive
(
fp32
=
True
)
loss
=
SoftmaxCrossEntropyWithLogits
(
is_grad
=
False
,
sparse
=
True
,
reduction
=
'mean'
)
loss
=
SoftmaxCrossEntropyWithLogits
(
is_grad
=
False
,
sparse
=
True
,
reduction
=
'mean'
)
print
(
"train args: "
,
args_opt
,
"
\n
cfg: "
,
config
,
print
(
"train args: "
,
args_opt
,
"
\n
cfg: "
,
config
,
...
@@ -135,8 +137,7 @@ if __name__ == '__main__':
...
@@ -135,8 +137,7 @@ if __name__ == '__main__':
opt
=
Momentum
(
filter
(
lambda
x
:
x
.
requires_grad
,
net
.
get_parameters
()),
lr
,
config
.
momentum
,
opt
=
Momentum
(
filter
(
lambda
x
:
x
.
requires_grad
,
net
.
get_parameters
()),
lr
,
config
.
momentum
,
config
.
weight_decay
,
config
.
loss_scale
)
config
.
weight_decay
,
config
.
loss_scale
)
model
=
Model
(
net
,
loss_fn
=
loss
,
optimizer
=
opt
,
loss_scale_manager
=
loss_scale
,
amp_level
=
'O0'
,
model
=
Model
(
net
,
loss_fn
=
loss
,
optimizer
=
opt
,
loss_scale_manager
=
loss_scale
)
keep_batchnorm_fp32
=
False
)
cb
=
None
cb
=
None
if
rank_id
==
0
:
if
rank_id
==
0
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录