-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathgather_runners_info.py
More file actions
executable file
·80 lines (61 loc) · 2.15 KB
/
Copy pathgather_runners_info.py
File metadata and controls
executable file
·80 lines (61 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
import json
import logging
import os
import platform
import socket
from logging import info
from typing import Any, Dict
import psutil # type: ignore[import-untyped]
logging.basicConfig(level=logging.INFO)
def set_output(name: str, val: Any) -> None:
if os.getenv("GITHUB_OUTPUT"):
with open(str(os.getenv("GITHUB_OUTPUT")), "a") as env:
print(f"{name}={val}", file=env)
else:
print(f"::set-output name={name}::{val}")
def get_runner_info() -> Dict[str, Any]:
device_name = ""
device_type = ""
try:
import torch # type: ignore[import-not-found]
if torch.cuda.is_available():
if torch.version.hip:
device_name = "rocm"
elif torch.version.cuda:
device_name = "cuda"
device_type = torch.cuda.get_device_name()
except ImportError:
info("Fail to import torch to get the device name")
runner_info = {
"cpu_info": platform.processor(),
"cpu_count": psutil.cpu_count(),
"avail_mem_in_gb": int(psutil.virtual_memory().total / (1024 * 1024 * 1024)),
"extra_info": {
"hostname": socket.gethostname(),
},
}
if device_name and device_type:
runner_info["name"] = device_name
runner_info["type"] = device_type
runner_info["gpu_count"] = torch.cuda.device_count()
runner_info["avail_gpu_mem_in_gb"] = int(
torch.cuda.get_device_properties(0).total_memory
* torch.cuda.device_count()
/ (1024 * 1024 * 1024)
)
else:
# Check if the workflow has already set the device name and type
runner_info["name"] = os.getenv("DEVICE_NAME", "")
runner_info["type"] = os.getenv("DEVICE_TYPE", "")
return runner_info
def main() -> None:
runner_info = get_runner_info()
set_output("runners", json.dumps([runner_info]))
if __name__ == "__main__":
main()