소스 검색

chore: add commit hash, clean up engine logs

AlpinDale 6 달 전
부모
커밋
0c17c2a8a7
5개의 변경된 파일87개의 추가작업 그리고 22개의 파일을 삭제
  1. 1 0
      .gitignore
  2. 3 1
      aphrodite/__init__.py
  3. 42 21
      aphrodite/engine/aphrodite_engine.py
  4. 12 0
      aphrodite/version.py
  5. 29 0
      setup.py

+ 1 - 0
.gitignore

@@ -11,6 +11,7 @@ conda/
 umamba.exe
 bin/
 *.whl
+aphrodite/commit_id.py
 # Byte-compiled / optimized / DLL files
 __pycache__/
 *.py[cod]

+ 3 - 1
aphrodite/__init__.py

@@ -9,9 +9,11 @@ from aphrodite.engine.async_aphrodite import AsyncAphrodite
 from aphrodite.executor.ray_utils import initialize_ray_cluster
 from aphrodite.modeling.models import ModelRegistry
 
-from .version import __version__
+from .version import __commit__, __short_commit__, __version__
 
 __all__ = [
+    "__commit__",
+    "__short_commit__",
     "__version__",
     "LLM",
     "ModelRegistry",

+ 42 - 21
aphrodite/engine/aphrodite_engine.py

@@ -165,27 +165,48 @@ class AphroditeEngine:
         log_stats: bool,
         stat_loggers: Optional[Dict[str, StatLoggerBase]] = None,
     ) -> None:
-        logger.info(
-            "-" * 76 + "\n"
-            f"Initializing the Aphrodite Engine (v{APHRODITE_VERSION}) "
-            "with the following config:\n"
-            f"Model = {model_config.model!r}\n"
-            f"Speculative Config = {speculative_config!r}\n"
-            f"DataType = {model_config.dtype}\n"
-            f"Model Load Format = {load_config.load_format}\n"
-            f"Tensor Parallel Size = {parallel_config.tensor_parallel_size}\n"
-            f"Pipeline Parallel Size = {parallel_config.pipeline_parallel_size}\n"  # noqa: E501
-            f"Disable Custom All-Reduce = "
-            f"{parallel_config.disable_custom_all_reduce}\n"
-            f"Quantization Format = {model_config.quantization}\n"
-            f"Context Length = {model_config.max_model_len}\n"
-            f"Enforce Eager Mode = {model_config.enforce_eager}\n"
-            f"Prefix Caching = {cache_config.enable_prefix_caching}\n"
-            f"KV Cache DataType = {cache_config.cache_dtype}\n"
-            f"Device = {device_config.device}\n"
-            f"Rope Scaling = {model_config.rope_scaling}\n"
-            f"Guided Decoding Backend = {decoding_config!r}\n")
-        logger.info("-" * 76)
+        try:
+            import aphrodite.commit_id
+            commit_id = True
+        except ImportError:
+            commit_id = False
+
+        config_dict = {
+            "Model": model_config.model,
+            "Speculative Config": speculative_config,
+            "DataType": model_config.dtype,
+            "Model Load Format": load_config.load_format,
+            "Tensor Parallel Size": parallel_config.tensor_parallel_size,
+            "Pipeline Parallel Size": parallel_config.pipeline_parallel_size,
+            "Disable Custom All-Reduce":
+            parallel_config.disable_custom_all_reduce,
+            "Quantization Format": model_config.quantization,
+            "Context Length": model_config.max_model_len,
+            "Enforce Eager Mode": model_config.enforce_eager,
+            "Prefix Caching": cache_config.enable_prefix_caching,
+            "KV Cache DataType": cache_config.cache_dtype,
+            "Device": device_config.device,
+            "Rope Scaling": model_config.rope_scaling,
+            "Guided Decoding Backend": decoding_config
+        }
+
+        logger.info("-" * 85)
+        if not commit_id:
+            logger.info(
+                f"Initializing Aphrodite Engine (v{APHRODITE_VERSION}) "
+                "with the following config:")
+        else:
+            logger.info(f"Initializing Aphrodite Engine (v{APHRODITE_VERSION} "
+                        f"commit {aphrodite.__short_commit__}) with the "
+                        "following config:")
+
+        for key, value in config_dict.items():
+            if value is not None and not ((key == "Model Load Format" or key ==\
+                                           "KV Cache DataType") and value == \
+                                            "auto"):
+                logger.info(f"{key} = {value!r}")
+
+        logger.info("-" * 85)
         # TODO: Print more configs in debug mode.
 
         self.model_config = model_config

+ 12 - 0
aphrodite/version.py

@@ -1 +1,13 @@
+import warnings
+
+try:
+    import aphrodite.commit_id
+    __commit__ = aphrodite.commit_id.__commit__
+    __short_commit__ = aphrodite.commit_id.__short_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.4-dev"

+ 29 - 0
setup.py

@@ -4,6 +4,7 @@ import os
 import re
 import subprocess
 import sys
+import warnings
 from shutil import which
 from typing import List
 
@@ -18,6 +19,34 @@ logger = logging.getLogger(__name__)
 # Target device of Aphrodite, supporting [cuda (by default), rocm, neuron, cpu]
 APHRODITE_TARGET_DEVICE = os.getenv("APHRODITE_TARGET_DEVICE", "cuda")
 
+
+def embed_commit_hash():
+    try:
+        commit_id = subprocess.check_output(["git", "rev-parse", "HEAD"],
+                                            encoding="utf-8").strip()
+        short_commit_id = subprocess.check_output(
+            ["git", "rev-parse", "--short", "HEAD"], encoding="utf-8").strip()
+
+        commit_contents = f'__commit__ = "{commit_id}"\n'
+        short_commit_contents = f'__short_commit__ = "{short_commit_id}"\n'
+
+        version_file = os.path.join(ROOT_DIR, "aphrodite", "commit_id.py")
+        with open(version_file, "w", encoding="utf-8") as f:
+            f.write(commit_contents)
+            f.write(short_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()
+
 # Aphrodite only supports Linux platform
 assert sys.platform.startswith(
     "linux"), "Aphrodite only supports Linux platform (including WSL)."