Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
16 changes: 16 additions & 0 deletions python/sglang/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

from sglang.cli.generate import generate
from sglang.cli.serve import serve
from sglang.cli.utils import get_git_commit_hash
from sglang.version import __version__


def version(args, extra_argv):
print(f"sglang version: {__version__}")
print(f"git revision: {get_git_commit_hash()[:7]}")


def main():
parser = argparse.ArgumentParser()

# complex sub commands
subparsers = parser.add_subparsers(dest="subcommand", required=True)

serve_parser = subparsers.add_parser(
Expand All @@ -22,5 +31,12 @@ def main():
)
generate_parser.set_defaults(func=generate)

# simple commands
version_parser = subparsers.add_parser(
"version",
help="Show the version information.",
)
version_parser.set_defaults(func=version)

args, extra_argv = parser.parse_known_args()
args.func(args, extra_argv)
21 changes: 21 additions & 0 deletions python/sglang/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import json
import logging
import os
import subprocess
import tempfile
from functools import lru_cache
from typing import Optional

import filelock
Expand Down Expand Up @@ -150,3 +152,22 @@ def get_model_path(extra_argv):
"Please provide the path to the model."
)
return model_path


@lru_cache(maxsize=1)
def get_git_commit_hash() -> str:
try:
commit_hash = os.environ.get("SGLANG_GIT_COMMIT")
if not commit_hash:
commit_hash = (
subprocess.check_output(
["git", "rev-parse", "HEAD"], stderr=subprocess.DEVNULL
)
.strip()
.decode("utf-8")
)
_CACHED_COMMIT_HASH = commit_hash
return commit_hash
except (subprocess.CalledProcessError, FileNotFoundError):
_CACHED_COMMIT_HASH = "N/A"
return "N/A"
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def load(
"""
gpu_mem_before_loading = current_platform.get_available_gpu_memory()
logger.info(
"Loading %s. avail mem: %.2f GB",
"Loading %s from %s. avail mem: %.2f GB",
module_name,
component_model_path,
gpu_mem_before_loading,
Expand Down
23 changes: 20 additions & 3 deletions python/sglang/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
try:
from sglang._version import __version__, __version_tuple__
except ImportError:
# Fallback for development without build
__version__ = "0.0.0.dev0"
__version_tuple__ = (0, 0, 0, "dev0")
try:
import importlib.metadata

__version__ = importlib.metadata.version("sglang")
__version_tuple__ = tuple(__version__.split("."))
except Exception:
try:
from setuptools_scm import get_version
import pathlib

# The root of the project is two levels up from this file's directory (python/sglang/version.py -> python/)
# But according to pyproject.toml, the scm root is ".." (the repo root).
# So we point to the directory containing pyproject.toml.
project_root = pathlib.Path(__file__).parent.parent.parent
__version__ = get_version(root=str(project_root), fallback_version="0.0.0.dev0")
__version_tuple__ = tuple(__version__.split("."))
except Exception:
# Fallback for development without build
__version__ = "0.0.0.dev0"
__version_tuple__ = (0, 0, 0, "dev0")
Loading