Skip to content

Commit f47061d

Browse files
committed
fix: probe venv Python and merge multiple pip freeze sources
- Auto-detect container Python venv (/opt/dynamo/venv/bin/python3) for framework version probes — system python3 misses venv-installed packages - Merge pip freeze output from venv python, system python, bare pip, and uv pip freeze — different install methods show different packages - Deduplicate across sources via set merge
1 parent e3df22f commit f47061d

2 files changed

Lines changed: 35 additions & 16 deletions

File tree

src/srtctl/core/fingerprint.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,29 @@ def run(cmd, timeout=5):
594594
except Exception:
595595
return None
596596
597+
def find_python():
598+
for p in ['/opt/dynamo/venv/bin/python3', '/opt/venv/bin/python3', 'python3']:
599+
if run(f'command -v {{0}} || test -x {{0}}'.format(p)):
600+
return p
601+
return 'python3'
602+
603+
PY = find_python()
604+
597605
def pip_pkgs():
598-
out = run('python3 -m pip freeze 2>/dev/null') or run('pip freeze')
599-
if not out: return []
600-
return sorted([l.strip() for l in out.splitlines() if l.strip()], key=lambda s: s.lower())
606+
pkgs = set()
607+
for cmd in [
608+
f'{{PY}} -m pip freeze 2>/dev/null'.format(PY=PY),
609+
'python3 -m pip freeze 2>/dev/null',
610+
'pip freeze 2>/dev/null',
611+
'uv pip freeze 2>/dev/null',
612+
]:
613+
out = run(cmd)
614+
if out:
615+
for line in out.splitlines():
616+
line = line.strip()
617+
if line and not line.startswith('#'):
618+
pkgs.add(line)
619+
return sorted(pkgs, key=lambda s: s.lower())
601620
602621
def gpu_info():
603622
out = run('nvidia-smi --query-gpu=name,driver_version,memory.total --format=csv,noheader')
@@ -611,19 +630,19 @@ def gpu_info():
611630
612631
def framework_versions():
613632
versions = {{}}
614-
for name, cmd in [
615-
('vllm', 'python3 -c "import vllm; print(vllm.__version__)"'),
616-
('sglang', 'python3 -c "import sglang; print(sglang.__version__)"'),
617-
('tensorrt_llm', 'python3 -c "import tensorrt_llm; print(tensorrt_llm.__version__)"'),
618-
('dynamo', 'python3 -c "import importlib.metadata; print(importlib.metadata.version(\\\"ai-dynamo\\\"))"'),
633+
for name, mod in [
634+
('vllm', 'vllm'),
635+
('sglang', 'sglang'),
636+
('tensorrt_llm', 'tensorrt_llm'),
637+
('torch', 'torch'),
619638
]:
620-
v = run(cmd)
639+
v = run(f'{{PY}} -c "import {{mod}}; print({{mod}}.__version__)"'.format(PY=PY, mod=mod))
621640
if v:
622641
versions[name] = v
623-
# torch embeds a git hash in the version string (e.g. 2.10.0a0+b4e4ee81d3.nv25.12)
624-
torch_v = run('python3 -c "import torch; print(torch.__version__)"')
625-
if torch_v:
626-
versions['torch'] = torch_v
642+
# dynamo uses ai-dynamo package name
643+
v = run(f"{{PY}} -c \\"import importlib.metadata; print(importlib.metadata.version('ai-dynamo'))\\"".format(PY=PY))
644+
if v:
645+
versions['dynamo'] = v
627646
return versions
628647
629648
def model_identity(model_path):
@@ -666,7 +685,7 @@ def model_identity(model_path):
666685
'gpu': gpu_info(),
667686
'python_version': platform.python_version(),
668687
'cuda_version': run('nvcc --version 2>/dev/null | grep release') or 'unavailable',
669-
'nccl_version': run('python3 -c "import torch; print(torch.cuda.nccl.version())"') or 'unavailable',
688+
'nccl_version': run(f'{{PY}} -c "import torch; print(torch.cuda.nccl.version())"'.format(PY=PY)) or 'unavailable',
670689
'frameworks': framework_versions(),
671690
'model': model_identity('/model'),
672691
'pip_packages': pip_pkgs(),

tests/test_fingerprint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,9 @@ def test_script_starts_with_python(self):
540540
assert script.startswith('python3')
541541

542542
def test_script_includes_pip_freeze(self):
543-
"""Script captures pip packages via python3 -m pip freeze."""
543+
"""Script captures pip packages via pip freeze."""
544544
script = generate_capture_script("/logs/fp.json")
545-
assert "python3 -m pip freeze" in script
545+
assert "pip freeze" in script
546546

547547
def test_script_includes_sorted(self):
548548
"""Script sorts pip output for deterministic diffs."""

0 commit comments

Comments
 (0)