Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve cpu count #26

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions geo_inference/geo_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import gc
import re
import sys
import platform
import time
import torch
import pystac
Expand Down Expand Up @@ -182,8 +183,13 @@ async def async_run_inference(self,

"""

# configuring dask
num_workers = len(os.sched_getaffinity(0)) - 1 if workers == 0 else workers
# configuring dask with proper number of workers, alternatively we could also use os.getenv('SLURM_CPUS_PER_TASK')
if workers != 0:
num_workers = workers
elif 'linux' in platform.uname().system.lower():
num_workers = len(os.sched_getaffinity(0)) - 1
else:
num_workers = os.cpu_count() - 1
print(f"running dask with {num_workers} workers")
config.set(scheduler='threads', num_workers=num_workers)
config.set(pool=ThreadPool(num_workers))
Expand Down
Loading