Last active
March 17, 2021 01:34
-
-
Save tuttelikz/ebd5ab3ffb29cb9399f2596b8f163a4e to your computer and use it in GitHub Desktop.
<cenv.py> sys & conda summary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""This script summarizes information on system and virtual environment. | |
Modified from https://github.com/facebookresearch/detectron2/raw/master/detectron2/utils/collect_env.py | |
Under Apache License 2.0 | |
Run following in the terminal: | |
$$ git clone https://gist.github.com/tuttelikz/ebd5ab3ffb29cb9399f2596b8f163a4e a && python a/cenv.py | |
Sample output: | |
---------------------- -------------------------------------------------------------------------------------- | |
sys.platform linux | |
Python 3.8.8 (default, Feb 24 2021, 21:46:12) [GCC 7.3.0] | |
numpy 1.19.4 | |
Compiler ($CXX) c++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 | |
CUDA compiler Build cuda_11.2.r11.2/compiler.29558016_0 | |
PyTorch 1.7.1+cu110 @/home/suzy/miniconda3/envs/vslego/lib/python3.8/site-packages/torch | |
PyTorch debug build False | |
GPU available True | |
GPU 0,1,2,3,4 GeForce RTX 3090 (arch=8.6) | |
CUDA_HOME /usr/local/cuda-11.2 | |
Pillow 8.1.1 | |
torchvision 0.8.2+cu110 @/home/suzy/miniconda3/envs/vslego/lib/python3.8/site-packages/torchvision | |
torchvision arch flags 3.5, 5.0, 6.0, 7.0, 7.5, 8.0 | |
cv2 4.5.1 | |
---------------------- -------------------------------------------------------------------------------------- | |
PyTorch built with: | |
- GCC 7.3 | |
- C++ Version: 201402 | |
- Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191122 for Intel(R) 64 architecture applications | |
- Intel(R) MKL-DNN v1.6.0 (Git Hash 5ef631a030a6f73131c77892041042805a06064f) | |
- OpenMP 201511 (a.k.a. OpenMP 4.5) | |
- NNPACK is enabled | |
- CPU capability usage: AVX2 | |
- CUDA Runtime 11.0 | |
- NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80 | |
- CuDNN 8.0.5 | |
- Magma 2.5.2 | |
- Build settings: BLAS=MKL, BUILD_TYPE=Release, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DUSE_VULKAN_WRAPPER -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, USE_CUDA=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, | |
""" | |
import importlib | |
import numpy as np | |
import os | |
import re | |
import subprocess | |
import sys | |
from collections import defaultdict | |
import PIL | |
import torch | |
import torchvision | |
from tabulate import tabulate | |
__all__ = ["collect_env_info"] | |
def collect_torch_env(): | |
try: | |
import torch.__config__ | |
return torch.__config__.show() | |
except ImportError: | |
# compatible with older versions of pytorch | |
from torch.utils.collect_env import get_pretty_env_info | |
return get_pretty_env_info() | |
def detect_compute_compatibility(CUDA_HOME, so_file): | |
try: | |
cuobjdump = os.path.join(CUDA_HOME, "bin", "cuobjdump") | |
if os.path.isfile(cuobjdump): | |
output = subprocess.check_output( | |
"'{}' --list-elf '{}'".format(cuobjdump, so_file), shell=True | |
) | |
output = output.decode("utf-8").strip().split("\n") | |
arch = [] | |
for line in output: | |
line = re.findall(r"\.sm_([0-9]*)\.", line)[0] | |
arch.append(".".join(line)) | |
arch = sorted(set(arch)) | |
return ", ".join(arch) | |
else: | |
return so_file + "; cannot find cuobjdump" | |
except Exception: | |
# unhandled failure | |
return so_file | |
def collect_env_info(): | |
has_gpu = torch.cuda.is_available() # true for both CUDA & ROCM | |
torch_version = torch.__version__ | |
# NOTE that CUDA_HOME/ROCM_HOME could be None even when CUDA runtime libs are functional | |
from torch.utils.cpp_extension import CUDA_HOME, ROCM_HOME | |
has_rocm = False | |
if (getattr(torch.version, "hip", None) is not None) and (ROCM_HOME is not None): | |
has_rocm = True | |
has_cuda = has_gpu and (not has_rocm) | |
data = [] | |
data.append(("sys.platform", sys.platform)) # check-template.yml depends on it | |
data.append(("Python", sys.version.replace("\n", ""))) | |
data.append(("numpy", np.__version__)) | |
# print system compilers when extension fails to build | |
if sys.platform != "win32": # don't know what to do for windows | |
try: | |
# this is how torch/utils/cpp_extensions.py choose compiler | |
cxx = os.environ.get("CXX", "c++") | |
cxx = subprocess.check_output("'{}' --version".format(cxx), shell=True) | |
cxx = cxx.decode("utf-8").strip().split("\n")[0] | |
except subprocess.SubprocessError: | |
cxx = "Not found" | |
data.append(("Compiler ($CXX)", cxx)) | |
if has_cuda and CUDA_HOME is not None: | |
try: | |
nvcc = os.path.join(CUDA_HOME, "bin", "nvcc") | |
nvcc = subprocess.check_output("'{}' -V".format(nvcc), shell=True) | |
nvcc = nvcc.decode("utf-8").strip().split("\n")[-1] | |
except subprocess.SubprocessError: | |
nvcc = "Not found" | |
data.append(("CUDA compiler", nvcc)) | |
else: | |
# print compilers that are used to build extension | |
data.append(("Compiler", _C.get_compiler_version())) | |
data.append(("CUDA compiler", _C.get_cuda_version())) # cuda or hip | |
data.append(("PyTorch", torch_version + " @" + os.path.dirname(torch.__file__))) | |
data.append(("PyTorch debug build", torch.version.debug)) | |
data.append(("GPU available", has_gpu)) | |
if has_gpu: | |
devices = defaultdict(list) | |
for k in range(torch.cuda.device_count()): | |
cap = ".".join((str(x) for x in torch.cuda.get_device_capability(k))) | |
name = torch.cuda.get_device_name(k) + f" (arch={cap})" | |
devices[name].append(str(k)) | |
for name, devids in devices.items(): | |
data.append(("GPU " + ",".join(devids), name)) | |
if has_rocm: | |
msg = " - invalid!" if not (ROCM_HOME and os.path.isdir(ROCM_HOME)) else "" | |
data.append(("ROCM_HOME", str(ROCM_HOME) + msg)) | |
else: | |
msg = " - invalid!" if not (CUDA_HOME and os.path.isdir(CUDA_HOME)) else "" | |
data.append(("CUDA_HOME", str(CUDA_HOME) + msg)) | |
cuda_arch_list = os.environ.get("TORCH_CUDA_ARCH_LIST", None) | |
if cuda_arch_list: | |
data.append(("TORCH_CUDA_ARCH_LIST", cuda_arch_list)) | |
data.append(("Pillow", PIL.__version__)) | |
try: | |
data.append( | |
( | |
"torchvision", | |
str(torchvision.__version__) + " @" + os.path.dirname(torchvision.__file__), | |
) | |
) | |
if has_cuda: | |
try: | |
torchvision_C = importlib.util.find_spec("torchvision._C").origin | |
msg = detect_compute_compatibility(CUDA_HOME, torchvision_C) | |
data.append(("torchvision arch flags", msg)) | |
except ImportError: | |
data.append(("torchvision._C", "Not found")) | |
except AttributeError: | |
data.append(("torchvision", "unknown")) | |
try: | |
import fvcore | |
data.append(("fvcore", fvcore.__version__)) | |
except ImportError: | |
pass | |
try: | |
import cv2 | |
data.append(("cv2", cv2.__version__)) | |
except ImportError: | |
data.append(("cv2", "Not found")) | |
env_str = tabulate(data) + "\n" | |
env_str += collect_torch_env() | |
return env_str | |
if __name__ == "__main__": | |
try: | |
from detectron2.utils.collect_env import collect_env_info as f | |
print(f()) | |
except ImportError: | |
print(collect_env_info()) | |
if torch.cuda.is_available(): | |
for k in range(torch.cuda.device_count()): | |
device = f"cuda:{k}" | |
try: | |
x = torch.tensor([1, 2.0], dtype=torch.float32) | |
x = x.to(device) | |
except Exception as e: | |
print( | |
f"Unable to copy tensor to device={device}: {e}. " | |
"Your CUDA environment is broken." | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment