Spaces:
Running on Zero
Running on Zero
Download src/epills/core/inference/runtime.py from DavidPanSX/pharmascan-api: direct link, hf CLI and curl.
- Browser
- Download file 976 Bytes
-
https://huggingface.co/spaces/DavidPanSX/pharmascan-api/resolve/main/src/epills/core/inference/runtime.py
- Command line
-
hf download hf://spaces/DavidPanSX/pharmascan-api/src/epills/core/inference/runtime.py
-
curl -L -o runtime.py https://huggingface.co/spaces/DavidPanSX/pharmascan-api/resolve/main/src/epills/core/inference/runtime.py
976 Bytes
| """The CPUs this process can really use (latency: too many threads on a container's few cores slow PyTorch down).""" | |
| import os | |
| def cpu_cores(): | |
| """The container's CPU quota (cgroup v2, then v1), else the CPUs this process may run on, else os.cpu_count().""" | |
| for quota_file, period_file in (("/sys/fs/cgroup/cpu.max", None), | |
| ("/sys/fs/cgroup/cpu/cpu.cfs_quota_us", "/sys/fs/cgroup/cpu/cpu.cfs_period_us")): | |
| try: | |
| if period_file is None: | |
| quota, period = open(quota_file).read().split()[:2] | |
| else: | |
| quota, period = open(quota_file).read().strip(), open(period_file).read().strip() | |
| if quota not in ("max", "-1"): | |
| return max(1, int(int(quota) / int(period))) | |
| except (OSError, ValueError): | |
| pass | |
| if hasattr(os, "sched_getaffinity"): | |
| return max(1, len(os.sched_getaffinity(0))) | |
| return max(1, os.cpu_count() or 1) | |