Skip to content

Commit 1199d3d

Browse files
Add files via upload
1 parent e7d51f5 commit 1199d3d

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

collect_env_details.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Copyright The PyTorch Lightning team.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Diagnose your system and show basic information.
15+
16+
This server mainly to get detail info for better bug reporting.
17+
"""
18+
19+
import os
20+
import platform
21+
import sys
22+
23+
import numpy
24+
import torch
25+
import tqdm
26+
27+
sys.path += [os.path.abspath(".."), os.path.abspath(".")]
28+
import pytorch_lightning # noqa: E402
29+
30+
LEVEL_OFFSET = "\t"
31+
KEY_PADDING = 20
32+
33+
34+
def info_system():
35+
return {
36+
"OS": platform.system(),
37+
"architecture": platform.architecture(),
38+
"version": platform.version(),
39+
"processor": platform.processor(),
40+
"python": platform.python_version(),
41+
}
42+
43+
44+
def info_cuda():
45+
return {
46+
"GPU": [torch.cuda.get_device_name(i) for i in range(torch.cuda.device_count())],
47+
# 'nvidia_driver': get_nvidia_driver_version(run_lambda),
48+
"available": torch.cuda.is_available(),
49+
"version": torch.version.cuda,
50+
}
51+
52+
53+
def info_packages():
54+
return {
55+
"numpy": numpy.__version__,
56+
"pyTorch_version": torch.__version__,
57+
"pyTorch_debug": torch.version.debug,
58+
"pytorch-lightning": pytorch_lightning.__version__,
59+
"tqdm": tqdm.__version__,
60+
}
61+
62+
63+
def nice_print(details, level=0):
64+
lines = []
65+
for k in sorted(details):
66+
key = f"* {k}:" if level == 0 else f"- {k}:"
67+
if isinstance(details[k], dict):
68+
lines += [level * LEVEL_OFFSET + key]
69+
lines += nice_print(details[k], level + 1)
70+
elif isinstance(details[k], (set, list, tuple)):
71+
lines += [level * LEVEL_OFFSET + key]
72+
lines += [(level + 1) * LEVEL_OFFSET + "- " + v for v in details[k]]
73+
else:
74+
template = "{:%is} {}" % KEY_PADDING
75+
key_val = template.format(key, details[k])
76+
lines += [(level * LEVEL_OFFSET) + key_val]
77+
return lines
78+
79+
80+
def main():
81+
details = {"System": info_system(), "CUDA": info_cuda(), "Packages": info_packages()}
82+
lines = nice_print(details)
83+
text = os.linesep.join(lines)
84+
print(text)
85+
86+
87+
if __name__ == "__main__":
88+
main()

0 commit comments

Comments
 (0)