Skip to content

Commit

Permalink
[Misc] Add generated git commit hash as vllm.__commit__ (#6386)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgoin authored Jul 12, 2024
1 parent 75f64d8 commit 111fc6e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# vllm commit id, generated by setup.py
vllm/commit_id.py

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
24 changes: 24 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import subprocess
import sys
import warnings
from shutil import which
from typing import Dict, List

Expand All @@ -26,6 +27,29 @@ def load_module_from_path(module_name, path):
ROOT_DIR = os.path.dirname(__file__)
logger = logging.getLogger(__name__)


def embed_commit_hash():
try:
commit_id = subprocess.check_output(["git", "rev-parse", "HEAD"],
encoding="utf-8").strip()
commit_contents = f'__commit__ = "{commit_id}"\n'

version_file = os.path.join(ROOT_DIR, "vllm", "commit_id.py")
with open(version_file, "w", encoding="utf-8") as f:
f.write(commit_contents)

except subprocess.CalledProcessError as e:
warnings.warn(f"Failed to get commit hash:\n{e}",
RuntimeWarning,
stacklevel=2)
except Exception as e:
warnings.warn(f"Failed to embed commit hash:\n{e}",
RuntimeWarning,
stacklevel=2)


embed_commit_hash()

# cannot import envs directly because it depends on vllm,
# which is not installed yet
envs = load_module_from_path('envs', os.path.join(ROOT_DIR, 'vllm', 'envs.py'))
Expand Down
7 changes: 7 additions & 0 deletions tests/test_embedded_commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import vllm


def test_embedded_commit_defined():
assert vllm.__commit__ != "COMMIT_HASH_PLACEHOLDER"
# 7 characters is the length of a short commit hash
assert len(vllm.__commit__) >= 7
3 changes: 2 additions & 1 deletion vllm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
from vllm.pooling_params import PoolingParams
from vllm.sampling_params import SamplingParams

from .version import __version__
from .version import __commit__, __version__

__all__ = [
"__commit__",
"__version__",
"LLM",
"ModelRegistry",
Expand Down
11 changes: 11 additions & 0 deletions vllm/version.py
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
import warnings

try:
import vllm.commit_id
__commit__ = vllm.commit_id.__commit__
except Exception as e:
warnings.warn(f"Failed to read commit hash:\n{e}",
RuntimeWarning,
stacklevel=2)
__commit__ = "COMMIT_HASH_PLACEHOLDER"

__version__ = "0.5.1"

0 comments on commit 111fc6e

Please sign in to comment.