fix(vram): model.to(cpu) eviction in free_cuda and run_rmu
Browse files
scripts/__pycache__/smoke_l4.cpython-312.pyc
CHANGED
|
Binary files a/scripts/__pycache__/smoke_l4.cpython-312.pyc and b/scripts/__pycache__/smoke_l4.cpython-312.pyc differ
|
|
|
scripts/smoke_l4.py
CHANGED
|
@@ -148,13 +148,22 @@ def reset_gpu_peak() -> None:
|
|
| 148 |
|
| 149 |
|
| 150 |
def free_cuda(*objs) -> None:
|
|
|
|
| 151 |
import torch
|
| 152 |
|
| 153 |
for obj in objs:
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
gc.collect()
|
| 156 |
if torch.cuda.is_available():
|
| 157 |
torch.cuda.empty_cache()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
|
| 160 |
# ---------------------------------------------------------------------------
|
|
@@ -389,6 +398,18 @@ def run_rmu(model_name: str, bench_repo: str, workdir: Path, telemetry: Telemetr
|
|
| 389 |
"elapsed_s": round(time.time() - t0, 1),
|
| 390 |
}
|
| 391 |
telemetry.push_json("rmu.json", result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
free_cuda(updated, model, frozen, trainer, tok)
|
| 393 |
return result
|
| 394 |
|
|
@@ -451,6 +472,11 @@ def run_circuitkit(
|
|
| 451 |
telemetry.push_json("circuitkit.json", result)
|
| 452 |
return result
|
| 453 |
finally:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
free_cuda(circuit, tl_model)
|
| 455 |
|
| 456 |
|
|
|
|
| 148 |
|
| 149 |
|
| 150 |
def free_cuda(*objs) -> None:
|
| 151 |
+
import gc
|
| 152 |
import torch
|
| 153 |
|
| 154 |
for obj in objs:
|
| 155 |
+
if obj is not None and hasattr(obj, "to"):
|
| 156 |
+
try:
|
| 157 |
+
obj.to("cpu")
|
| 158 |
+
except Exception:
|
| 159 |
+
pass
|
| 160 |
gc.collect()
|
| 161 |
if torch.cuda.is_available():
|
| 162 |
torch.cuda.empty_cache()
|
| 163 |
+
try:
|
| 164 |
+
torch.cuda.ipc_collect()
|
| 165 |
+
except Exception:
|
| 166 |
+
pass
|
| 167 |
|
| 168 |
|
| 169 |
# ---------------------------------------------------------------------------
|
|
|
|
| 398 |
"elapsed_s": round(time.time() - t0, 1),
|
| 399 |
}
|
| 400 |
telemetry.push_json("rmu.json", result)
|
| 401 |
+
try:
|
| 402 |
+
model.to("cpu")
|
| 403 |
+
frozen.to("cpu")
|
| 404 |
+
updated.to("cpu")
|
| 405 |
+
except Exception:
|
| 406 |
+
pass
|
| 407 |
+
if hasattr(trainer, "model"):
|
| 408 |
+
trainer.model = None
|
| 409 |
+
if hasattr(trainer, "frozen_model"):
|
| 410 |
+
trainer.frozen_model = None
|
| 411 |
+
if hasattr(trainer, "optimizer"):
|
| 412 |
+
trainer.optimizer = None
|
| 413 |
free_cuda(updated, model, frozen, trainer, tok)
|
| 414 |
return result
|
| 415 |
|
|
|
|
| 472 |
telemetry.push_json("circuitkit.json", result)
|
| 473 |
return result
|
| 474 |
finally:
|
| 475 |
+
try:
|
| 476 |
+
if tl_model is not None and hasattr(tl_model, "to"):
|
| 477 |
+
tl_model.to("cpu")
|
| 478 |
+
except Exception:
|
| 479 |
+
pass
|
| 480 |
free_cuda(circuit, tl_model)
|
| 481 |
|
| 482 |
|