From 36b83d704f0aa2a89b5e613da307f63d96527947 Mon Sep 17 00:00:00 2001 From: Ilyas Moutawwakil <57442720+IlyasMoutawwakil@users.noreply.github.com> Date: Thu, 19 Oct 2023 21:01:10 +0200 Subject: [PATCH] Report lib SHA (#72) --- optimum_benchmark/env_utils.py | 16 ++++++++++++++++ optimum_benchmark/experiment.py | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/optimum_benchmark/env_utils.py b/optimum_benchmark/env_utils.py index 258dbb64..a5bc424b 100644 --- a/optimum_benchmark/env_utils.py +++ b/optimum_benchmark/env_utils.py @@ -88,3 +88,19 @@ def get_gpus(): gpus = ["GPUs not available"] return gpus + + +def get_git_revision_hash(path: Optional[str]) -> str: + """ + Returns the git commit SHA for the git repository in `path`. + """ + if path is None: + return None + else: + try: + return subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=path).decode("ascii").strip() + except Exception as e: + LOGGER.warning( + f"Asked to log the git commit SHA for {path}, but it does not appear to be a git repository: {e}" + ) + return None diff --git a/optimum_benchmark/experiment.py b/optimum_benchmark/experiment.py index 6941c66a..bd82c8a4 100644 --- a/optimum_benchmark/experiment.py +++ b/optimum_benchmark/experiment.py @@ -16,7 +16,7 @@ from .backends.text_generation_inference.config import TGIConfig from .benchmarks.inference.config import InferenceConfig from .benchmarks.training.config import TrainingConfig -from .env_utils import get_cpu, get_cpu_ram_mb, get_gpus +from .env_utils import get_cpu, get_cpu_ram_mb, get_git_revision_hash, get_gpus from .import_utils import ( accelerate_version, diffusers_version, @@ -66,9 +66,13 @@ class ExperimentConfig: environment: Dict = field( default_factory=lambda: { "optimum_version": optimum_version(), + "optimum_commit": get_git_revision_hash(os.environ.get("OPTIMUM_PATH")), "transformers_version": transformers_version(), + "transformers_commit": get_git_revision_hash(os.environ.get("TRANSFORMERS_PATH")), "accelerate_version": accelerate_version(), + "accelerate_commit": get_git_revision_hash(os.environ.get("ACCELERATE_PATH")), "diffusers_version": diffusers_version(), + "diffusers_commit": get_git_revision_hash(os.environ.get("DIFFUSERS_PATH")), "python_version": platform.python_version(), "system": platform.system(), "cpu": get_cpu(),