Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
3052f36c
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2305
Star
20932
Fork
5423
代码
文件
提交
分支
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看板
未验证
提交
3052f36c
编写于
5月 13, 2022
作者:
K
kuizhiqing
提交者:
GitHub
5月 13, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Launch] add gpu report during training (#42675)
* add nvsmi * collect gpu info to log * fix unitest * rm ret_type
上级
0c6baf3c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
221 addition
and
1 deletion
+221
-1
python/paddle/distributed/launch/controllers/controller.py
python/paddle/distributed/launch/controllers/controller.py
+6
-0
python/paddle/distributed/launch/controllers/watcher.py
python/paddle/distributed/launch/controllers/watcher.py
+95
-0
python/paddle/distributed/launch/utils/nvsmi.py
python/paddle/distributed/launch/utils/nvsmi.py
+117
-0
python/paddle/fluid/tests/unittests/test_run.py
python/paddle/fluid/tests/unittests/test_run.py
+3
-1
未找到文件。
python/paddle/distributed/launch/controllers/controller.py
浏览文件 @
3052f36c
...
...
@@ -21,6 +21,7 @@ from paddle.distributed.launch.job.pod import Pod
from
paddle.distributed.launch.job.container
import
Container
from
.master
import
Master
from
.watcher
import
Watcher
import
time
...
...
@@ -39,6 +40,8 @@ class ControllerBase(object):
self
.
ctx
=
ctx
self
.
master
=
Master
.
factory
(
self
.
ctx
)
self
.
watcher
=
Watcher
(
self
.
ctx
)
self
.
job
=
Job
(
nnodes
=
self
.
ctx
.
args
.
nnodes
,
mode
=
self
.
ctx
.
args
.
run_mode
,
jid
=
self
.
ctx
.
args
.
job_id
)
...
...
@@ -114,6 +117,9 @@ class ControllerBase(object):
def
stop
(
self
,
sigint
=
None
):
self
.
ctx
.
logger
.
debug
(
"Controller stop"
)
self
.
watcher
.
stop
()
self
.
master
.
stop
()
self
.
pod
.
stop
(
sigint
)
...
...
python/paddle/distributed/launch/controllers/watcher.py
0 → 100644
浏览文件 @
3052f36c
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
..utils.nvsmi
import
get_gpu_process
,
get_gpu_util
,
get_gpu_info
import
time
import
os
from
threading
import
Thread
class
Watcher
(
object
):
def
__init__
(
self
,
ctx
):
self
.
ctx
=
ctx
self
.
interval
=
10
self
.
gpu_util
=
[]
# gpu log file
self
.
gpus
=
self
.
ctx
.
args
.
devices
or
self
.
ctx
.
node
.
device
.
labels
if
len
(
self
.
gpus
)
>
0
:
fn
=
os
.
path
.
join
(
self
.
ctx
.
args
.
log_dir
,
"{}.gpu.log"
.
format
(
self
.
ctx
.
args
.
job_id
))
os
.
makedirs
(
os
.
path
.
dirname
(
fn
),
exist_ok
=
True
)
self
.
gpu_fd
=
open
(
fn
,
'w'
)
else
:
return
# start
self
.
proc
=
Thread
(
target
=
self
.
watch
)
self
.
proc
.
daemon
=
True
self
.
proc
.
start
()
def
watch
(
self
):
if
not
len
(
self
.
gpus
)
>
0
:
return
self
.
_print_gpu_info
()
util_key
=
"index,utilization_gpu,memory_total,memory_used,memory_free,timestamp"
self
.
gpu_fd
.
write
(
util_key
)
self
.
gpu_fd
.
write
(
'
\n
'
)
while
not
self
.
ctx
.
status
.
is_done
():
self
.
_save_gpu_log
(
util_key
)
time
.
sleep
(
self
.
interval
)
if
hasattr
(
self
,
"gpu_fd"
):
self
.
gpu_fd
.
close
()
def
_print_gpu_info
(
self
):
try
:
info_key
=
"index,uuid,driver_version,name,gpu_serial,display_active,display_mode"
self
.
gpu_fd
.
write
(
info_key
)
self
.
gpu_fd
.
write
(
'
\n
'
)
for
line
in
get_gpu_info
(
self
.
gpus
):
self
.
gpu_fd
.
write
(
line
.
str
(
info_key
))
self
.
gpu_fd
.
write
(
'
\n
'
)
self
.
gpu_fd
.
write
(
'
\n
'
)
process_key
=
"pid,process_name,gpu_uuid,gpu_name,used_memory"
self
.
gpu_fd
.
write
(
process_key
)
self
.
gpu_fd
.
write
(
'
\n
'
)
for
line
in
get_gpu_process
(
self
.
gpus
):
self
.
gpu_fd
.
write
(
line
.
str
(
process_key
))
self
.
gpu_fd
.
write
(
'
\n
'
)
self
.
gpu_fd
.
write
(
'
\n
'
)
self
.
gpu_fd
.
flush
()
except
:
self
.
ctx
.
log
.
error
(
"save gpu info failed"
)
def
_save_gpu_log
(
self
,
util_key
):
try
:
for
line
in
get_gpu_util
(
self
.
gpus
):
self
.
gpu_fd
.
write
(
line
.
str
(
util_key
))
self
.
gpu_fd
.
write
(
'
\n
'
)
self
.
gpu_fd
.
flush
()
except
:
self
.
ctx
.
log
.
error
(
"save gpu log failed"
)
def
stop
(
self
):
if
hasattr
(
self
,
"proc"
):
self
.
proc
.
join
()
python/paddle/distributed/launch/utils/nvsmi.py
0 → 100644
浏览文件 @
3052f36c
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
subprocess
import
shlex
import
os
import
json
import
shutil
class
Info
(
object
):
def
__repr__
(
self
):
return
str
(
self
.
__dict__
)
def
json
(
self
):
return
json
.
dumps
(
self
.
__dict__
)
def
dict
(
self
):
return
self
.
__dict__
def
str
(
self
,
keys
=
None
):
if
keys
is
None
:
keys
=
self
.
__dict__
.
keys
()
if
isinstance
(
keys
,
str
):
keys
=
keys
.
split
(
','
)
values
=
[
str
(
self
.
__dict__
.
get
(
k
,
''
))
for
k
in
keys
]
return
","
.
join
(
values
)
def
query_smi
(
query
=
None
,
query_type
=
"gpu"
,
index
=
None
,
dtype
=
None
):
"""
query_type: gpu/compute
"""
if
not
has_nvidia_smi
():
return
[]
cmd
=
[
"nvidia-smi"
,
"--format=csv,noheader,nounits"
]
if
isinstance
(
query
,
list
)
and
query_type
==
"gpu"
:
cmd
.
extend
([
"--query-gpu={}"
.
format
(
","
.
join
(
query
))])
elif
isinstance
(
query
,
list
)
and
query_type
.
startswith
(
"compute"
):
cmd
.
extend
([
"--query-compute-apps={}"
.
format
(
","
.
join
(
query
))])
else
:
return
if
isinstance
(
index
,
list
)
and
len
(
index
)
>
0
:
cmd
.
extend
([
"--id={}"
.
format
(
","
.
join
(
index
))])
if
not
isinstance
(
dtype
,
list
)
or
len
(
dtype
)
!=
len
(
query
):
dtype
=
[
str
]
*
len
(
query
)
output
=
subprocess
.
check_output
(
cmd
,
timeout
=
3
)
lines
=
output
.
decode
(
"utf-8"
).
split
(
os
.
linesep
)
ret
=
[]
for
line
in
lines
:
if
not
line
:
continue
info
=
Info
()
for
k
,
v
,
d
in
zip
(
query
,
line
.
split
(
", "
),
dtype
):
setattr
(
info
,
k
.
replace
(
"."
,
"_"
),
d
(
v
))
ret
.
append
(
info
)
return
ret
def
get_gpu_info
(
index
=
None
):
q
=
"index,uuid,driver_version,name,gpu_serial,display_active,display_mode"
.
split
(
","
)
d
=
[
int
,
str
,
str
,
str
,
str
,
str
,
str
]
index
=
index
if
index
is
None
or
isinstance
(
index
,
list
)
else
str
(
index
).
split
(
","
)
return
query_smi
(
q
,
index
=
index
,
dtype
=
d
)
def
get_gpu_util
(
index
=
None
):
q
=
"index,utilization.gpu,memory.total,memory.used,memory.free,timestamp"
.
split
(
","
)
d
=
[
int
,
int
,
int
,
int
,
int
,
str
]
index
=
index
if
index
is
None
or
isinstance
(
index
,
list
)
else
str
(
index
).
split
(
","
)
return
query_smi
(
q
,
index
=
index
,
dtype
=
d
)
def
get_gpu_process
(
index
=
None
):
q
=
"pid,process_name,gpu_uuid,gpu_name,used_memory"
.
split
(
","
)
d
=
[
int
,
str
,
str
,
str
,
int
]
index
=
index
if
index
is
None
or
isinstance
(
index
,
list
)
else
str
(
index
).
split
(
","
)
return
query_smi
(
q
,
index
=
index
,
query_type
=
"compute"
,
dtype
=
d
)
def
has_nvidia_smi
():
return
shutil
.
which
(
"nvidia-smi"
)
if
__name__
==
'__main__'
:
print
(
get_gpu_info
(
0
))
print
(
get_gpu_util
(
0
))
print
(
get_gpu_process
(
0
))
u
=
get_gpu_util
()
for
i
in
u
:
print
(
i
.
str
())
python/paddle/fluid/tests/unittests/test_run.py
浏览文件 @
3052f36c
...
...
@@ -51,7 +51,9 @@ def write_file(name, ct):
def
get_files
(
pth
,
prefix
):
return
[
f
for
f
in
listdir
(
pth
)
if
isfile
(
join
(
pth
,
f
))
and
f
.
startswith
(
prefix
)
f
for
f
in
listdir
(
pth
)
if
isfile
(
join
(
pth
,
f
))
and
f
.
startswith
(
prefix
)
and
f
!=
f
"
{
prefix
}
.gpu.log"
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录