env_report.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import torch
  2. import deepspeed
  3. import subprocess
  4. import argparse
  5. from .ops.op_builder import ALL_OPS
  6. from .git_version_info import installed_ops, torch_info
  7. from .ops import __compatible_ops__ as compatible_ops
  8. GREEN = '\033[92m'
  9. RED = '\033[91m'
  10. YELLOW = '\033[93m'
  11. END = '\033[0m'
  12. SUCCESS = f"{GREEN} [SUCCESS] {END}"
  13. OKAY = f"{GREEN}[OKAY]{END}"
  14. WARNING = f"{YELLOW}[WARNING]{END}"
  15. FAIL = f'{RED}[FAIL]{END}'
  16. INFO = '[INFO]'
  17. color_len = len(GREEN) + len(END)
  18. okay = f"{GREEN}[OKAY]{END}"
  19. warning = f"{YELLOW}[WARNING]{END}"
  20. def op_report(verbose=True):
  21. max_dots = 23
  22. max_dots2 = 11
  23. h = ["op name", "installed", "compatible"]
  24. print("-" * (max_dots + max_dots2 + len(h[0]) + len(h[1])))
  25. print("DeepSpeed C++/CUDA extension op report")
  26. print("-" * (max_dots + max_dots2 + len(h[0]) + len(h[1])))
  27. print("NOTE: Ops not installed will be just-in-time (JIT) compiled at\n"
  28. " runtime if needed. Op compatibility means that your system\n"
  29. " meet the required dependencies to JIT install the op.")
  30. print("-" * (max_dots + max_dots2 + len(h[0]) + len(h[1])))
  31. print("JIT compiled ops requires ninja")
  32. ninja_status = OKAY if ninja_installed() else FAIL
  33. print('ninja', "." * (max_dots - 5), ninja_status)
  34. print("-" * (max_dots + max_dots2 + len(h[0]) + len(h[1])))
  35. print(h[0], "." * (max_dots - len(h[0])), h[1], "." * (max_dots2 - len(h[1])), h[2])
  36. print("-" * (max_dots + max_dots2 + len(h[0]) + len(h[1])))
  37. installed = f"{GREEN}[YES]{END}"
  38. no = f"{YELLOW}[NO]{END}"
  39. for op_name, builder in ALL_OPS.items():
  40. dots = "." * (max_dots - len(op_name))
  41. is_compatible = OKAY if builder.is_compatible(verbose) else no
  42. is_installed = installed if installed_ops[op_name] else no
  43. dots2 = '.' * ((len(h[1]) + (max_dots2 - len(h[1]))) -
  44. (len(is_installed) - color_len))
  45. print(op_name, dots, is_installed, dots2, is_compatible)
  46. print("-" * (max_dots + max_dots2 + len(h[0]) + len(h[1])))
  47. def ninja_installed():
  48. try:
  49. import ninja
  50. except ImportError:
  51. return False
  52. return True
  53. def nvcc_version():
  54. import torch.utils.cpp_extension
  55. cuda_home = torch.utils.cpp_extension.CUDA_HOME
  56. if cuda_home is None:
  57. return f"{RED} [FAIL] cannot find CUDA_HOME via torch.utils.cpp_extension.CUDA_HOME={torch.utils.cpp_extension.CUDA_HOME} {END}"
  58. try:
  59. output = subprocess.check_output([cuda_home + "/bin/nvcc",
  60. "-V"],
  61. universal_newlines=True)
  62. except FileNotFoundError:
  63. return f"{RED} [FAIL] nvcc missing {END}"
  64. output_split = output.split()
  65. release_idx = output_split.index("release")
  66. release = output_split[release_idx + 1].replace(',', '').split(".")
  67. return ".".join(release)
  68. def debug_report():
  69. max_dots = 33
  70. report = [
  71. ("torch install path",
  72. torch.__path__),
  73. ("torch version",
  74. torch.__version__),
  75. ("torch cuda version",
  76. torch.version.cuda),
  77. ("nvcc version",
  78. nvcc_version()),
  79. ("deepspeed install path",
  80. deepspeed.__path__),
  81. ("deepspeed info",
  82. f"{deepspeed.__version__}, {deepspeed.__git_hash__}, {deepspeed.__git_branch__}"
  83. ),
  84. ("deepspeed wheel compiled w.",
  85. f"torch {torch_info['version']}, cuda {torch_info['cuda_version']}"),
  86. ]
  87. print("DeepSpeed general environment info:")
  88. for name, value in report:
  89. print(name, "." * (max_dots - len(name)), value)
  90. def parse_arguments():
  91. parser = argparse.ArgumentParser()
  92. parser.add_argument(
  93. '--hide_operator_status',
  94. action='store_true',
  95. help=
  96. 'Suppress display of installation and compatiblity statuses of DeepSpeed operators. '
  97. )
  98. parser.add_argument('--hide_errors_and_warnings',
  99. action='store_true',
  100. help='Suppress warning and error messages.')
  101. args = parser.parse_args()
  102. return args
  103. def main(hide_operator_status=False, hide_errors_and_warnings=False):
  104. if not hide_operator_status:
  105. op_report(verbose=not hide_errors_and_warnings)
  106. debug_report()
  107. def cli_main():
  108. args = parse_arguments()
  109. main(hide_operator_status=args.hide_operator_status,
  110. hide_errors_and_warnings=args.hide_errors_and_warnings)
  111. if __name__ == "__main__":
  112. main()