Record CUDA benchmark diagnostics
This commit is contained in:
@@ -192,7 +192,7 @@ def detect_hardware() -> dict:
|
||||
}
|
||||
|
||||
|
||||
def benchmark_throughput(device_str: str = "cpu") -> float:
|
||||
def benchmark_throughput_checked(device_str: str = "cpu") -> tuple[float, bool, str | None]:
|
||||
"""
|
||||
Estimate compute throughput via a synthetic transformer GEMM benchmark.
|
||||
|
||||
@@ -201,7 +201,8 @@ def benchmark_throughput(device_str: str = "cpu") -> float:
|
||||
The value is used as benchmark_tokens_per_sec in tracker registration for
|
||||
routing tiebreaks; it is not an absolute token rate.
|
||||
|
||||
Falls back to 1.0 if torch is unavailable.
|
||||
Returns (score, ok, error). Score falls back to 1.0 when the requested
|
||||
device cannot run the benchmark.
|
||||
"""
|
||||
try:
|
||||
import torch # type: ignore[import]
|
||||
@@ -233,6 +234,12 @@ def benchmark_throughput(device_str: str = "cpu") -> float:
|
||||
_sync()
|
||||
elapsed = time.perf_counter() - t0
|
||||
|
||||
return round(n_iters / max(elapsed, 1e-9), 2)
|
||||
except Exception:
|
||||
return 1.0
|
||||
return round(n_iters / max(elapsed, 1e-9), 2), True, None
|
||||
except Exception as exc:
|
||||
return 1.0, False, f"{type(exc).__name__}: {exc}"
|
||||
|
||||
|
||||
def benchmark_throughput(device_str: str = "cpu") -> float:
|
||||
"""Return only the numeric throughput index, preserving the legacy API."""
|
||||
score, _ok, _error = benchmark_throughput_checked(device_str)
|
||||
return score
|
||||
|
||||
@@ -14,7 +14,7 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from .downloader import compute_shard_checksum, download_shard
|
||||
from .hardware import detect_hardware, benchmark_throughput
|
||||
from .hardware import detect_hardware, benchmark_throughput_checked
|
||||
from .relay_bridge import RelayHttpBridge, peer_id_from_wallet
|
||||
from .server import StubNodeServer
|
||||
from .torch_server import TorchNodeServer
|
||||
@@ -386,7 +386,18 @@ def run_startup(
|
||||
print(f" Memory budget: {memory_budget_mb / 1024:.1f} GB {memory_budget_source}", flush=True)
|
||||
|
||||
print("Benchmarking compute...", flush=True)
|
||||
bench_tps = benchmark_throughput(device)
|
||||
if device != "cuda" and gpu_name:
|
||||
_cuda_score, cuda_ok, cuda_error = benchmark_throughput_checked("cuda")
|
||||
hw["cuda_benchmark_ok"] = cuda_ok
|
||||
if cuda_error:
|
||||
hw["cuda_benchmark_error"] = cuda_error
|
||||
if not cuda_ok:
|
||||
print(f" CUDA benchmark unavailable: {cuda_error}; using CPU benchmark", flush=True)
|
||||
bench_tps, bench_ok, bench_error = benchmark_throughput_checked(device)
|
||||
hw["benchmark_device"] = device
|
||||
hw["benchmark_ok"] = bench_ok
|
||||
if bench_error:
|
||||
hw["benchmark_error"] = bench_error
|
||||
device_label = "GPU" if device == "cuda" else "CPU"
|
||||
print(f" {device_label} throughput index: {bench_tps:,.0f}", flush=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user