checkpoint: add initial CLI implementation

This commit is contained in:
RevLayDust committed 2026-09-08 17:46:31 +07:00
1 parent f62e5644f0
commit 4fdc3b43fd
19 files changed
+1714 -1361

No files matched your search

+2 -1
View File
@@ -10,7 +10,8 @@ __pycache__/
venv/
.venv/
.agents/
benchmark_cache/
benchmark_results/
uvr_run.log
data.pkl
benchmark_cache/
+4 -3
View File
@@ -1,9 +1,10 @@
# Contributions
Runtime benchmarking is recorded automatically for each top-level inference started from the UVR GUI. The implementation and output format are documented in `benchmarks/README.md`.
The CLI and performance benchmarking suite is located in `uvr_cli/`. The implementation and output format are documented in `uvr_cli/README.md`.
Do not commit private audio, model files, generated stems, or local `benchmark_cache/` logs. Before submitting recorder changes, run:
Do not commit private audio, model files, generated stems, or local `benchmark_results/` logs. Before submitting benchmark changes, run:
```powershell
venv\Scripts\python.exe -m unittest tests.test_gui_runtime_recorder tests.test_in_memory_model_cache -v
venv\Scripts\python.exe -m unittest tests.test_uvr_cli tests.test_in_memory_model_cache -v
```
+1 -1
View File
@@ -3358,7 +3358,7 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
model_precision_Label.grid(pady=MENU_PADDING_2)
model_precision_Option = ComboBoxMenu(settings_menu_format_Frame, textvariable=self.model_precision_var, values=MODEL_PRECISION_OPTIONS, width=GEN_SETTINGS_WIDTH+1)
model_precision_Option.grid(padx=20,pady=MENU_PADDING_1)
self.help_hints(model_precision_Label, text="Select precision preset:\n• Ultra Quality: FP32 (Max precision, mastering)\n• Balanced: BF16 (Recommended for general use)\n• Performance: FP16 (Fast, lower VRAM)")
self.help_hints(model_precision_Label, text="Select precision preset:\n• Ultra Quality: FP32 (Max precision, mastering)\n• Performance: FP16 (Fast, lower VRAM)")
# if is_choose_arch:
# is_use_opencl_Option = ttk.Checkbutton(settings_menu_format_Frame,
-53
View File
@@ -1,53 +0,0 @@
# GUI Runtime Benchmark Recorder
UVR records runtime benchmark metadata automatically whenever the GUI backend enters a top-level `seperate()` call after **Start Processing**. There is no benchmark CLI, case matrix, profiler command, result packager, or upload workflow.
Supported production backends:
- VR Architecture
- MDX-Net ONNX
- MDX PyTorch/MDXC
- Demucs
## Output
Each application session writes progressively to:
```text
benchmark_cache/gui_runtime/latest.txt
benchmark_cache/gui_runtime/<session>/benchmark.log
benchmark_cache/gui_runtime/<session>/inference_<number>_<model>.log
benchmark_cache/gui_runtime/<session>/inference_<number>_<model>.json
```
Every top-level audio job receives a separate block:
```text
1st Inference:
Model: <model filename>
Model round: 1
OS: <operating system>
...
Total-time: <backend entry through completed output>
=======
```
`Model round` increments while model path and requested precision remain unchanged. Changing either value resets the round to one. Nested secondary separators remain part of the parent pipeline and do not create overlapping benchmark records.
The recorder stores model identity/hash, backend, requested and effective precision, execution provider, input metadata, cache state, stage timings, total time, CPU/RAM, GPU utilization, device/Torch VRAM, power when available, output validation, warnings, and failure state. Start, progress, stage, warning, and completion data are flushed incrementally.
Recorder failures never cancel audio processing. When instrumentation setup fails, UVR continues without instrumentation and closes any record already opened with its final status and total time.
## Configuration
- Set `UVR_GUI_BENCHMARK=0` before launch to disable recording.
- Set `UVR_GUI_BENCHMARK_DIR=<directory>` to override the local output directory.
- Keep `nvidia-ml-py` installed for NVIDIA utilization, VRAM, driver, and power metadata. Missing NVML support produces a warning rather than stopping inference.
## Tests
```powershell
venv\Scripts\python.exe -m unittest tests.test_gui_runtime_recorder tests.test_in_memory_model_cache -v
```
`UVR.py` is not modified by the recorder. Hooks are installed from `separate.py` after all separator classes are defined.
-1
View File
@@ -1 +0,0 @@
"""Automatic per-inference runtime recording for the UVR GUI."""
File diff suppressed because it is too large. Load diff
+5 -3
View File
@@ -17,13 +17,15 @@ MODEL_PRECISION_BF16 = 'Balanced (BF16)'
MODEL_PRECISION_FP16 = 'Performance (FP16)'
MODEL_PRECISION_OPTIONS = (
MODEL_PRECISION_FP32,
MODEL_PRECISION_BF16,
MODEL_PRECISION_FP16,
)
MODEL_PRECISION_DEFAULT = MODEL_PRECISION_BF16
MODEL_PRECISION_DEFAULT = MODEL_PRECISION_FP16
def normalize_model_precision(value):
return value if value in MODEL_PRECISION_OPTIONS else MODEL_PRECISION_DEFAULT
if value in MODEL_PRECISION_OPTIONS or value == MODEL_PRECISION_BF16:
return value
return MODEL_PRECISION_DEFAULT
#MAIN_FONT_NAME = "Century Gothic"
OPT_SEPARATOR_SAVE = '─'*25
-5
View File
@@ -2237,9 +2237,4 @@ def loading_mix(X, mp):
return X_spec
try:
from benchmarks.gui_runtime_recorder import install_gui_runtime_benchmark_hooks
install_gui_runtime_benchmark_hooks(globals())
except Exception as gui_benchmark_error:
print(f"[Benchmark warning] GUI runtime recorder unavailable: {type(gui_benchmark_error).__name__}")
-246
View File
@@ -1,246 +0,0 @@
"""Regression coverage for automatic GUI per-inference recording."""
from __future__ import annotations
import json
import tempfile
import unittest
import wave
from pathlib import Path
from types import SimpleNamespace
from benchmarks.gui_runtime_recorder import (
GUIRuntimeBenchmarkRecorder,
install_gui_runtime_benchmark_hooks,
sha256_file,
)
class FakeCache:
def __init__(self):
self.cache = {}
def get_model(self, model_path, precision_mode=None):
normalized = str(Path(model_path).resolve())
entry = self.cache.get(normalized)
if entry and entry["precision_mode"] == precision_mode:
return entry["model_obj"]
if entry:
self.cache.pop(normalized)
return None
def set_model(self, model_path, model_obj, size_bytes=0, precision_mode=None):
self.cache[str(Path(model_path).resolve())] = {
"model_obj": model_obj,
"precision_mode": precision_mode,
}
class FakeOrtSession:
def __init__(self, precision):
self.precision = precision
def get_inputs(self):
input_type = "tensor(float16)" if "FP16" in self.precision else "tensor(float)"
return [SimpleNamespace(type=input_type)]
def get_providers(self):
return ["CUDAExecutionProvider", "CPUExecutionProvider"]
class FakeSampler:
def __init__(self, progress=None, **kwargs):
self.progress = progress or (lambda snapshot: None)
def start(self):
self.progress({
"elapsed_seconds": 0.0,
"process_cpu_percent": 12.5,
"gpu_utilization_percent": 75.0,
"device_vram_mb": 1024.0,
})
def stop(self):
return {
"sampling_interval_ms": 250.0,
"average_process_cpu_percent": 12.5,
"peak_process_cpu_percent": 20.0,
"average_system_cpu_percent": 10.0,
"peak_system_cpu_percent": 15.0,
"peak_process_ram_mb": 512.0,
"average_gpu_utilization_percent": 75.0,
"peak_gpu_utilization_percent": 90.0,
"baseline_device_vram_mb": 512.0,
"peak_device_vram_mb": 1536.0,
"average_power_w": 100.0,
"peak_power_w": 125.0,
"torch_peak_allocated_vram_mb": 768.0,
"torch_peak_reserved_vram_mb": 896.0,
"warnings": [],
}
class FailingSampler(FakeSampler):
def start(self):
raise RuntimeError("synthetic sampler failure")
class SeperateMDX:
def __init__(self, root: Path, cache: FakeCache, precision: str):
self.model_path = str(root / "UVR-MDX-NET-Test.onnx")
self.audio_file = str(root / "input.wav")
self.audio_file_base = "input"
self.export_path = str(root / "outputs")
self.model_data = SimpleNamespace(model_precision=precision, device_set="0")
self.device = "cuda:0"
self.process_data = {}
self.cache = cache
self.messages = []
def write_to_console(self, message, **kwargs):
self.messages.append(str(message))
def demix(self):
return "separated"
def write_audio(self):
output = Path(self.export_path)
output.mkdir(parents=True, exist_ok=True)
with wave.open(str(output / "input_(Vocals).wav"), "wb") as stream:
stream.setnchannels(2)
stream.setsampwidth(2)
stream.setframerate(44100)
stream.writeframes(b"\0\0\0\0" * 4410)
def seperate(self):
precision = self.model_data.model_precision
model = self.cache.get_model(self.model_path, precision_mode=precision)
if model is None:
model = FakeOrtSession(precision)
self.cache.set_model(self.model_path, model, precision_mode=precision)
self.demix()
self.write_audio()
return "done"
def fake_environment(device_index: int):
return {
"hardware": {
"os": "Test Windows",
"cpu": "Test CPU",
"gpu_name": "Test NVIDIA GPU",
},
"software": {
"python_version": "3.11",
"torch_version": "test",
},
"warnings": [],
}
class GUIRuntimeRecorderTests(unittest.TestCase):
def tearDown(self):
method = SeperateMDX.seperate
original = getattr(method, "_uvr_gui_benchmark_original", None)
if original is not None:
SeperateMDX.seperate = original
def test_blocks_are_separate_and_model_round_resets_on_precision_change(self):
project_root = Path(__file__).resolve().parents[1]
uvr_hash_before = sha256_file(project_root / "UVR.py")
with tempfile.TemporaryDirectory() as temporary:
root = Path(temporary)
(root / "UVR-MDX-NET-Test.onnx").write_bytes(b"model")
with wave.open(str(root / "input.wav"), "wb") as stream:
stream.setnchannels(2)
stream.setsampwidth(2)
stream.setframerate(44100)
stream.writeframes(b"\0\0\0\0" * 4410)
cache = FakeCache()
namespace = {
"SeperateMDX": SeperateMDX,
"MODEL_CACHE": cache,
"prepare_mix": lambda value: value,
}
recorder = GUIRuntimeBenchmarkRecorder(
namespace,
output_root=root / "runtime",
sampler_factory=FakeSampler,
environment_collector=fake_environment,
progress_interval_seconds=1.0,
)
install_gui_runtime_benchmark_hooks(namespace, recorder=recorder)
first = SeperateMDX(root, cache, "Performance (FP16)")
second = SeperateMDX(root, cache, "Performance (FP16)")
third = SeperateMDX(root, cache, "Ultra Quality (FP32)")
self.assertEqual(first.seperate(), "done")
self.assertEqual(second.seperate(), "done")
self.assertEqual(third.seperate(), "done")
session_name = (root / "runtime" / "latest.txt").read_text(encoding="utf-8").strip()
session = root / "runtime" / session_name
combined = (session / "benchmark.log").read_text(encoding="utf-8")
records = [
json.loads(path.read_text(encoding="utf-8"))
for path in sorted(session.glob("inference_*.json"))
]
self.assertIn("1st Inference:", combined)
self.assertIn("2nd Inference:", combined)
self.assertIn("3rd Inference:", combined)
self.assertEqual([record["model_round"] for record in records], [1, 2, 1])
self.assertEqual([record["status"] for record in records], ["completed"] * 3)
self.assertEqual(records[0]["runtime"]["effective_precision"], "fp16")
self.assertEqual(records[2]["runtime"]["effective_precision"], "fp32")
self.assertIn("Stage inference:", combined)
self.assertIn("Total-time:", combined)
self.assertGreaterEqual(combined.count("======="), 4)
self.assertTrue(any("[Benchmark] Recording" in message for message in first.messages))
self.assertEqual(sha256_file(project_root / "UVR.py"), uvr_hash_before)
def test_sampler_setup_failure_keeps_processing_and_closes_record(self):
with tempfile.TemporaryDirectory() as temporary:
root = Path(temporary)
(root / "UVR-MDX-NET-Test.onnx").write_bytes(b"model")
with wave.open(str(root / "input.wav"), "wb") as stream:
stream.setnchannels(2)
stream.setsampwidth(2)
stream.setframerate(44100)
stream.writeframes(b"\0\0\0\0" * 100)
cache = FakeCache()
prepare_mix = lambda value: value
namespace = {
"SeperateMDX": SeperateMDX,
"MODEL_CACHE": cache,
"prepare_mix": prepare_mix,
}
recorder = GUIRuntimeBenchmarkRecorder(
namespace,
output_root=root / "runtime",
sampler_factory=FailingSampler,
environment_collector=fake_environment,
)
install_gui_runtime_benchmark_hooks(namespace, recorder=recorder)
separator = SeperateMDX(root, cache, "Performance (FP16)")
result = separator.seperate()
session_name = (root / "runtime" / "latest.txt").read_text(encoding="utf-8").strip()
session = root / "runtime" / session_name
record_path = next(session.glob("inference_*.json"))
record = json.loads(record_path.read_text(encoding="utf-8"))
text_log = next(session.glob("inference_*.log")).read_text(encoding="utf-8")
self.assertEqual(result, "done")
self.assertEqual(record["status"], "completed")
self.assertTrue(any("Recorder setup failed" in warning for warning in record["warnings"]))
self.assertIn("Warning: Recorder setup failed: RuntimeError", text_log)
self.assertIn("Status: COMPLETED", text_log)
self.assertIn("Total-time:", text_log)
self.assertIs(namespace["prepare_mix"], prepare_mix)
self.assertNotIn("demix", separator.__dict__)
if __name__ == "__main__":
unittest.main()
+170
View File
@@ -0,0 +1,170 @@
"""Automated unit and regression tests for UVR CLI and Benchmarking suite."""
from __future__ import annotations
import csv
import json
import tempfile
import unittest
from pathlib import Path
from uvr_cli.cli import build_parser, create_synthetic_audio, normalize_cli_precision
from uvr_cli.exporter import export_benchmark_csv, export_benchmark_json, sanitize_path
from uvr_cli.model_resolver import (
HeadlessModelData,
build_headless_model_data,
list_available_models,
resolve_model_file,
)
from uvr_cli.telemetry import TelemetrySampler, collect_system_info
class BenchmarkCLITests(unittest.TestCase):
"""Test coverage for model resolution, telemetry, CLI parsing, and export."""
def test_model_discovery_finds_installed_models(self):
models = list_available_models()
self.assertIsInstance(models, list)
self.assertGreater(len(models), 0, "Should detect at least one installed UVR model")
first = models[0]
self.assertIn("name", first)
self.assertIn("architecture", first)
self.assertIn("path", first)
def test_model_resolution_and_headless_data(self):
models = list_available_models()
target = models[0]["name"]
path, arch = resolve_model_file(target)
self.assertTrue(path.is_file())
model_data = build_headless_model_data(
model_path=path,
architecture=arch,
precision="Performance (FP16)",
device="cpu",
)
self.assertIsInstance(model_data, HeadlessModelData)
self.assertEqual(model_data.process_method, arch)
self.assertEqual(model_data.model_precision, "Performance (FP16)")
self.assertIsNotNone(model_data.model_hash)
def test_telemetry_sampler_lifecycle(self):
sampler = TelemetrySampler(device_index=0, interval_sec=0.05)
sampler.start()
# Brief pause to collect samples
import time
time.sleep(0.2)
metrics = sampler.stop()
self.assertIn("avg_process_cpu_percent", metrics)
self.assertIn("peak_process_cpu_percent", metrics)
self.assertIn("peak_process_ram_mb", metrics)
self.assertIn("samples_count", metrics)
self.assertGreaterEqual(metrics["samples_count"], 1)
def test_system_info_collection(self):
info = collect_system_info(device_index=0)
self.assertIn("os", info)
self.assertIn("cpu", info)
self.assertIn("system_ram_gb", info)
self.assertIn("python_version", info)
def test_path_sanitization(self):
raw_path = r"C:\Users\JohnDoe\AppData\Local\test.wav"
sanitized = sanitize_path(raw_path)
self.assertNotIn("JohnDoe", sanitized)
self.assertIn("<user_dir>/", sanitized)
def test_export_json_and_csv(self):
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = Path(temp_dir)
json_file = temp_path / "test_session.json"
csv_file = temp_path / "summary.csv"
dummy_data = {
"session_id": "test_123",
"system_info": {"os": "TestOS"},
"summary": {"avg_total_time_sec": 1.23},
}
export_benchmark_json(dummy_data, json_file)
self.assertTrue(json_file.is_file())
with json_file.open("r", encoding="utf-8") as f:
loaded = json.load(f)
self.assertEqual(loaded["session_id"], "test_123")
dummy_rows = [{
"session_id": "test_123",
"timestamp_utc": "2026-09-06T00:00:00Z",
"gpu_name": "TestGPU",
"cpu_name": "TestCPU",
"model_name": "test_model.onnx",
"model_hash": "abc123hash",
"backend": "MDX-Net",
"precision": "Performance (FP16)",
"audio_file": "sample.wav",
"audio_duration_sec": 10.0,
"round": "1",
"cache_state": "cold",
"total_time_sec": 2.5,
"inference_time_sec": 2.5,
"speed_factor_rt": 4.0,
"peak_torch_vram_mb": 1024.0,
"peak_device_vram_mb": 2048.0,
"avg_gpu_util_percent": 85.0,
"peak_gpu_util_percent": 95.0,
"avg_cpu_util_percent": 50.0,
"peak_process_ram_mb": 512.0,
"status": "COMPLETED",
}]
export_benchmark_csv(dummy_rows, csv_file)
self.assertTrue(csv_file.is_file())
with csv_file.open("r", encoding="utf-8") as f:
reader = csv.DictReader(f)
rows = list(reader)
self.assertEqual(len(rows), 1)
self.assertEqual(rows[0]["model_name"], "test_model.onnx")
def test_cli_argument_parsing(self):
parser = build_parser()
# Test 'list-models'
args_list = parser.parse_args(["list-models"])
self.assertEqual(args_list.command, "list-models")
# Test 'run'
args_run = parser.parse_args([
"run",
"--audio", "test.wav",
"--model", "UVR-MDX-NET-Inst_HQ_4.onnx",
"--precision", "fp16",
"--device", "cuda:0",
])
self.assertEqual(args_run.command, "run")
self.assertEqual(args_run.precision, "fp16")
# Test 'bench'
args_bench = parser.parse_args([
"bench",
"--audio", "test.wav",
"--model", "UVR-MDX-NET-Inst_HQ_4.onnx",
"--rounds", "3",
"--warmup", "1",
])
self.assertEqual(args_bench.command, "bench")
self.assertEqual(args_bench.rounds, 3)
self.assertEqual(args_bench.warmup, 1)
def test_synthetic_audio_creation(self):
audio_path = create_synthetic_audio(duration_sec=1.0, samplerate=44100)
try:
self.assertTrue(audio_path.is_file())
self.assertGreater(audio_path.stat().st_size, 1000)
finally:
if audio_path.is_file():
audio_path.unlink()
if audio_path.parent.is_dir():
audio_path.parent.rmdir()
if __name__ == "__main__":
unittest.main()
+105
View File
@@ -0,0 +1,105 @@
# Ultimate Vocal Remover (UVR) - CLI & Performance Benchmark Suite
This package provides a **Command-Line Interface (CLI)** and a **Real Performance Benchmarking Suite** for UVR. It connects directly to UVR's actual inference engine in `separate.py` without requiring the Tkinter GUI or desktop automation.
---
## Folder Structure
```text
uvr_cli/
├── __init__.py # Package exports and version
├── __main__.py # Package runner for `python -m uvr_cli`
├── cli.py # Command-line interface (`run`, `bench`, `list-models`, `smoke-test`)
├── model_resolver.py # Headless model discovery & parameter builder
├── runner.py # Direct execution bridge to separate.py
├── telemetry.py # Real-time resource sampler (CPU, RAM, GPU %, VRAM, Power)
├── engine.py # Benchmark orchestrator (warmup, rounds, statistics)
├── exporter.py # Machine-readable JSON & CSV exporters with path sanitization
└── README.md # This documentation
```
---
## How It Works
1. **Headless Model Resolution (`model_resolver.py`)**:
Reads UVR's model directories (`models/MDX_Net_Models`, `models/VR_Models`, `models/Demucs_Models`), computes the exact model MD5 hash using UVR's chunked hash algorithm, and loads the model's architecture parameters (FFT, hop size, frequency bins, stems, compensation) from `model_data.json` without depending on Tkinter GUI variables.
2. **Direct Core Separation (`runner.py`)**:
Directly instantiates `SeperateMDX`, `SeperateMDXC`, `SeperateVR`, or `SeperateDemucs` from `separate.py` and triggers `.seperate()` directly.
3. **Real-time Telemetry (`telemetry.py`)**:
Runs a background sampling daemon measuring process CPU %, system CPU %, process RAM, GPU utilization %, and device VRAM. Synchronizes CUDA devices and resets PyTorch peak allocation statistics before/after inference to capture true peak VRAM.
4. **Machine-Readable Export (`exporter.py`)**:
Outputs complete structured JSON documents and appends runs to a shared tabular CSV (`summary.csv`) suitable for cross-GPU comparisons and committing to GitHub. All user profile paths are automatically redacted for privacy.
---
## CLI Commands
### 1. List Available Models
Scan and display all downloaded models across MDX-Net, VR, and Demucs:
```powershell
venv\Scripts\python.exe -m uvr_cli list-models
```
### 2. Direct Separation (CLI-Only)
Separate an audio file directly from the terminal without GUI:
```powershell
venv\Scripts\python.exe -m uvr_cli run `
--audio "path/to/song.wav" `
--model "UVR-MDX-NET-Inst_HQ_4.onnx" `
--precision fp16 `
--device cuda:0 `
--output-dir "separated_outputs"
```
Supported precisions: `fp32`, `fp16`, `fp8_e4m3`, `nvfp4`.
### 3. Real Performance Benchmark
Benchmark one or more models across multiple rounds with warmup:
```powershell
venv\Scripts\python.exe -m uvr_cli bench `
--audio "path/to/song.wav" `
--model "UVR-MDX-NET-Inst_HQ_4.onnx" `
--precision fp16 `
--rounds 3 `
--warmup 1 `
--export-dir "benchmark_results"
```
### 4. Automated Smoke Test
Run an end-to-end verification test using an automatically generated synthetic audio clip:
```powershell
venv\Scripts\python.exe -m uvr_cli smoke-test
```
---
## Output Data Format
### 1. Tabular CSV (`benchmark_results/summary.csv`)
Columns included in the CSV summary:
- `session_id`: Unique identifier for the benchmark session
- `timestamp_utc`: UTC timestamp of the run
- `gpu_name`: Hardware GPU device name
- `cpu_name`: Hardware CPU processor model
- `model_name`: File name of the model
- `model_hash`: MD5 hash of the model
- `backend`: UVR backend architecture (MDX-Net, VR Arc, Demucs)
- `precision`: Effective precision policy (FP32, FP16, BF16, etc.)
- `audio_file`: Name of the benchmarked audio file
- `audio_duration_sec`: Duration of the audio file in seconds
- `round`: Measurement round index or `warmup_1`
- `cache_state`: `cold` (first run) or `warm` (subsequent runs)
- `total_time_sec`: Total wall-clock execution time
- `inference_time_sec`: Pure inference time
- `speed_factor_rt`: Real-time processing speed multiplier (`audio_duration / total_time`)
- `peak_torch_vram_mb`: Peak VRAM allocated by PyTorch tensors (MiB)
- `peak_device_vram_mb`: Peak overall hardware VRAM in use (MiB)
- `avg_gpu_util_percent`: Average GPU core utilization percentage
- `peak_gpu_util_percent`: Peak GPU core utilization percentage
- `avg_cpu_util_percent`: Average CPU process utilization percentage
- `peak_process_ram_mb`: Peak system RAM consumed by the process (MiB)
- `status`: Execution outcome (`COMPLETED` or error)
### 2. Structured JSON (`benchmark_results/<session_id>.json`)
Contains the full system hardware report, audio metadata, model configuration parameters, individual per-round telemetry profiles, and aggregated statistics (mean, min, max).
+35
View File
@@ -0,0 +1,35 @@
"""Ultimate Vocal Remover - CLI-Only Inference & Real Performance Benchmarking Suite."""
from __future__ import annotations
from .engine import BenchmarkEngine
from .exporter import export_benchmark_csv, export_benchmark_json, sanitize_path
from .model_resolver import (
HeadlessModelData,
build_headless_model_data,
compute_uvr_hash,
list_available_models,
resolve_model_file,
)
from .runner import execute_inference, get_audio_metadata
from .telemetry import TelemetrySampler, collect_system_info, sync_cuda
__version__ = "2.0.0"
__all__ = [
"BenchmarkEngine",
"HeadlessModelData",
"TelemetrySampler",
"build_headless_model_data",
"collect_system_info",
"compute_uvr_hash",
"execute_inference",
"export_benchmark_csv",
"export_benchmark_json",
"get_audio_metadata",
"list_available_models",
"resolve_model_file",
"sanitize_path",
"sync_cuda",
"__version__",
]
+6
View File
@@ -0,0 +1,6 @@
"""Package entry point allowing execution via `python -m uvr_cli`."""
from uvr_cli.cli import main
if __name__ == "__main__":
main()
+308
View File
@@ -0,0 +1,308 @@
"""Command-Line Interface for UVR CLI-Only inference and performance benchmarking."""
from __future__ import annotations
import argparse
import sys
import tempfile
import wave
from pathlib import Path
from typing import Optional
import numpy as np
from gui_data.constants import (
MODEL_PRECISION_BF16,
MODEL_PRECISION_DEFAULT,
MODEL_PRECISION_FP16,
MODEL_PRECISION_FP32,
MODEL_PRECISION_OPTIONS,
)
from uvr_cli.engine import BenchmarkEngine
from uvr_cli.model_resolver import (
build_headless_model_data,
list_available_models,
resolve_model_file,
)
from uvr_cli.runner import execute_inference
# Map shorthand precision arguments to UVR canonical precision strings
PRECISION_MAP = {
"fp32": MODEL_PRECISION_FP32,
"fp16": MODEL_PRECISION_FP16,
"bf16": MODEL_PRECISION_BF16,
"fp8": "Performance (FP8-E4M3)",
"fp8_e4m3": "Performance (FP8-E4M3)",
"nvfp4": "Performance (NVFP4)",
}
def normalize_cli_precision(prec_arg: Optional[str]) -> str:
"""Map user CLI input (e.g. 'fp16') to UVR canonical precision name."""
if not prec_arg:
return MODEL_PRECISION_DEFAULT
clean = prec_arg.strip().lower()
if clean in PRECISION_MAP:
return PRECISION_MAP[clean]
# Check if user passed the full canonical string
for opt in MODEL_PRECISION_OPTIONS:
if clean == opt.lower():
return opt
return MODEL_PRECISION_DEFAULT
def create_synthetic_audio(duration_sec: float = 2.0, samplerate: int = 44100) -> Path:
"""Create a temporary sine-wave test WAV file for smoke testing."""
temp_dir = Path(tempfile.mkdtemp(prefix="uvr_smoke_test_"))
audio_path = temp_dir / "synthetic_test_input.wav"
total_samples = int(duration_sec * samplerate)
t = np.linspace(0, duration_sec, total_samples, endpoint=False)
# 440 Hz (A4) sine wave in stereo
signal = 0.5 * np.sin(2 * np.pi * 440 * t)
stereo_signal = np.vstack((signal, signal)).T
int_signal = (stereo_signal * 32767).astype(np.int16)
with wave.open(str(audio_path), "wb") as wf:
wf.setnchannels(2)
wf.setsampwidth(2)
wf.setframerate(samplerate)
wf.writeframes(int_signal.tobytes())
return audio_path
def handle_list_models(args: argparse.Namespace) -> int:
"""List all installed UVR models."""
models = list_available_models()
if not models:
print("No models found in models/ directories.")
return 0
print(f"\n{'='*75}")
print(f" INSTALLED UVR MODELS ({len(models)} found)")
print(f"{'='*75}")
print(f"{'Architecture':<15} | {'Size (MB)':<10} | {'Model Name'}")
print(f"{'-'*15}-+-{'-'*10}-+-{'-'*45}")
for m in models:
print(f"{m['architecture']:<15} | {m['size_mb']:<10.2f} | {m['name']}")
print(f"{'='*75}\n")
return 0
def handle_run(args: argparse.Namespace) -> int:
"""Perform CLI-only separation directly through UVR core."""
model_path, arch = resolve_model_file(args.model)
precision = normalize_cli_precision(args.precision)
print(f"Resolving model: {model_path.name} ({arch})")
model_data = build_headless_model_data(
model_path=model_path,
architecture=arch,
precision=precision,
device=args.device,
segment_size=args.segment_size,
overlap=args.overlap,
batch_size=args.batch_size,
)
audio_path = Path(args.audio).resolve()
output_dir = Path(args.output_dir).resolve()
print(f"Separating : {audio_path.name}")
print(f"Precision : {precision}")
print(f"Output folder : {output_dir}")
stems, is_valid = execute_inference(
model_data=model_data,
audio_path=audio_path,
export_dir=output_dir,
console_callback=lambda text, base="": print(f"[UVR Core] {text}"),
)
if is_valid and stems:
print(f"\n[OK] Separation completed successfully! Generated {len(stems)} stem(s):")
for stem in stems:
print(f" -> {stem.name} ({round(stem.stat().st_size / (1024*1024), 2)} MB)")
return 0
else:
print(f"\n[ERROR] Separation completed but no valid outputs were generated.")
return 1
def handle_bench(args: argparse.Namespace) -> int:
"""Run real performance benchmark on UVR models."""
model_path, arch = resolve_model_file(args.model)
precision = normalize_cli_precision(args.precision)
model_data = build_headless_model_data(
model_path=model_path,
architecture=arch,
precision=precision,
device=args.device,
segment_size=args.segment_size,
overlap=args.overlap,
batch_size=args.batch_size,
)
device_idx = int(args.device.split(":")[-1]) if ":" in args.device else 0
engine = BenchmarkEngine(
model_data=model_data,
audio_path=args.audio,
results_dir=args.export_dir,
rounds=args.rounds,
warmup=args.warmup,
device_index=device_idx,
)
results = engine.run(verbose=True)
return 0 if results["summary"]["rounds_measured"] > 0 else 1
def handle_smoke_test(args: argparse.Namespace) -> int:
"""Run end-to-end smoke test with synthetic audio."""
print("Generating 2.0-second synthetic stereo audio for smoke test...")
audio_path = create_synthetic_audio(duration_sec=2.0)
try:
# Select model: use specified or pick first available
if args.model:
model_target = args.model
else:
models = list_available_models()
if not models:
print("[ERROR] No models installed to test with. Download a model first.")
return 1
model_target = models[0]["path"]
model_path, arch = resolve_model_file(model_target)
precision = normalize_cli_precision(args.precision)
print(f"Selected smoke test model: {model_path.name} ({arch})")
model_data = build_headless_model_data(
model_path=model_path,
architecture=arch,
precision=precision,
device=args.device,
)
device_idx = int(args.device.split(":")[-1]) if ":" in args.device else 0
engine = BenchmarkEngine(
model_data=model_data,
audio_path=audio_path,
results_dir=args.export_dir,
rounds=1,
warmup=1,
device_index=device_idx,
)
results = engine.run(verbose=True)
if results["summary"]["rounds_measured"] > 0:
print("\n[OK] Smoke test passed successfully!")
return 0
else:
print("\n[FAIL] Smoke test completed without successful rounds.")
return 1
finally:
# Clean up synthetic audio file and its folder
try:
if audio_path.is_file():
audio_path.unlink()
if audio_path.parent.is_dir():
audio_path.parent.rmdir()
except Exception:
pass
def build_parser() -> argparse.ArgumentParser:
"""Build command-line parser."""
parser = argparse.ArgumentParser(
prog="uvr_cli",
description="Ultimate Vocal Remover - CLI-Only Inference & Performance Benchmarking Suite",
)
subparsers = parser.add_subparsers(dest="command", help="Available subcommands")
# Command: list-models
subparsers.add_parser("list-models", help="List all available installed models")
# Command: run
run_parser = subparsers.add_parser("run", help="Run UVR separation directly via CLI (No GUI)")
run_parser.add_argument("--audio", "-a", required=True, help="Path to input audio file")
run_parser.add_argument("--model", "-m", required=True, help="Model name, filename, or absolute path")
run_parser.add_argument(
"--precision",
"-p",
default="fp16",
help="Inference precision: fp32, fp16, fp8, nvfp4 (default: fp16)",
)
run_parser.add_argument("--device", "-d", default="cuda:0", help="Target device: cuda:0, cpu (default: cuda:0)")
run_parser.add_argument("--output-dir", "-o", default="separated_outputs", help="Output directory for stems")
run_parser.add_argument("--segment-size", type=int, default=None, help="Segment size (MDX chunk size)")
run_parser.add_argument("--overlap", type=float, default=None, help="Overlap ratio (e.g. 0.25)")
run_parser.add_argument("--batch-size", type=int, default=1, help="Inference batch size (default: 1)")
# Command: bench
bench_parser = subparsers.add_parser("bench", help="Run real benchmark with hardware telemetry & metric export")
bench_parser.add_argument("--audio", "-a", required=True, help="Path to input audio file")
bench_parser.add_argument("--model", "-m", required=True, help="Model name, filename, or absolute path")
bench_parser.add_argument(
"--precision",
"-p",
default="fp16",
help="Inference precision: fp32, fp16, fp8, nvfp4 (default: fp16)",
)
bench_parser.add_argument("--device", "-d", default="cuda:0", help="Target device: cuda:0, cpu (default: cuda:0)")
bench_parser.add_argument("--rounds", "-r", type=int, default=3, help="Number of measurement rounds (default: 3)")
bench_parser.add_argument("--warmup", "-w", type=int, default=1, help="Number of warmup rounds (default: 1)")
bench_parser.add_argument(
"--export-dir",
"-e",
default="benchmark_results",
help="Directory to save JSON & CSV reports (default: benchmark_results)",
)
bench_parser.add_argument("--segment-size", type=int, default=None, help="Segment size (MDX chunk size)")
bench_parser.add_argument("--overlap", type=float, default=None, help="Overlap ratio (e.g. 0.25)")
bench_parser.add_argument("--batch-size", type=int, default=1, help="Inference batch size (default: 1)")
# Command: smoke-test
smoke_parser = subparsers.add_parser("smoke-test", help="Run automated smoke test using synthetic audio")
smoke_parser.add_argument("--model", "-m", default=None, help="Optional model name (defaults to first available)")
smoke_parser.add_argument("--precision", "-p", default="fp16", help="Inference precision (default: fp16)")
smoke_parser.add_argument("--device", "-d", default="cuda:0", help="Target device: cuda:0, cpu (default: cuda:0)")
smoke_parser.add_argument(
"--export-dir",
"-e",
default="benchmark_results",
help="Directory to save smoke test reports (default: benchmark_results)",
)
return parser
def main() -> None:
parser = build_parser()
args = parser.parse_args()
if not args.command:
parser.print_help()
sys.exit(1)
if args.command == "list-models":
sys.exit(handle_list_models(args))
elif args.command == "run":
sys.exit(handle_run(args))
elif args.command == "bench":
sys.exit(handle_bench(args))
elif args.command == "smoke-test":
sys.exit(handle_smoke_test(args))
else:
parser.print_help()
sys.exit(1)
if __name__ == "__main__":
main()
+211
View File
@@ -0,0 +1,211 @@
"""Benchmarking engine managing warmup, measurement rounds, timing, and export."""
from __future__ import annotations
import os
import shutil
import time
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Dict, List, Optional
import uuid
from .exporter import export_benchmark_csv, export_benchmark_json
from .model_resolver import HeadlessModelData
from .runner import execute_inference, get_audio_metadata
from .telemetry import TelemetrySampler, collect_system_info, sync_cuda
class BenchmarkEngine:
"""Orchestrates end-to-end performance benchmarking for UVR inference."""
def __init__(
self,
model_data: HeadlessModelData,
audio_path: str | Path,
results_dir: str | Path = "benchmark_results",
rounds: int = 1,
warmup: int = 0,
device_index: int = 0,
) -> None:
self.model_data = model_data
self.audio_path = Path(audio_path).resolve()
self.results_dir = Path(results_dir).resolve()
self.rounds = max(1, rounds)
self.warmup = max(0, warmup)
self.device_index = device_index
self.session_id = f"session_{datetime.now(timezone.utc).strftime('%Y%m%d_%H%M%S')}_{uuid.uuid4().hex[:6]}"
self.results_dir.mkdir(parents=True, exist_ok=True)
def run(self, verbose: bool = True) -> Dict[str, Any]:
"""Run warmup and measurement rounds, gather telemetry, and export results."""
if verbose:
print(f"\n{'='*70}")
print(f" UVR BENCHMARK SESSION: {self.session_id}")
print(f"{'='*70}")
print(f"Model : {self.model_data.model_name}")
print(f"Backend : {self.model_data.process_method}")
print(f"Precision : {self.model_data.model_precision}")
print(f"Audio File : {self.audio_path.name}")
print(f"Rounds : {self.rounds} (Warmup: {self.warmup})")
print(f"Device Index : {self.device_index}")
print(f"{'='*70}\n")
system_info = collect_system_info(self.device_index)
audio_info = get_audio_metadata(self.audio_path)
all_runs_data: List[Dict[str, Any]] = []
csv_rows: List[Dict[str, Any]] = []
total_iterations = self.warmup + self.rounds
current_iter = 0
temp_stems_dir = self.results_dir / "temp_stems" / self.session_id
temp_stems_dir.mkdir(parents=True, exist_ok=True)
try:
for i in range(total_iterations):
current_iter += 1
is_warmup_run = current_iter <= self.warmup
round_number = current_iter if is_warmup_run else (current_iter - self.warmup)
cache_state = "cold" if current_iter == 1 else "warm"
run_label = f"Warmup {round_number}" if is_warmup_run else f"Measurement Round {round_number}/{self.rounds}"
if verbose:
print(f"--> Starting {run_label} (Cache: {cache_state})...")
round_export_dir = temp_stems_dir / f"round_{current_iter}"
round_export_dir.mkdir(parents=True, exist_ok=True)
sampler = TelemetrySampler(device_index=self.device_index, interval_sec=0.1)
sync_cuda(self.device_index)
sampler.start()
start_time = time.perf_counter()
stems, is_valid = execute_inference(
model_data=self.model_data,
audio_path=self.audio_path,
export_dir=round_export_dir,
)
sync_cuda(self.device_index)
end_time = time.perf_counter()
telemetry = sampler.stop()
total_time = round(end_time - start_time, 4)
duration_sec = audio_info.get("duration_sec", 0.0)
speed_factor = round(duration_sec / total_time, 2) if total_time > 0 and duration_sec > 0 else 0.0
run_record = {
"iteration": current_iter,
"is_warmup": is_warmup_run,
"round": round_number,
"cache_state": cache_state,
"total_time_sec": total_time,
"speed_factor_rt": speed_factor,
"is_valid": is_valid,
"output_stems": [s.name for s in stems],
"telemetry": telemetry,
}
all_runs_data.append(run_record)
csv_row = {
"session_id": self.session_id,
"timestamp_utc": datetime.now(timezone.utc).isoformat(),
"gpu_name": system_info.get("gpu_name", "N/A"),
"cpu_name": system_info.get("cpu", "N/A"),
"model_name": self.model_data.model_name,
"model_hash": self.model_data.model_hash,
"backend": self.model_data.process_method,
"precision": self.model_data.model_precision,
"audio_file": self.audio_path.name,
"audio_duration_sec": duration_sec,
"round": f"warmup_{round_number}" if is_warmup_run else str(round_number),
"cache_state": cache_state,
"total_time_sec": total_time,
"inference_time_sec": total_time, # Pure separator execution
"speed_factor_rt": speed_factor,
"peak_torch_vram_mb": telemetry.get("torch_peak_allocated_vram_mb", 0.0),
"peak_device_vram_mb": telemetry.get("peak_device_vram_mb", 0.0),
"avg_gpu_util_percent": telemetry.get("avg_gpu_utilization_percent", 0.0),
"peak_gpu_util_percent": telemetry.get("peak_gpu_utilization_percent", 0.0),
"avg_cpu_util_percent": telemetry.get("avg_process_cpu_percent", 0.0),
"peak_process_ram_mb": telemetry.get("peak_process_ram_mb", 0.0),
"status": "COMPLETED" if is_valid else "VALIDATION_FAILED",
}
csv_rows.append(csv_row)
if verbose:
print(
f" Time: {total_time:.2f}s ({speed_factor}x RT) | "
f"Peak Torch VRAM: {telemetry.get('torch_peak_allocated_vram_mb', 0):.1f} MiB | "
f"Peak Device VRAM: {telemetry.get('peak_device_vram_mb', 0):.1f} MiB | "
f"GPU Util: {telemetry.get('avg_gpu_utilization_percent', 0):.1f}% (Peak: {telemetry.get('peak_gpu_utilization_percent', 0):.1f}%)"
)
finally:
# Clean up temporary stems after benchmarking
try:
shutil.rmtree(temp_stems_dir, ignore_errors=True)
except Exception:
pass
# Compute summary metrics across non-warmup rounds (or all if only warmup was run)
measured_runs = [r for r in all_runs_data if not r["is_warmup"]]
if not measured_runs:
measured_runs = all_runs_data
measured_times = [r["total_time_sec"] for r in measured_runs]
measured_speed_factors = [r["speed_factor_rt"] for r in measured_runs]
measured_torch_vram = [r["telemetry"].get("torch_peak_allocated_vram_mb", 0.0) for r in measured_runs]
measured_device_vram = [r["telemetry"].get("peak_device_vram_mb", 0.0) for r in measured_runs]
summary = {
"rounds_measured": len(measured_runs),
"warmup_rounds": self.warmup,
"avg_total_time_sec": round(sum(measured_times) / len(measured_times), 4),
"min_total_time_sec": min(measured_times),
"max_total_time_sec": max(measured_times),
"avg_speed_factor_rt": round(sum(measured_speed_factors) / len(measured_speed_factors), 2),
"peak_torch_allocated_vram_mb": max(measured_torch_vram) if measured_torch_vram else 0.0,
"peak_device_vram_mb": max(measured_device_vram) if measured_device_vram else 0.0,
}
report_data: Dict[str, Any] = {
"session_id": self.session_id,
"timestamp_utc": datetime.now(timezone.utc).isoformat(),
"system_info": system_info,
"audio_info": audio_info,
"model_info": {
"name": self.model_data.model_name,
"hash": self.model_data.model_hash,
"backend": self.model_data.process_method,
"precision": self.model_data.model_precision,
"segment_size": getattr(self.model_data, "mdx_segment_size", None),
"batch_size": getattr(self.model_data, "mdx_batch_size", 1),
},
"summary": summary,
"runs": all_runs_data,
}
# Export JSON and CSV
json_file = self.results_dir / f"{self.session_id}.json"
csv_file = self.results_dir / "summary.csv"
export_benchmark_json(report_data, json_file)
export_benchmark_csv(csv_rows, csv_file)
if verbose:
print(f"\n{'='*70}")
print(f" BENCHMARK SUMMARY")
print(f"{'='*70}")
print(f"Avg Time : {summary['avg_total_time_sec']:.2f}s (Min: {summary['min_total_time_sec']:.2f}s, Max: {summary['max_total_time_sec']:.2f}s)")
print(f"Speed Factor : {summary['avg_speed_factor_rt']:.2f}x real-time")
print(f"Peak VRAM : Torch: {summary['peak_torch_allocated_vram_mb']:.1f} MiB | Device: {summary['peak_device_vram_mb']:.1f} MiB")
print(f"JSON Report : {json_file}")
print(f"CSV Summary : {csv_file}")
print(f"{'='*70}\n")
return report_data
+81
View File
@@ -0,0 +1,81 @@
"""Machine-readable JSON and CSV exporters for UVR benchmarks with privacy sanitization."""
from __future__ import annotations
import csv
import json
import os
import re
from pathlib import Path
from typing import Any, Dict, List
_WINDOWS_USER_PATH = re.compile(r"(?i)[A-Z]:[\\/]Users[\\/][^\\/\r\n\"']+[\\/]")
_GENERIC_ABS_PATH = re.compile(r"(?i)[A-Z]:[\\/][^\r\n\"']+")
def sanitize_path(value: Any) -> Any:
"""Sanitize paths and redact local username for safe GitHub uploads."""
if isinstance(value, str):
# Redact specific user profile directory while keeping project relative path
redacted = _WINDOWS_USER_PATH.sub("<user_dir>/", value)
return redacted.replace("\\", "/")
if isinstance(value, dict):
return {k: sanitize_path(v) for k, v in value.items()}
if isinstance(value, (list, tuple)):
return [sanitize_path(v) for v in value]
return value
def export_benchmark_json(data: Dict[str, Any], output_path: str | Path) -> Path:
"""Export benchmark result to structured machine-readable JSON."""
path = Path(output_path).resolve()
path.parent.mkdir(parents=True, exist_ok=True)
sanitized = sanitize_path(data)
with path.open("w", encoding="utf-8") as f:
json.dump(sanitized, f, indent=2, sort_keys=True)
return path
CSV_FIELDS = [
"session_id",
"timestamp_utc",
"gpu_name",
"cpu_name",
"model_name",
"model_hash",
"backend",
"precision",
"audio_file",
"audio_duration_sec",
"round",
"cache_state",
"total_time_sec",
"inference_time_sec",
"speed_factor_rt",
"peak_torch_vram_mb",
"peak_device_vram_mb",
"avg_gpu_util_percent",
"peak_gpu_util_percent",
"avg_cpu_util_percent",
"peak_process_ram_mb",
"status",
]
def export_benchmark_csv(runs_summary: List[Dict[str, Any]], csv_path: str | Path) -> Path:
"""Append benchmark runs to a tabular summary CSV file."""
path = Path(csv_path).resolve()
path.parent.mkdir(parents=True, exist_ok=True)
file_exists = path.is_file() and path.stat().st_size > 0
with path.open("a", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=CSV_FIELDS, extrasaction="ignore")
if not file_exists:
writer.writeheader()
for run in runs_summary:
clean_run = sanitize_path(run)
writer.writerow(clean_run)
return path
+419
View File
@@ -0,0 +1,419 @@
"""Model resolution and headless configuration adapter for UVR models.
Discovers models, computes UVR MD5 hashes, parses model configurations,
and constructs HeadlessModelData objects suitable for direct ingestion by
separate.py separator classes (SeperateMDX, SeperateMDXC, SeperateVR, SeperateDemucs).
"""
from __future__ import annotations
import hashlib
import json
import os
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple
import yaml
from ml_collections import ConfigDict
from gui_data.constants import (
ALL_STEMS,
CKPT,
DEMUCS_2_SOURCE,
DEMUCS_2_SOURCE_MAPPER,
DEMUCS_4_SOURCE,
DEMUCS_4_SOURCE_MAPPER,
DEMUCS_ARCH_TYPE,
DEMUCS_NEWER_TAGS,
DEMUCS_UVR_MODEL,
DEMUCS_V1,
DEMUCS_V1_TAG,
DEMUCS_V2,
DEMUCS_V2_TAG,
DEMUCS_V3,
DEMUCS_V3_TAG,
DEMUCS_V4,
DEMUCS_V4_TAG,
DEMUCS_VERSION_MAPPER,
INST_STEM,
MDX_ARCH_TYPE,
MODEL_PRECISION_DEFAULT,
MODEL_PRECISION_FP16,
MODEL_PRECISION_FP32,
MODEL_PRECISION_BF16,
MODEL_PRECISION_OPTIONS,
NO_MODEL,
ONNX,
PRIMARY_STEM,
PTH,
VOCAL_STEM,
VR_ARCH_TYPE,
YAML,
normalize_model_precision,
secondary_stem,
)
PROJECT_ROOT = Path(__file__).resolve().parents[1]
MODELS_DIR = PROJECT_ROOT / "models"
MDX_MODELS_DIR = MODELS_DIR / "MDX_Net_Models"
VR_MODELS_DIR = MODELS_DIR / "VR_Models"
DEMUCS_MODELS_DIR = MODELS_DIR / "Demucs_Models"
DEMUCS_NEWER_REPO_DIR = DEMUCS_MODELS_DIR / "v3_v4_repo"
MDX_HASH_DIR = MDX_MODELS_DIR / "model_data"
MDX_HASH_JSON = MDX_HASH_DIR / "model_data.json"
MDX_C_CONFIG_PATH = MDX_HASH_DIR / "mdx_c_configs"
MDX_NAME_MAPPER_PATH = MDX_HASH_DIR / "model_name_mapper.json"
VR_HASH_DIR = VR_MODELS_DIR / "model_data"
VR_HASH_JSON = VR_HASH_DIR / "model_data.json"
VR_PARAM_DIR = PROJECT_ROOT / "lib_v5" / "vr_network" / "modelparams"
DEMUCS_NAME_MAPPER_PATH = DEMUCS_MODELS_DIR / "model_data" / "model_name_mapper.json"
def compute_uvr_hash(model_path: str | Path) -> str:
"""Compute the model hash using UVR's exact algorithm.
Reads the last 10,000 * 1024 bytes (or full file if smaller) and computes MD5.
"""
path = Path(model_path).resolve()
with open(path, "rb") as stream:
try:
stream.seek(-10000 * 1024, 2)
return hashlib.md5(stream.read()).hexdigest()
except (OSError, ValueError):
stream.seek(0)
return hashlib.md5(stream.read()).hexdigest()
class HeadlessModelData:
"""Lightweight configuration container compatible with SeperateAttributes."""
def __init__(self, **kwargs: Any) -> None:
# Default flags matching SeperateAttributes expectations
self.process_method: str = MDX_ARCH_TYPE
self.model_path: str = ""
self.model_name: str = ""
self.model_basename: str = ""
self.model_hash: Optional[str] = None
self.model_status: bool = True
self.device_set: str = "0"
self.is_gpu_conversion: int = 0
self.is_use_opencl: bool = False
self.model_precision: str = MODEL_PRECISION_DEFAULT
self.save_format: str = "WAV"
self.wav_type_set: str = "PCM_16"
self.mp3_bit_set: str = "320k"
self.is_normalization: bool = False
self.is_primary_stem_only: bool = False
self.is_secondary_stem_only: bool = False
self.is_pitch_change: bool = False
self.semitone_shift: float = 0.0
self.is_match_frequency_pitch: bool = False
self.is_invert_spec: bool = False
self.is_deverb_vocals: bool = False
self.is_mixer_mode: bool = False
self.primary_stem: str = "Instrumental"
self.secondary_stem: str = "Vocals"
self.primary_stem_native: str = "Instrumental"
self.model_samplerate: int = 44100
self.model_capacity: Tuple[int, int] = (32, 128)
self.is_vr_51_model: bool = False
# Secondary / chain model placeholders
self.is_secondary_model: bool = False
self.is_secondary_model_activated: bool = False
self.secondary_model: Any = None
self.secondary_model_scale: Any = None
self.primary_model_primary_stem: Any = None
self.is_primary_model_primary_stem_only: bool = False
self.is_primary_model_secondary_stem_only: bool = False
self.is_pre_proc_model: bool = False
self.pre_proc_model_activated: bool = False
self.pre_proc_model: Any = None
self.vocal_split_model: Any = None
self.is_vocal_split_model: bool = False
self.is_vocal_split_model_activated: bool = False
self.is_save_inst_vocal_splitter: bool = False
self.is_inst_only_voc_splitter: bool = False
self.is_save_vocal_only: bool = False
self.is_karaoke: bool = False
self.is_bv_model: bool = False
self.bv_model_rebalance: float = 0.0
self.is_sec_bv_rebalance: bool = False
self.deverb_vocal_opt: Any = None
self.DENOISER_MODEL: Any = None
self.DEVERBER_MODEL: Any = None
# Ensemble flags
self.is_ensemble_mode: bool = False
self.is_4_stem_ensemble: bool = False
self.is_multi_stem_ensemble: bool = False
self.ensemble_primary_stem: Any = None
self.ensemble_secondary_stem: Any = None
# MDX specific
self.is_mdx_ckpt: bool = False
self.is_mdx_c: bool = False
self.mdx_c_configs: Any = None
self.mdx_dim_f_set: int = 2048
self.mdx_dim_t_set: int = 8
self.mdx_n_fft_scale_set: int = 6144
self.compensate: Optional[float] = 1.035
self.mdxnet_stem_select: str = "Vocals"
self.mdx_batch_size: int = 1
self.mdx_segment_size: int = 256
self.overlap: float = 0.25
self.overlap_mdx: Any = "Default"
self.overlap_mdx23: int = 8
self.chunks: int = 0
self.margin: int = 44100
self.is_adaptive_chunk: bool = False
self.is_denoise: bool = False
self.is_denoise_model: bool = False
self.is_mdx_combine_stems: bool = False
self.is_mdx_c_seg_def: bool = False
self.mixer_path: str = str(MDX_MODELS_DIR / "mixer_val.ckpt")
# VR specific
self.vr_model_param: Any = None
self.is_high_end_process: str = "mirroring"
self.is_tta: bool = False
self.is_post_process: bool = False
self.window_size: int = 512
self.batch_size: int = 1
self.crop_size: int = 256
self.post_process_threshold: float = 0.2
self.aggression_setting: float = 0.05
# Demucs specific
self.demucs_version: str = DEMUCS_V4
self.demucs_stems: str = ALL_STEMS
self.demucs_source_list: List[str] = list(DEMUCS_4_SOURCE)
self.demucs_source_map: Dict[str, Any] = dict(DEMUCS_4_SOURCE_MAPPER)
self.demucs_stem_count: int = 4
self.shifts: int = 2
self.segment: Any = "Default"
self.is_split_mode: bool = True
self.is_chunk_demucs: bool = False
self.is_demucs_combine_stems: bool = False
self.secondary_model_4_stem: List[Any] = []
self.secondary_model_4_stem_scale: List[Any] = []
self.is_demucs_pre_proc_model_inst_mix: bool = False
for k, v in kwargs.items():
setattr(self, k, v)
def _load_json(path: Path) -> Dict[str, Any]:
if path.is_file():
try:
with path.open("r", encoding="utf-8") as f:
return json.load(f)
except Exception:
return {}
return {}
def list_available_models() -> List[Dict[str, Any]]:
"""Scan and list all installed models across MDX, VR, and Demucs architectures."""
results: List[Dict[str, Any]] = []
# MDX Models
if MDX_MODELS_DIR.is_dir():
for file in MDX_MODELS_DIR.iterdir():
if file.is_file() and file.suffix.lower() in [ONNX, CKPT]:
results.append({
"name": file.name,
"basename": file.stem,
"path": str(file),
"architecture": MDX_ARCH_TYPE,
"size_mb": round(file.stat().st_size / (1024 * 1024), 2),
"format": file.suffix.lower(),
})
# VR Models
if VR_MODELS_DIR.is_dir():
for file in VR_MODELS_DIR.iterdir():
if file.is_file() and file.suffix.lower() in [PTH]:
results.append({
"name": file.name,
"basename": file.stem,
"path": str(file),
"architecture": VR_ARCH_TYPE,
"size_mb": round(file.stat().st_size / (1024 * 1024), 2),
"format": file.suffix.lower(),
})
# Demucs Models
if DEMUCS_MODELS_DIR.is_dir():
for file in DEMUCS_MODELS_DIR.iterdir():
if file.is_file() and file.suffix.lower() in [".th", YAML]:
results.append({
"name": file.name,
"basename": file.stem,
"path": str(file),
"architecture": DEMUCS_ARCH_TYPE,
"size_mb": round(file.stat().st_size / (1024 * 1024), 2),
"format": file.suffix.lower(),
})
if DEMUCS_NEWER_REPO_DIR.is_dir():
for file in DEMUCS_NEWER_REPO_DIR.iterdir():
if file.is_file() and file.suffix.lower() in [YAML, ".th"]:
results.append({
"name": file.name,
"basename": file.stem,
"path": str(file),
"architecture": DEMUCS_ARCH_TYPE,
"size_mb": round(file.stat().st_size / (1024 * 1024), 2),
"format": file.suffix.lower(),
})
return results
def resolve_model_file(model_identifier: str) -> Tuple[Path, str]:
"""Resolve a model name or file path to an existing file and its architecture."""
# 1. Direct path check
direct_path = Path(model_identifier).resolve()
if direct_path.is_file():
ext = direct_path.suffix.lower()
if ext in [ONNX, CKPT]:
return direct_path, MDX_ARCH_TYPE
if ext in [PTH]:
return direct_path, VR_ARCH_TYPE
if ext in [YAML, ".th"]:
return direct_path, DEMUCS_ARCH_TYPE
return direct_path, MDX_ARCH_TYPE
# 2. Search by filename or stem in MDX_Net_Models
for candidate in [MDX_MODELS_DIR / model_identifier, MDX_MODELS_DIR / f"{model_identifier}.onnx", MDX_MODELS_DIR / f"{model_identifier}.ckpt"]:
if candidate.is_file():
return candidate, MDX_ARCH_TYPE
# 3. Search in VR_Models
for candidate in [VR_MODELS_DIR / model_identifier, VR_MODELS_DIR / f"{model_identifier}.pth"]:
if candidate.is_file():
return candidate, VR_ARCH_TYPE
# 4. Search in Demucs_Models
for candidate in [DEMUCS_MODELS_DIR / model_identifier, DEMUCS_NEWER_REPO_DIR / model_identifier, DEMUCS_NEWER_REPO_DIR / f"{model_identifier}.yaml"]:
if candidate.is_file():
return candidate, DEMUCS_ARCH_TYPE
# 5. Fallback search through all available models
for m in list_available_models():
if model_identifier.lower() in [m["name"].lower(), m["basename"].lower()]:
return Path(m["path"]), m["architecture"]
raise FileNotFoundError(f"Model '{model_identifier}' could not be located in models directories.")
def build_headless_model_data(
model_path: Path,
architecture: str,
precision: str = MODEL_PRECISION_DEFAULT,
device: str = "cuda:0",
segment_size: Optional[int] = None,
overlap: Optional[float] = None,
batch_size: int = 1,
) -> HeadlessModelData:
"""Build a complete HeadlessModelData object configured for the requested model."""
model_path = model_path.resolve()
model_name = model_path.name
model_basename = model_path.stem
model_hash = compute_uvr_hash(model_path)
is_gpu = "cuda" in device.lower() or "directml" in device.lower()
device_set = device.split(":")[-1] if ":" in device else "0"
norm_precision = normalize_model_precision(precision)
data = HeadlessModelData(
process_method=architecture,
model_path=str(model_path),
model_name=model_name,
model_basename=model_basename,
model_hash=model_hash,
model_precision=norm_precision,
device_set=device_set,
is_gpu_conversion=0 if is_gpu else -1,
)
if architecture == MDX_ARCH_TYPE:
data.is_mdx_ckpt = model_name.endswith(CKPT)
if segment_size is not None:
data.mdx_segment_size = segment_size
if overlap is not None:
data.overlap_mdx = overlap
data.mdx_batch_size = batch_size
# Check for model settings in hash json, then model_data.json
hash_file = MDX_HASH_DIR / f"{model_hash}.json"
hash_data = _load_json(hash_file)
if not hash_data:
master_data = _load_json(MDX_HASH_JSON)
hash_data = master_data.get(model_hash, {})
if hash_data:
if "config_yaml" in hash_data:
data.is_mdx_c = True
cfg_path = MDX_C_CONFIG_PATH / hash_data["config_yaml"]
if cfg_path.is_file():
with cfg_path.open("r", encoding="utf-8") as f:
data.mdx_c_configs = ConfigDict(yaml.load(f, Loader=yaml.FullLoader))
target = getattr(data.mdx_c_configs.training, "target_instrument", None)
if target:
data.primary_stem = target
else:
stems = getattr(data.mdx_c_configs.training, "instruments", ["Vocals"])
data.primary_stem = stems[0]
else:
data.compensate = hash_data.get("compensate", 1.035)
data.mdx_dim_f_set = hash_data.get("mdx_dim_f_set", 2048)
data.mdx_dim_t_set = hash_data.get("mdx_dim_t_set", 8)
data.mdx_n_fft_scale_set = hash_data.get("mdx_n_fft_scale_set", 6144)
data.primary_stem = hash_data.get("primary_stem", "Instrumental")
data.primary_stem_native = data.primary_stem
data.is_karaoke = hash_data.get("is_karaoke", False)
data.secondary_stem = secondary_stem(data.primary_stem)
elif architecture == VR_ARCH_TYPE:
hash_file = VR_HASH_DIR / f"{model_hash}.json"
hash_data = _load_json(hash_file)
if not hash_data:
master_data = _load_json(VR_HASH_JSON)
hash_data = master_data.get(model_hash, {})
if hash_data:
data.primary_stem = hash_data.get("primary_stem", "Vocals")
data.secondary_stem = secondary_stem(data.primary_stem)
vr_param_file = VR_PARAM_DIR / f"{hash_data.get('vr_model_param', '1_HP-UVR')}.json"
if vr_param_file.is_file():
from lib_v5.vr_network.model_param_init import ModelParameters
data.vr_model_param = ModelParameters(str(vr_param_file))
data.model_samplerate = data.vr_model_param.param.get("sr", 44100)
if "nout" in hash_data and "nout_lstm" in hash_data:
data.model_capacity = (hash_data["nout"], hash_data["nout_lstm"])
data.is_vr_51_model = True
elif architecture == DEMUCS_ARCH_TYPE:
data.demucs_version = DEMUCS_V4
for ver, tag in DEMUCS_VERSION_MAPPER.items():
if tag in model_name:
data.demucs_version = ver
if DEMUCS_UVR_MODEL in model_name:
data.demucs_source_list = list(DEMUCS_2_SOURCE)
data.demucs_source_map = dict(DEMUCS_2_SOURCE_MAPPER)
data.demucs_stem_count = 2
else:
data.demucs_source_list = list(DEMUCS_4_SOURCE)
data.demucs_source_map = dict(DEMUCS_4_SOURCE_MAPPER)
data.demucs_stem_count = 4
return data
+118
View File
@@ -0,0 +1,118 @@
"""Headless inference runner bridging directly to UVR's separate.py backends."""
from __future__ import annotations
import os
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Tuple
import soundfile as sf
from gui_data.constants import DEMUCS_ARCH_TYPE, MDX_ARCH_TYPE, VR_ARCH_TYPE
from .model_resolver import HeadlessModelData
from separate import SeperateDemucs, SeperateMDX, SeperateMDXC, SeperateVR
def get_audio_metadata(audio_path: str | Path) -> Dict[str, Any]:
"""Inspect audio file duration, sample rate, channels, and format."""
path = Path(audio_path).resolve()
try:
info = sf.info(str(path))
return {
"file_name": path.name,
"duration_sec": round(info.duration, 4),
"samplerate": info.samplerate,
"channels": info.channels,
"format": info.format,
"subtype": info.subtype,
"size_bytes": path.stat().st_size,
}
except Exception:
# Fallback if soundfile info fails
return {
"file_name": path.name,
"duration_sec": 0.0,
"samplerate": 44100,
"channels": 2,
"format": "UNKNOWN",
"subtype": "UNKNOWN",
"size_bytes": path.stat().st_size if path.is_file() else 0,
}
def execute_inference(
model_data: HeadlessModelData,
audio_path: str | Path,
export_dir: str | Path,
progress_callback: Optional[Callable[[float, float], None]] = None,
console_callback: Optional[Callable[[str, str], None]] = None,
) -> Tuple[List[Path], bool]:
"""Execute UVR separation directly using core separate.py classes.
Returns:
(generated_stems, is_valid)
"""
audio_path = Path(audio_path).resolve()
export_path = Path(export_dir).resolve()
export_path.mkdir(parents=True, exist_ok=True)
if not audio_path.is_file():
raise FileNotFoundError(f"Input audio file not found: {audio_path}")
# Snapshot existing files in export directory to detect new outputs
existing_files = set(export_path.glob("*"))
def default_progress(step: float, inference_iterations: float = 0.0) -> None:
if progress_callback:
progress_callback(step, inference_iterations)
def default_console(text: str, base_text: str = "") -> None:
if console_callback:
console_callback(text, base_text)
process_data: Dict[str, Any] = {
"model_data": model_data,
"export_path": str(export_path),
"audio_file_base": audio_path.stem,
"audio_file": str(audio_path),
"set_progress_bar": default_progress,
"write_to_console": default_console,
"process_iteration": 0,
"cached_source_callback": lambda process_method, model_name=None: (None, None),
"cached_model_source_holder": lambda *args, **kwargs: None,
"list_all_models": [],
"is_ensemble_master": False,
"is_4_stem_ensemble": False,
}
# Instantiate the corresponding UVR separator
if model_data.process_method == VR_ARCH_TYPE:
separator = SeperateVR(model_data, process_data)
elif model_data.process_method == MDX_ARCH_TYPE:
if model_data.is_mdx_c:
separator = SeperateMDXC(model_data, process_data)
else:
separator = SeperateMDX(model_data, process_data)
elif model_data.process_method == DEMUCS_ARCH_TYPE:
separator = SeperateDemucs(model_data, process_data)
else:
raise ValueError(f"Unsupported architecture: {model_data.process_method}")
# Run inference directly
separator.seperate()
# Detect generated stems
all_current_files = set(export_path.glob("*"))
new_files = [f for f in (all_current_files - existing_files) if f.is_file()]
# Validate output files
is_valid = True
if not new_files:
is_valid = False
else:
for stem_file in new_files:
if stem_file.stat().st_size == 0:
is_valid = False
break
return sorted(new_files), is_valid
+249
View File
@@ -0,0 +1,249 @@
"""Hardware telemetry and performance monitoring for UVR benchmarks.
Provides background resource sampling (CPU, GPU, VRAM, Power) and system
environment discovery, with graceful fallback if NVML or CUDA is unavailable.
"""
from __future__ import annotations
import os
import platform
import threading
import time
from typing import Any, Dict, List, Optional
import psutil
import torch
try:
import onnxruntime as ort
ORT_AVAILABLE = True
ORT_VERSION = ort.__version__
except Exception:
ORT_AVAILABLE = False
ORT_VERSION = "N/A"
try:
import pynvml
pynvml.nvmlInit()
NVML_AVAILABLE = True
except Exception:
NVML_AVAILABLE = False
def sync_cuda(device_index: int = 0) -> None:
"""Synchronize CUDA device if available."""
if torch.cuda.is_available():
try:
torch.cuda.synchronize(device_index)
except Exception:
pass
def collect_system_info(device_index: int = 0) -> Dict[str, Any]:
"""Collect hardware and software runtime environment details."""
gpu_name = None
driver_version = None
total_gpu_vram_mb = 0.0
if torch.cuda.is_available():
try:
gpu_name = torch.cuda.get_device_name(device_index)
except Exception:
pass
if NVML_AVAILABLE:
try:
handle = pynvml.nvmlDeviceGetHandleByIndex(device_index)
if not gpu_name:
gpu_name = pynvml.nvmlDeviceGetName(handle)
if isinstance(gpu_name, bytes):
gpu_name = gpu_name.decode("utf-8")
driver_version = pynvml.nvmlSystemGetDriverVersion()
if isinstance(driver_version, bytes):
driver_version = driver_version.decode("utf-8")
mem_info = pynvml.nvmlDeviceGetMemoryInfo(handle)
total_gpu_vram_mb = round(mem_info.total / (1024 * 1024), 2)
except Exception:
pass
return {
"os": platform.platform(),
"cpu": platform.processor() or platform.machine() or "Unknown CPU",
"cpu_count_logical": psutil.cpu_count(logical=True) or 0,
"cpu_count_physical": psutil.cpu_count(logical=False) or 0,
"system_ram_gb": round(psutil.virtual_memory().total / (1024**3), 2),
"gpu_name": gpu_name or "N/A",
"total_gpu_vram_mb": total_gpu_vram_mb,
"driver_version": driver_version or "N/A",
"cuda_available": torch.cuda.is_available(),
"cuda_version": torch.version.cuda or "N/A",
"torch_version": torch.__version__,
"onnxruntime_version": ORT_VERSION,
"python_version": platform.python_version(),
}
class TelemetrySampler:
"""Background sampling monitor measuring CPU, RAM, GPU utilization, VRAM, and power."""
def __init__(self, device_index: int = 0, interval_sec: float = 0.1) -> None:
self.device_index = device_index
self.interval_sec = interval_sec
self._stop_event = threading.Event()
self._thread: Optional[threading.Thread] = None
self._process = psutil.Process(os.getpid())
self._nvml_handle: Any = None
if NVML_AVAILABLE:
try:
self._nvml_handle = pynvml.nvmlDeviceGetHandleByIndex(self.device_index)
except Exception:
self._nvml_handle = None
# Sample storage
self.process_cpu_samples: List[float] = []
self.system_cpu_samples: List[float] = []
self.process_ram_samples: List[float] = []
self.gpu_util_samples: List[float] = []
self.device_vram_samples: List[float] = []
self.power_samples: List[float] = []
self.baseline_device_vram_mb: float = 0.0
self.baseline_torch_allocated_mb: float = 0.0
def start(self) -> None:
"""Start the background sampling thread and reset peak GPU stats."""
# Initial CPU reading primes psutil
try:
self._process.cpu_percent()
psutil.cpu_percent()
except Exception:
pass
if torch.cuda.is_available():
try:
sync_cuda(self.device_index)
torch.cuda.reset_peak_memory_stats(self.device_index)
self.baseline_torch_allocated_mb = round(
torch.cuda.memory_allocated(self.device_index) / (1024 * 1024), 2
)
except Exception:
pass
if self._nvml_handle:
try:
mem = pynvml.nvmlDeviceGetMemoryInfo(self._nvml_handle)
self.baseline_device_vram_mb = round(mem.used / (1024 * 1024), 2)
except Exception:
pass
self._stop_event.clear()
self._thread = threading.Thread(target=self._sample_loop, daemon=True, name="TelemetrySampler")
self._thread.start()
def _sample_loop(self) -> None:
while not self._stop_event.is_set():
try:
# CPU & RAM
proc_cpu = self._process.cpu_percent()
sys_cpu = psutil.cpu_percent()
proc_ram = self._process.memory_info().rss / (1024 * 1024)
self.process_cpu_samples.append(proc_cpu)
self.system_cpu_samples.append(sys_cpu)
self.process_ram_samples.append(proc_ram)
# NVML metrics
if self._nvml_handle:
rates = pynvml.nvmlDeviceGetUtilizationRates(self._nvml_handle)
self.gpu_util_samples.append(float(rates.gpu))
mem = pynvml.nvmlDeviceGetMemoryInfo(self._nvml_handle)
self.device_vram_samples.append(mem.used / (1024 * 1024))
try:
power_w = pynvml.nvmlDeviceGetPowerUsage(self._nvml_handle) / 1000.0
self.power_samples.append(power_w)
except Exception:
pass
except Exception:
pass
time.sleep(self.interval_sec)
def stop(self) -> Dict[str, Any]:
"""Stop sampling and return aggregated hardware metrics."""
self._stop_event.set()
if self._thread and self._thread.is_alive():
self._thread.join(timeout=1.0)
sync_cuda(self.device_index)
torch_peak_alloc = 0.0
torch_peak_reserved = 0.0
if torch.cuda.is_available():
try:
torch_peak_alloc = round(
torch.cuda.max_memory_allocated(self.device_index) / (1024 * 1024), 2
)
torch_peak_reserved = round(
torch.cuda.max_memory_reserved(self.device_index) / (1024 * 1024), 2
)
except Exception:
pass
avg_proc_cpu = (
round(sum(self.process_cpu_samples) / len(self.process_cpu_samples), 2)
if self.process_cpu_samples
else 0.0
)
peak_proc_cpu = round(max(self.process_cpu_samples), 2) if self.process_cpu_samples else 0.0
avg_sys_cpu = (
round(sum(self.system_cpu_samples) / len(self.system_cpu_samples), 2)
if self.system_cpu_samples
else 0.0
)
peak_sys_cpu = round(max(self.system_cpu_samples), 2) if self.system_cpu_samples else 0.0
peak_proc_ram = (
round(max(self.process_ram_samples), 2) if self.process_ram_samples else 0.0
)
avg_gpu_util = (
round(sum(self.gpu_util_samples) / len(self.gpu_util_samples), 2)
if self.gpu_util_samples
else 0.0
)
peak_gpu_util = round(max(self.gpu_util_samples), 2) if self.gpu_util_samples else 0.0
peak_device_vram = (
round(max(self.device_vram_samples), 2)
if self.device_vram_samples
else (self.baseline_device_vram_mb or torch_peak_alloc)
)
avg_power = (
round(sum(self.power_samples) / len(self.power_samples), 2)
if self.power_samples
else 0.0
)
peak_power = round(max(self.power_samples), 2) if self.power_samples else 0.0
return {
"samples_count": len(self.process_cpu_samples),
"avg_process_cpu_percent": avg_proc_cpu,
"peak_process_cpu_percent": peak_proc_cpu,
"avg_system_cpu_percent": avg_sys_cpu,
"peak_system_cpu_percent": peak_sys_cpu,
"peak_process_ram_mb": peak_proc_ram,
"avg_gpu_utilization_percent": avg_gpu_util,
"peak_gpu_utilization_percent": peak_gpu_util,
"baseline_device_vram_mb": self.baseline_device_vram_mb,
"peak_device_vram_mb": peak_device_vram,
"torch_peak_allocated_vram_mb": torch_peak_alloc,
"torch_peak_reserved_vram_mb": torch_peak_reserved,
"avg_power_watts": avg_power,
"peak_power_watts": peak_power,
}