keep-gpu 0.1.0.post2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- keep_gpu/__init__.py +5 -0
- keep_gpu/benchmark.py +51 -0
- keep_gpu/cli.py +23 -0
- keep_gpu/keep_gpu.py +27 -0
- keep_gpu-0.1.0.post2.dist-info/METADATA +62 -0
- keep_gpu-0.1.0.post2.dist-info/RECORD +11 -0
- keep_gpu-0.1.0.post2.dist-info/WHEEL +5 -0
- keep_gpu-0.1.0.post2.dist-info/entry_points.txt +2 -0
- keep_gpu-0.1.0.post2.dist-info/licenses/AUTHORS.rst +13 -0
- keep_gpu-0.1.0.post2.dist-info/licenses/LICENSE +21 -0
- keep_gpu-0.1.0.post2.dist-info/top_level.txt +1 -0
keep_gpu/__init__.py
ADDED
keep_gpu/benchmark.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
import time
|
|
3
|
+
import subprocess
|
|
4
|
+
import re
|
|
5
|
+
import random
|
|
6
|
+
|
|
7
|
+
def get_gpu_util(rank):
|
|
8
|
+
cmds = ['nvidia-smi', '-i', str(rank)]
|
|
9
|
+
proc = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
10
|
+
stdout, stderr = proc.communicate()
|
|
11
|
+
outputs = stdout.decode('utf-8').split('\n')
|
|
12
|
+
|
|
13
|
+
util = 0
|
|
14
|
+
for output in outputs[::-1]:
|
|
15
|
+
if 'Default' in output:
|
|
16
|
+
util = int(re.findall(r'\d+', output)[-1])
|
|
17
|
+
break
|
|
18
|
+
else:
|
|
19
|
+
print(f"rank {rank}: couldn't match any, check GPU status!")
|
|
20
|
+
return util
|
|
21
|
+
|
|
22
|
+
def keep(rank, args):
|
|
23
|
+
torch.cuda.set_device(rank)
|
|
24
|
+
print(f'benchmarking {args.gpus} gpus...')
|
|
25
|
+
while True:
|
|
26
|
+
n = random.randint(5, 9)
|
|
27
|
+
a = torch.rand((8192 * n, 8192)).cuda()
|
|
28
|
+
b = torch.rand((8192 * n, 8192)).cuda()
|
|
29
|
+
|
|
30
|
+
tic = time.time()
|
|
31
|
+
for _ in range(5000):
|
|
32
|
+
c = a * b
|
|
33
|
+
torch.cuda.synchronize()
|
|
34
|
+
toc = time.time()
|
|
35
|
+
if rank == 0:
|
|
36
|
+
print('benchmark 5K matmul: time span: {}ms'.format((toc - tic) * 1000 / 5000))
|
|
37
|
+
|
|
38
|
+
time.sleep(args.interval)
|
|
39
|
+
while get_gpu_util(rank) > 10:
|
|
40
|
+
print(f'rank {rank}: GPU busy, sleeping...')
|
|
41
|
+
time.sleep(args.interval)
|
|
42
|
+
print(f'rank {rank} resumes')
|
|
43
|
+
|
|
44
|
+
def run_benchmark(gpus=1, interval=100):
|
|
45
|
+
class Args:
|
|
46
|
+
def __init__(self, gpus, interval):
|
|
47
|
+
self.gpus = gpus
|
|
48
|
+
self.interval = interval
|
|
49
|
+
|
|
50
|
+
args = Args(gpus, interval)
|
|
51
|
+
torch.multiprocessing.spawn(keep, args=(args,), nprocs=gpus, join=True)
|
keep_gpu/cli.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Console script for keep_gpu."""
|
|
2
|
+
import keep_gpu
|
|
3
|
+
from .keep_gpu import run
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
|
|
8
|
+
app = typer.Typer()
|
|
9
|
+
console = Console()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@app.command()
|
|
13
|
+
def main():
|
|
14
|
+
"""Console script for keep_gpu."""
|
|
15
|
+
console.print("Replace this message by putting your code into "
|
|
16
|
+
"keep_gpu.cli.main")
|
|
17
|
+
console.print("See Typer documentation at https://typer.tiangolo.com/")
|
|
18
|
+
run()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if __name__ == "__main__":
|
|
23
|
+
app()
|
keep_gpu/keep_gpu.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import time
|
|
3
|
+
import os
|
|
4
|
+
import torch
|
|
5
|
+
|
|
6
|
+
from .benchmark import run_benchmark
|
|
7
|
+
|
|
8
|
+
def check_gpu_usage():
|
|
9
|
+
result = subprocess.run(['nvidia-smi', '--query-gpu=utilization.gpu', '--format=csv,noheader'], capture_output=True, text=True)
|
|
10
|
+
gpu_usages = [int(line.split()[0]) for line in result.stdout.strip().split('\n')]
|
|
11
|
+
return any(usage > 0 for usage in gpu_usages)
|
|
12
|
+
|
|
13
|
+
def run():
|
|
14
|
+
idle_count = 0
|
|
15
|
+
gpu_count = torch.cuda.device_count()
|
|
16
|
+
print(f'GPU count: {gpu_count}')
|
|
17
|
+
while True:
|
|
18
|
+
if not check_gpu_usage():
|
|
19
|
+
idle_count += 1
|
|
20
|
+
else:
|
|
21
|
+
idle_count = 0
|
|
22
|
+
|
|
23
|
+
if idle_count >= 1:
|
|
24
|
+
run_benchmark(gpu_count)
|
|
25
|
+
idle_count = 0
|
|
26
|
+
|
|
27
|
+
time.sleep(300)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: keep_gpu
|
|
3
|
+
Version: 0.1.0.post2
|
|
4
|
+
Summary: Keep GPU is a simple cli app that keep your gpus running
|
|
5
|
+
Author-email: Siyuan Wang <sywang0227@gmail.com>
|
|
6
|
+
Maintainer-email: Siyuan Wang <sywang0227@gmail.com>
|
|
7
|
+
License: MIT license
|
|
8
|
+
Project-URL: bugs, https://github.com/Wangmerlyn/keep_gpu/issues
|
|
9
|
+
Project-URL: changelog, https://github.com/Wangmerlyn/keep_gpu/blob/master/changelog.md
|
|
10
|
+
Project-URL: homepage, https://github.com/Wangmerlyn/keep_gpu
|
|
11
|
+
Description-Content-Type: text/x-rst
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
License-File: AUTHORS.rst
|
|
14
|
+
Requires-Dist: typer
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: coverage; extra == "dev"
|
|
17
|
+
Requires-Dist: mypy; extra == "dev"
|
|
18
|
+
Requires-Dist: pytest; extra == "dev"
|
|
19
|
+
Requires-Dist: ruff; extra == "dev"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
========
|
|
23
|
+
Keep GPU
|
|
24
|
+
========
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
.. image:: https://img.shields.io/pypi/v/keep_gpu.svg
|
|
28
|
+
:target: https://pypi.python.org/pypi/keep_gpu
|
|
29
|
+
|
|
30
|
+
.. image:: https://img.shields.io/travis/Wangmerlyn/KeepGPU.svg
|
|
31
|
+
:target: https://travis-ci.com/Wangmerlyn/KeepGPU
|
|
32
|
+
|
|
33
|
+
.. image:: https://readthedocs.org/projects/keep-gpu/badge/?version=latest
|
|
34
|
+
:target: https://keep-gpu.readthedocs.io/en/latest/?version=latest
|
|
35
|
+
:alt: Documentation Status
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
.. image:: https://pyup.io/repos/github/Wangmerlyn/keep_gpu/shield.svg
|
|
39
|
+
:target: https://pyup.io/repos/github/Wangmerlyn/keep_gpu/
|
|
40
|
+
:alt: Updates
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
Keep GPU is a simple cli app that keep your gpus running
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
* Free software: MIT license
|
|
48
|
+
* Documentation: https://keep-gpu.readthedocs.io.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
Features
|
|
52
|
+
--------
|
|
53
|
+
|
|
54
|
+
* TODO
|
|
55
|
+
|
|
56
|
+
Credits
|
|
57
|
+
-------
|
|
58
|
+
|
|
59
|
+
This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.
|
|
60
|
+
|
|
61
|
+
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
|
|
62
|
+
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
keep_gpu/__init__.py,sha256=QUHEJ6d-rCaH0wmjr0m3NXKFDRHasZVgvGiHOB4SNrs,133
|
|
2
|
+
keep_gpu/benchmark.py,sha256=luF7OykdNVVvK-kCoPmf_Uv4Yt7ndGRUifKVWDjKRMY,1535
|
|
3
|
+
keep_gpu/cli.py,sha256=7xFA-fd3XSQEZBnrtTrokiUMTTgt-OMpmNH5fSdNh2U,467
|
|
4
|
+
keep_gpu/keep_gpu.py,sha256=ibT1uq6LoBu0SxyD9m5xoxeee76bPJmTMGjWODNKFSY,729
|
|
5
|
+
keep_gpu-0.1.0.post2.dist-info/licenses/AUTHORS.rst,sha256=noCLnXG7s3FbpXW5p6xOCvFbtthB-EbNrXYkJiZ0UJ0,157
|
|
6
|
+
keep_gpu-0.1.0.post2.dist-info/licenses/LICENSE,sha256=kllvw8ht5d-ouGFNw5MKUZbJsin2FT9pDoj-Pb77oKU,1068
|
|
7
|
+
keep_gpu-0.1.0.post2.dist-info/METADATA,sha256=hc_wG6UoiUJaxXxpWhUZMlXA0-3L0IdMWzMliqtYkMo,1802
|
|
8
|
+
keep_gpu-0.1.0.post2.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
|
9
|
+
keep_gpu-0.1.0.post2.dist-info/entry_points.txt,sha256=kwu7vUr9BKa_J8faaSvOoyLrYCLPJw-Q5Uj8CjvkVc8,47
|
|
10
|
+
keep_gpu-0.1.0.post2.dist-info/top_level.txt,sha256=xTOXirwmEOtbk4HZ_kVH6Y4spzHoh9Rhv78XeQ_Fhu0,9
|
|
11
|
+
keep_gpu-0.1.0.post2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Wang Siyuan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
keep_gpu
|