Delete raven/benchmark.py
Browse files- raven/benchmark.py +0 -43
raven/benchmark.py
DELETED
|
@@ -1,43 +0,0 @@
|
|
| 1 |
-
from __future__ import annotations
|
| 2 |
-
import copy
|
| 3 |
-
import time
|
| 4 |
-
import torch
|
| 5 |
-
from .foundation import FoundationEncoder
|
| 6 |
-
from .foundation_runtime import FoundationRuntime
|
| 7 |
-
from .utils import configure_cpu
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def benchmark_foundation(cfg: dict, accelerator: str = "auto", loops: int = 5) -> dict:
|
| 11 |
-
cfg = copy.deepcopy(cfg)
|
| 12 |
-
hc = cfg["hardware"]
|
| 13 |
-
fc = cfg["foundation"]
|
| 14 |
-
fc["accelerator"] = accelerator
|
| 15 |
-
configure_cpu(hc.get("torch_threads", 6), hc.get("interop_threads", 1))
|
| 16 |
-
enc = FoundationEncoder(
|
| 17 |
-
fc.get("backend", "dinov2_vits14"),
|
| 18 |
-
bool(fc.get("allow_fallback", True)),
|
| 19 |
-
fc.get("fallback_backend", "torchvision_convnext_tiny"),
|
| 20 |
-
).eval().to("cpu")
|
| 21 |
-
rt = FoundationRuntime(fc, enc)
|
| 22 |
-
b = rt.batch_size
|
| 23 |
-
x = torch.randn(b, 3, 224, 224)
|
| 24 |
-
rt.infer(x)
|
| 25 |
-
loops = max(2, int(loops))
|
| 26 |
-
t0 = time.perf_counter()
|
| 27 |
-
for _ in range(loops):
|
| 28 |
-
rt.infer(x)
|
| 29 |
-
sec = time.perf_counter() - t0
|
| 30 |
-
ips = (b * loops) / max(sec, 1e-9)
|
| 31 |
-
result = {
|
| 32 |
-
"requested_accelerator": accelerator,
|
| 33 |
-
"selected_runtime": rt.backend,
|
| 34 |
-
"foundation_backend": enc.backend,
|
| 35 |
-
"batch_size": b,
|
| 36 |
-
"loops": loops,
|
| 37 |
-
"seconds": sec,
|
| 38 |
-
"foundation_images_per_second": ips,
|
| 39 |
-
"foundation_only_estimate_minutes_30000_images": 30000.0 / max(ips, 1e-9) / 60.0,
|
| 40 |
-
"note": "This measures frozen foundation inference only; JPEG/Parquet decode and forensic branches add extra time.",
|
| 41 |
-
}
|
| 42 |
-
rt.release_accelerator_memory()
|
| 43 |
-
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|