|
3 | 3 | import collections |
4 | 4 | import dataclasses |
5 | 5 | import enum |
| 6 | +import importlib.metadata |
| 7 | +import os |
| 8 | +import subprocess |
6 | 9 | from typing import Any, Callable |
7 | 10 |
|
8 | 11 | from absl import logging |
|
11 | 14 | import numpy as np |
12 | 15 | from tunix.utils import env_utils |
13 | 16 |
|
| 17 | +try: |
| 18 | + import vllm # pylint: disable=g-import-not-at-top |
| 19 | +except ImportError: |
| 20 | + vllm = None |
| 21 | + |
| 22 | + |
| 23 | +def _get_module_info( |
| 24 | + module: Any, path_for_git: str = "", package_name: str = "" |
| 25 | +) -> tuple[str, str]: |
| 26 | + """Resolves (version, commit) concisely for environment fingerprinting.""" |
| 27 | + if module is None and not package_name and not path_for_git: |
| 28 | + return "not_installed", "not_installed" |
| 29 | + |
| 30 | + ver = getattr(module, "__version__", "") |
| 31 | + if package_name: |
| 32 | + try: |
| 33 | + ver = importlib.metadata.version(package_name) |
| 34 | + except Exception: |
| 35 | + pass |
| 36 | + ver = ver or "unknown" |
| 37 | + |
| 38 | + commit = "" |
| 39 | + path = path_for_git or getattr(module, "__file__", "") |
| 40 | + if path and os.path.exists(path): |
| 41 | + try: |
| 42 | + d = os.path.dirname(path) if os.path.isfile(path) else path |
| 43 | + commit = subprocess.check_output( |
| 44 | + ["git", "rev-parse", "HEAD"], cwd=d, stderr=subprocess.DEVNULL, text=True |
| 45 | + ).strip() |
| 46 | + except Exception: |
| 47 | + pass |
| 48 | + |
| 49 | + commit = commit or (ver.split("+")[-1] if "+" in ver else "unknown") |
| 50 | + return ver, commit |
| 51 | + |
14 | 52 | LoggingBackend = metrax_logging.LoggingBackend |
15 | 53 | TensorboardBackend = metrax_logging.TensorboardBackend |
16 | 54 | WandbBackend = metrax_logging.WandbBackend |
@@ -55,6 +93,16 @@ def create_backends(self) -> list[LoggingBackend]: |
55 | 93 | if jax.process_index() != 0: |
56 | 94 | return [] |
57 | 95 |
|
| 96 | + tunix_version, tunix_commit = _get_module_info( |
| 97 | + None, path_for_git=__file__, package_name="google-tunix" |
| 98 | + ) |
| 99 | + vllm_version, vllm_commit = _get_module_info(vllm) |
| 100 | + |
| 101 | + logging.info("=== Tunix Environment Fingerprint ===") |
| 102 | + logging.info("Tunix: version=%s, commit=%s", tunix_version, tunix_commit) |
| 103 | + logging.info("vLLM: version=%s, commit=%s", vllm_version, vllm_commit) |
| 104 | + logging.info("=====================================") |
| 105 | + |
58 | 106 | # Case 1: Override. Use user-provided factories. |
59 | 107 | if ( |
60 | 108 | "custom_backend" in self.backend_kwargs |
@@ -83,7 +131,13 @@ def create_backends(self) -> list[LoggingBackend]: |
83 | 131 | ) |
84 | 132 | ) |
85 | 133 | try: |
86 | | - wandb_kwargs = kwargs_dict.get("wandb", {}) |
| 134 | + wandb_kwargs = dict(kwargs_dict.get("wandb", {})) |
| 135 | + wandb_config = dict(wandb_kwargs.get("config", {})) |
| 136 | + wandb_config["tunix_version"] = tunix_version |
| 137 | + wandb_config["tunix_commit"] = tunix_commit |
| 138 | + wandb_config["vllm_version"] = vllm_version |
| 139 | + wandb_config["vllm_commit"] = vllm_commit |
| 140 | + wandb_kwargs["config"] = wandb_config |
87 | 141 | active_backends.append( |
88 | 142 | WandbBackend( |
89 | 143 | project=self.project_name, |
|
0 commit comments