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

Added a script to generate information useful for debugging #803

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
8 changes: 5 additions & 3 deletions .github/ISSUE_TEMPLATE/---bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ python -c 'import GANDLF as g;print(g.__version__)'
-->
Version information of the GaNDLF package in the virtual environment.

**Desktop (please complete the following information):**
- OS: [e.g. Windows/Linux (include detailed distro information)/macOS]
- Version (including Build information, if any): [e.g. Fedora 22 or Windows 10.1803]
**Environment information:**
<!-- Put the output of the following command:
python ./gandlf_debugInfo
-->
OS, hardware, and so on.

**Additional context**
Add any other context about the problem here.
1 change: 1 addition & 0 deletions GANDLF/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
print_and_format_metrics,
determine_classification_task_type,
getBase2,
get_git_hash,
)

from .modelio import (
Expand Down
20 changes: 19 additions & 1 deletion GANDLF/utils/generic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, datetime, sys
import os, datetime, subprocess, sys
from copy import deepcopy
import random
import numpy as np
Expand Down Expand Up @@ -329,3 +329,21 @@
"""
task = "binary" if params["model"]["num_classes"] == 2 else "multiclass"
return task


def get_git_hash() -> str:
"""
Get the git hash of the current commit.

Returns:
str: The git hash of the current commit.
"""
try:
git_hash = (
subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=os.getcwd())
.decode("ascii")
.strip()
)
except (subprocess.CalledProcessError, FileNotFoundError):
git_hash = "None"

Check warning on line 348 in GANDLF/utils/generic.py

View check run for this annotation

Codecov / codecov/patch

GANDLF/utils/generic.py#L347-L348

Added lines #L347 - L348 were not covered by tests
return git_hash
17 changes: 3 additions & 14 deletions GANDLF/utils/modelio.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import hashlib
import os
import subprocess
import hashlib, os
from typing import Any, Dict, Optional, Tuple

import torch

from ..version import __version__
from .generic import get_unique_timestamp
from .generic import get_unique_timestamp, get_git_hash

# these are the base keys for the model dictionary to save
model_dict_full = {
Expand Down Expand Up @@ -155,16 +153,7 @@ def save_model(
).hexdigest()
model_dict["version"] = __version__
model_dict["parameters"] = params

try:
# this will try to encode the git hash of the current GaNDLF codebase, and reverts to "None" if not found
model_dict["git_hash"] = (
subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=os.getcwd())
.decode("ascii")
.strip()
)
except (subprocess.CalledProcessError, FileNotFoundError):
model_dict["git_hash"] = "None"
model_dict["git_hash"] = get_git_hash()

torch.save(model_dict, path)

Expand Down
20 changes: 20 additions & 0 deletions gandlf_debugInfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!usr/bin/env python
# -*- coding: utf-8 -*-
import platform

from GANDLF import __version__
from GANDLF.utils import get_git_hash


if __name__ == "__main__":
print(f"GANDLF version: {__version__}")
print(f"Git hash: {get_git_hash()}")
print(f"Platform: {platform.platform()}")
print(f"Machine: {platform.machine()}")
print(f"Processor: {platform.processor()}")
print(f"Architecture: {(' ').join(list(platform.architecture()))}")
print("Python environment:")
print(f" Version: {platform.python_version()}")
print(f" Implementation: {platform.python_implementation()}")
print(f" Compiler: {platform.python_compiler()}")
print(f" Build: {(' ').join(list(platform.python_build()))}")
Loading