HexaGrid / utils /version_info.py
Surn's picture
Merge from Main repository
6ef117e
raw
history blame
2.69 kB
# utils/version_info.py
import subprocess
import os
import torch
import sys
import gradio as gr
git = os.environ.get('GIT', "git")
def commit_hash():
try:
return subprocess.check_output([git, "rev-parse", "HEAD"], shell=False, encoding='utf8').strip()
except Exception:
return "<none>"
def get_xformers_version():
try:
import xformers
return xformers.__version__
except Exception:
return "<none>"
def get_transformers_version():
try:
import transformers
return transformers.__version__
except Exception:
return "<none>"
def get_accelerate_version():
try:
import accelerate
return accelerate.__version__
except Exception:
return "<none>"
def get_safetensors_version():
try:
import safetensors
return safetensors.__version__
except Exception:
return "<none>"
def get_diffusers_version():
try:
import diffusers
return diffusers.__version__
except Exception:
return "<none>"
def get_torch_info():
try:
return [torch.__version__, f"CUDA Version:{torch.version.cuda}", f"Available:{torch.cuda.is_available()}", f"flash attention enabled: {torch.backends.cuda.flash_sdp_enabled()}", f"Capabilities: {torch.cuda.get_device_capability(0)}", f"Device Name: {torch.cuda.get_device_name(0)}"]
except Exception:
return "<none>"
def versions_html():
python_version = ".".join([str(x) for x in sys.version_info[0:3]])
commit = commit_hash()
# Define the Toggle Dark Mode link with JavaScript
toggle_dark_link = '''
<a href="#" onclick="document.body.classList.toggle('dark'); return false;" style="cursor: pointer; text-decoration: underline; color: #1a0dab;">
Toggle Dark Mode
</a>
'''
# version: <a href="https://github.com/Oncorporation/audiocraft/commit/{"" if commit == "<none>" else commit}" target="_blank">{"click" if commit == "<none>" else commit}</a>
return f"""
version: <a href="https://github.com/Oncorporation/audiocraft/commit/{"" if commit == "<none>" else commit}" target="_blank">{"click" if commit == "<none>" else commit}</a>
&#x2000;•&#x2000;
python: <span title="{sys.version}">{python_version}</span>
&#x2000;•&#x2000;
torch: {getattr(torch, '__long_version__',torch.__version__)}
&#x2000;•&#x2000;
diffusers: {get_diffusers_version()}
&#x2000;•&#x2000;
transformers: {get_transformers_version()}
&#x2000;•&#x2000;
gradio: {gr.__version__}
&#x2000;•&#x2000;
{toggle_dark_link}
"""