Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Moved environment collection script outside of lib #96

Merged
merged 7 commits into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ Steps to reproduce the behavior:
## Environment

Please copy and paste the output from our
[environment collection script](https://raw.githubusercontent.com/pyronear/PyroNear/master/pyro-vision/utils/collect_env.py)
[environment collection script](https://raw.githubusercontent.com/pyronear/pyro-vision/master/scripts/collect_env.py)
(or fill out the checklist below manually).

You can get the script and run it with:
```
wget https://raw.githubusercontent.com/pyronear/PyroNear/master/pyro-vision/utils/collect_env.py
wget https://raw.githubusercontent.com/pyronear/pyro-vision/master/scripts/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
```

- Pyrovision Version (e.g., 1.0.0):
- PyTorch Version (e.g., 1.2):
- Torchvision Version (e.g., 0.4):
- OS (e.g., Linux):
- How you installed PyTorch (`conda`, `pip`, source):
- How you installed Pyrovision (`conda`, `pip`, source):
- Python version:
- CUDA/cuDNN version:
- GPU models and configuration:
Expand Down
3 changes: 0 additions & 3 deletions pyrovision/utils/__init__.py

This file was deleted.

118 changes: 16 additions & 102 deletions pyrovision/utils/collect_env.py → scripts/collect_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
import os
from collections import namedtuple

try:
import pyrovision
PYROVISION_AVAILABLE = True
except (ImportError, NameError, AttributeError):
PYROVISION_AVAILABLE = False

try:
import torch
TORCH_AVAILABLE = True
Expand All @@ -31,24 +37,19 @@

PY3 = sys.version_info >= (3, 0)


# System Environment Information
SystemEnv = namedtuple('SystemEnv', [
'pyrovision_version',
'torch_version',
'torchvision_version',
'is_debug_build',
'cuda_compiled_version',
'gcc_version',
'cmake_version',
'os',
'python_version',
'is_cuda_available',
'cuda_runtime_version',
'nvidia_driver_version',
'nvidia_gpu_models',
'cudnn_version',
'pip_version', # 'pip' or 'pip3'
'pip_packages',
'conda_packages',
])


Expand Down Expand Up @@ -84,28 +85,6 @@ def run_and_parse_first_match(run_lambda, command, regex):
return match.group(1)


def get_conda_packages(run_lambda):
if get_platform() == 'win32':
grep_cmd = r'findstr /R "torchvision torch soumith mkl magma"'
else:
grep_cmd = r'grep "torchvision\|torch\|soumith\|mkl\|magma"'
conda = os.environ.get('CONDA_EXE', 'conda')
out = run_and_read_all(run_lambda, conda + ' list | ' + grep_cmd)
if out is None:
return out
# Comment starting at beginning of line
comment_regex = re.compile(r'^#.*\n')
return re.sub(comment_regex, '', out)


def get_gcc_version(run_lambda):
return run_and_parse_first_match(run_lambda, 'gcc --version', r'gcc (.*)')


def get_cmake_version(run_lambda):
return run_and_parse_first_match(run_lambda, 'cmake --version', r'cmake (.*)')


def get_nvidia_driver_version(run_lambda):
if get_platform() == 'darwin':
cmd = 'kextstat | grep -i cuda'
Expand Down Expand Up @@ -234,93 +213,52 @@ def get_os(run_lambda):
return platform


def get_pip_packages(run_lambda):
# People generally have `pip` as `pip` or `pip3`
def run_with_pip(pip):
if get_platform() == 'win32':
grep_cmd = r'findstr /R "numpy torch torchvision"'
else:
grep_cmd = r'grep "torchvision\|torch\|numpy"'
return run_and_read_all(run_lambda, pip + ' list --format=freeze | ' + grep_cmd)

if not PY3:
return 'pip', run_with_pip('pip')

# Try to figure out if the user is running pip or pip3.
out2 = run_with_pip('pip')
out3 = run_with_pip('pip3')

num_pips = len([x for x in [out2, out3] if x is not None])
if num_pips == 0:
return 'pip', out2

if num_pips == 1:
if out2 is not None:
return 'pip', out2
return 'pip3', out3

# num_pips is 2. Return pip3 by default b/c that most likely
# is the one associated with Python 3
return 'pip3', out3


def get_env_info():
run_lambda = run
pip_version, pip_list_output = get_pip_packages(run_lambda)

if PYROVISION_AVAILABLE:
pyrovision_str = pyrovision.__version__
else:
pyrovision_str = 'N/A'

if TORCH_AVAILABLE:
torch_str = torch.__version__
debug_mode_str = torch.version.debug
cuda_available_str = torch.cuda.is_available()
cuda_version_str = torch.version.cuda
else:
torch_str = debug_mode_str = cuda_available_str = cuda_version_str = 'N/A'
torch_str = cuda_available_str = 'N/A'

if VISION_AVAILABLE:
torchvision_str = torchvision.__version__
else:
torchvision_str = 'N/A'

return SystemEnv(
pyrovision_version=pyrovision_str,
torch_version=torch_str,
torchvision_version=torchvision_str,
is_debug_build=debug_mode_str,
python_version='{}.{}'.format(sys.version_info[0], sys.version_info[1]),
is_cuda_available=cuda_available_str,
cuda_compiled_version=cuda_version_str,
cuda_runtime_version=get_running_cuda_version(run_lambda),
nvidia_gpu_models=get_gpu_info(run_lambda),
nvidia_driver_version=get_nvidia_driver_version(run_lambda),
cudnn_version=get_cudnn_version(run_lambda),
pip_version=pip_version,
pip_packages=pip_list_output,
conda_packages=get_conda_packages(run_lambda),
os=get_os(run_lambda),
gcc_version=get_gcc_version(run_lambda),
cmake_version=get_cmake_version(run_lambda),
)


env_info_fmt = """
Pyrovision version: {pyrovision_version}
PyTorch version: {torch_version}
Is debug build: {is_debug_build}
CUDA used to build PyTorch: {cuda_compiled_version}
Torchvision version: {torchvision_version}

OS: {os}
GCC version: {gcc_version}
CMake version: {cmake_version}

Python version: {python_version}
Is CUDA available: {is_cuda_available}
CUDA runtime version: {cuda_runtime_version}
GPU models and configuration: {nvidia_gpu_models}
Nvidia driver version: {nvidia_driver_version}
cuDNN version: {cudnn_version}

Versions of relevant libraries:
{pip_packages}
{conda_packages}
""".strip()


Expand All @@ -340,16 +278,6 @@ def replace_bools(dct, true='Yes', false='No'):
dct[key] = false
return dct

def prepend(text, tag='[prepend]'):
lines = text.split('\n')
updated_lines = [tag + line for line in lines]
return '\n'.join(updated_lines)

def replace_if_empty(text, replacement='No relevant packages'):
if text is not None and len(text) == 0:
return replacement
return text

def maybe_start_on_next_line(string):
# If `string` is multiline, prepend a \n to it.
if string is not None and len(string.split('\n')) > 1:
Expand All @@ -374,27 +302,13 @@ def maybe_start_on_next_line(string):
if TORCH_AVAILABLE and not torch.cuda.is_available() and all_dynamic_cuda_fields_missing:
for field in all_cuda_fields:
mutable_dict[field] = 'No CUDA'
if envinfo.cuda_compiled_version is None:
mutable_dict['cuda_compiled_version'] = 'None'

# Replace True with Yes, False with No
mutable_dict = replace_bools(mutable_dict)

# Replace all None objects with 'Could not collect'
mutable_dict = replace_nones(mutable_dict)

# If either of these are '', replace with 'No relevant packages'
mutable_dict['pip_packages'] = replace_if_empty(mutable_dict['pip_packages'])
mutable_dict['conda_packages'] = replace_if_empty(mutable_dict['conda_packages'])

# Tag conda and pip packages with a prefix
# If they were previously None, they'll show up as ie '[conda] Could not collect'
if mutable_dict['pip_packages']:
mutable_dict['pip_packages'] = prepend(mutable_dict['pip_packages'],
'[{}] '.format(envinfo.pip_version))
if mutable_dict['conda_packages']:
mutable_dict['conda_packages'] = prepend(mutable_dict['conda_packages'],
'[conda] ')
return env_info_fmt.format(**mutable_dict)


Expand Down