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