Spaces:
Running on Zero
Running on Zero
Let villa's pyramid step start its worker pool inside the ZeroGPU worker
Browse files- lasfield.py +24 -1
lasfield.py
CHANGED
|
@@ -437,6 +437,29 @@ def predict3d_argv(p, ct_input, out_json, checkpoint, device):
|
|
| 437 |
"--device", device, "--no-download", "--flush-workers", "0", "--accumulator-workers", "0"]
|
| 438 |
|
| 439 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
def run_villa_lasagna(p, ct_input, out_dir, device, checkpoint):
|
| 441 |
"""villa's predict3d in this process. Returns its exit code, wall seconds and the tail of its log."""
|
| 442 |
import contextlib
|
|
@@ -456,7 +479,7 @@ def run_villa_lasagna(p, ct_input, out_dir, device, checkpoint):
|
|
| 456 |
return len(s)
|
| 457 |
|
| 458 |
try:
|
| 459 |
-
with contextlib.redirect_stdout(Tee()), contextlib.redirect_stderr(Tee()):
|
| 460 |
rc = pco.cli_main(argv)
|
| 461 |
except SystemExit as exc:
|
| 462 |
rc = exc.code if isinstance(exc.code, int) else 1
|
|
|
|
| 437 |
"--device", device, "--no-download", "--flush-workers", "0", "--accumulator-workers", "0"]
|
| 438 |
|
| 439 |
|
| 440 |
+
POOL_CPUS = 8 # pyramid processes predict3d may start (its default is every CPU of the host)
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
@__import__("contextlib").contextmanager
|
| 444 |
+
def _pool_friendly():
|
| 445 |
+
"""Let predict3d's OME-Zarr pyramid step start its process pool when it runs inside a daemon process (ZeroGPU
|
| 446 |
+
runs a GPU call in one, and Python refuses children there), and cap that pool at POOL_CPUS. The pool's processes
|
| 447 |
+
only downsample chunks on the CPU. Restored on exit."""
|
| 448 |
+
import multiprocessing as mp
|
| 449 |
+
proc = mp.current_process()
|
| 450 |
+
was_daemon = proc._config.get("daemon")
|
| 451 |
+
real = mp.cpu_count
|
| 452 |
+
mp.cpu_count = lambda: max(1, min(POOL_CPUS, real()))
|
| 453 |
+
if was_daemon:
|
| 454 |
+
proc._config["daemon"] = False
|
| 455 |
+
try:
|
| 456 |
+
yield
|
| 457 |
+
finally:
|
| 458 |
+
mp.cpu_count = real
|
| 459 |
+
if was_daemon:
|
| 460 |
+
proc._config["daemon"] = was_daemon
|
| 461 |
+
|
| 462 |
+
|
| 463 |
def run_villa_lasagna(p, ct_input, out_dir, device, checkpoint):
|
| 464 |
"""villa's predict3d in this process. Returns its exit code, wall seconds and the tail of its log."""
|
| 465 |
import contextlib
|
|
|
|
| 479 |
return len(s)
|
| 480 |
|
| 481 |
try:
|
| 482 |
+
with contextlib.redirect_stdout(Tee()), contextlib.redirect_stderr(Tee()), _pool_friendly():
|
| 483 |
rc = pco.cli_main(argv)
|
| 484 |
except SystemExit as exc:
|
| 485 |
rc = exc.code if isinstance(exc.code, int) else 1
|