Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
cbe45abf
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
cbe45abf
编写于
6月 01, 2021
作者:
C
Chen Weihang
提交者:
GitHub
6月 01, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix spawn default nprocs get error (#33215)
* fix spawn default nprocs get error * polish error message
上级
44dd918d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
13 deletion
+23
-13
python/paddle/distributed/spawn.py
python/paddle/distributed/spawn.py
+13
-12
python/paddle/fluid/tests/unittests/test_spawn_and_init_parallel_env.py
...fluid/tests/unittests/test_spawn_and_init_parallel_env.py
+10
-1
未找到文件。
python/paddle/distributed/spawn.py
浏览文件 @
cbe45abf
...
@@ -89,6 +89,18 @@ def _options_valid_check(options):
...
@@ -89,6 +89,18 @@ def _options_valid_check(options):
%
key
)
%
key
)
def
_get_default_nprocs
():
device
=
get_device
()
if
'gpu'
in
device
:
return
core
.
get_cuda_device_count
()
elif
'xpu'
in
device
:
return
core
.
get_xpu_device_count
()
else
:
raise
RuntimeError
(
"`paddle.distributed.spawn` does not support parallel training on device `{}` now."
.
format
(
device
))
def
_get_node_ip
(
ips
):
def
_get_node_ip
(
ips
):
node_ip
=
None
node_ip
=
None
node_ips
=
[
x
.
strip
()
for
x
in
ips
.
split
(
','
)]
node_ips
=
[
x
.
strip
()
for
x
in
ips
.
split
(
','
)]
...
@@ -448,18 +460,7 @@ def spawn(func, args=(), nprocs=-1, join=True, daemon=False, **options):
...
@@ -448,18 +460,7 @@ def spawn(func, args=(), nprocs=-1, join=True, daemon=False, **options):
# get default nprocs
# get default nprocs
if
nprocs
==
-
1
:
if
nprocs
==
-
1
:
device
=
get_device
()
nprocs
=
_get_default_nprocs
()
if
device
==
'cpu'
:
# TODO: not supports cpu parallel now
nprocs
=
_cpu_num
()
elif
device
==
'gpu'
:
nprocs
=
core
.
get_cuda_device_count
()
elif
device
==
'xpu'
:
nprocs
=
core
.
get_xpu_device_count
()
else
:
raise
ValueError
(
"`device` should be a string of `cpu`, 'gpu' or 'xpu', but got {}"
.
format
(
device
))
# NOTE(chenweihang): [ why need get cluster info before run? ]
# NOTE(chenweihang): [ why need get cluster info before run? ]
# when using `paddle.distributed.spawn` start parallel training,
# when using `paddle.distributed.spawn` start parallel training,
...
...
python/paddle/fluid/tests/unittests/test_spawn_and_init_parallel_env.py
浏览文件 @
cbe45abf
...
@@ -20,7 +20,7 @@ import unittest
...
@@ -20,7 +20,7 @@ import unittest
import
paddle
import
paddle
import
paddle.distributed
as
dist
import
paddle.distributed
as
dist
from
paddle.distributed.spawn
import
_get_subprocess_env_list
,
_options_valid_check
from
paddle.distributed.spawn
import
_get_subprocess_env_list
,
_options_valid_check
,
_get_default_nprocs
from
paddle.fluid
import
core
from
paddle.fluid
import
core
from
paddle.fluid.dygraph
import
parallel_helper
from
paddle.fluid.dygraph
import
parallel_helper
...
@@ -87,6 +87,15 @@ class TestSpawnAssistMethod(unittest.TestCase):
...
@@ -87,6 +87,15 @@ class TestSpawnAssistMethod(unittest.TestCase):
options
[
'error'
]
=
"error"
options
[
'error'
]
=
"error"
_options_valid_check
(
options
)
_options_valid_check
(
options
)
def
test_get_default_nprocs
(
self
):
paddle
.
set_device
(
'cpu'
)
with
self
.
assertRaises
(
RuntimeError
):
nprocs
=
_get_default_nprocs
()
paddle
.
set_device
(
'gpu'
)
nprocs
=
_get_default_nprocs
()
self
.
assertEqual
(
nprocs
,
core
.
get_cuda_device_count
())
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录