pytorch-lightning

Форк
0
/
collect_env_details.py 
88 строк · 2.7 Кб
1
# Copyright The Lightning AI 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

20
import os
21
import platform
22
import sys
23

24
import pkg_resources
25
import torch
26

27
sys.path += [os.path.abspath(".."), os.path.abspath("")]
28

29

30
LEVEL_OFFSET = "\t"
31
KEY_PADDING = 20
32

33

34
def info_system() -> dict:
35
    return {
36
        "OS": platform.system(),
37
        "architecture": platform.architecture(),
38
        "version": platform.version(),
39
        "release": platform.release(),
40
        "processor": platform.processor(),
41
        "python": platform.python_version(),
42
    }
43

44

45
def info_cuda() -> dict:
46
    return {
47
        "GPU": [torch.cuda.get_device_name(i) for i in range(torch.cuda.device_count())] or None,
48
        "available": torch.cuda.is_available(),
49
        "version": torch.version.cuda,
50
    }
51

52

53
def info_packages() -> dict:
54
    """Get name and version of all installed packages."""
55
    packages = {}
56
    for dist in pkg_resources.working_set:
57
        package = dist.as_requirement()
58
        packages[package.key] = package.specs[0][1]
59
    return packages
60

61

62
def nice_print(details: dict, level: int = 0) -> list:
63
    lines = []
64
    for k in sorted(details):
65
        key = f"* {k}:" if level == 0 else f"- {k}:"
66
        if isinstance(details[k], dict):
67
            lines += [level * LEVEL_OFFSET + key]
68
            lines += nice_print(details[k], level + 1)
69
        elif isinstance(details[k], (set, list, tuple)):
70
            lines += [level * LEVEL_OFFSET + key]
71
            lines += [(level + 1) * LEVEL_OFFSET + "- " + v for v in details[k]]
72
        else:
73
            template = "{:%is} {}" % KEY_PADDING
74
            key_val = template.format(key, details[k])
75
            lines += [(level * LEVEL_OFFSET) + key_val]
76
    return lines
77

78

79
def main() -> None:
80
    details = {"System": info_system(), "CUDA": info_cuda(), "Packages": info_packages()}
81
    details["Lightning"] = {k: v for k, v in details["Packages"].items() if "torch" in k or "lightning" in k}
82
    lines = nice_print(details)
83
    text = os.linesep.join(lines)
84
    print(f"<details>\n  <summary>Current environment</summary>\n\n{text}\n\n</details>")
85

86

87
if __name__ == "__main__":
88
    main()
89

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.