Download core/parallel.py from JG1310/repro-swf-allocation-bundle: direct link, hf CLI and curl.
- Browser
- Download file 583 Bytes
-
https://huggingface.co/datasets/JG1310/repro-swf-allocation-bundle/resolve/main/core/parallel.py
- Command line
-
hf download hf://datasets/JG1310/repro-swf-allocation-bundle/core/parallel.py
-
curl -L -o parallel.py https://huggingface.co/datasets/JG1310/repro-swf-allocation-bundle/resolve/main/core/parallel.py
583 Bytes
| """Shared joblib parallel grid runner (spec: specs/exp00_core.md).""" | |
| import os | |
| from joblib import Parallel, delayed | |
| def get_n_jobs(): | |
| return int(os.environ.get("JOB_CORES", "1")) | |
| def _run_one(func, item): | |
| os.environ["OMP_NUM_THREADS"] = "1" | |
| return func(item) | |
| def run_grid(func, items, n_jobs=None): | |
| """Run func(item) over items via joblib loky backend, correct (only slower) at n_jobs=1.""" | |
| if n_jobs is None: | |
| n_jobs = get_n_jobs() | |
| return Parallel(n_jobs=n_jobs, backend="loky")( | |
| delayed(_run_one)(func, item) for item in items | |
| ) | |