Skip to content

Commit

Permalink
Merge pull request #803 from scap3yvt/802-add-a-script-to-generate-in…
Browse files Browse the repository at this point in the history
…formation-useful-for-debugging

Added a script to generate information useful for debugging
  • Loading branch information
sarthakpati authored Feb 16, 2024
2 parents 3af7fff + 94d13ec commit 8b1f881
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 18 deletions.
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 @@ def determine_classification_task_type(params: dict) -> str:
"""
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"
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()))}")

0 comments on commit 8b1f881

Please sign in to comment.