You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dask hangs when running certain tasks depending on number of nodes #5229
I'm sure there's a more succinct title, but it's the best I can explain it. Dask just seems to hang if I run UMAP multiple times.
I've been able to trigger this behavior by running UMAP with different parameters in parallel using dask. Some of the computations may complete before the process hangs. I think this is dependent on the number of computations and workers.
fromumapimportUMAPimportdaskfromdask.distributedimportClientimportnumpyasnpfromfunctoolsimportreducedefrun_umap(data, n_neighbors, min_dist) ->np.ndarray:
returnUMAP(n_neighbors=n_neighbors, min_dist=min_dist).fit_transform(data)
defsum_all(x):
returnreduce(np.add, x)
client=Client() # This also occurs with the threaded schedueler# dask.config.set(scheduler='threads')N=10# Some may complete, seems like fewer complete when N is largerdata=np.random.random_sample((100, 100))
comps= []
forninnp.linspace(0, 1, N):
comps.append(dask.delayed(run_umap)(data, 15, n))
job=dask.delayed(sum_all)(comps)
job.compute()
After some of the tasks complete (sometimes none), the task graph have some nodes stuck at "processing":
Version info: python==3.7.3 dask==2.2.0 distributed==2.2.0 umap-learn==0.3.9 numba==0.45.1
My actual use case involves just using the graph building parts of UMAP (similar to pynndescent) which still triggers this behavior but takes more setup. My suspicion is that it has something to do with how UMAP heavy use of numba, or I've done something terribly wrong. I'd definitely appreciate any tips or suggestions for what to try when debugging. Thanks for any help!
I notice that the tasks finish when the workers are started with one thread per worker (Client(threads_per_worker=1) Do you know how if UMAP interacts well with multiple threads?
UMAP utilizes @numba.njit(parallel=True) throughout its codebase. Numba and Dask aren't currently able to share threadpools, so using multi-threaded Numba and multi-threaded Dask can lead to the type of hanging you're seeing @ivirshup. See #5132 for another example. I'd recommend either using single-threaded Dask (as @TomAugspurger pointed out), or using single-threaded Numba
Thanks! Setting the threads_per_worker=1 worked great! Should I also expect potential halting with any library that might multithread its operations?
I'd like to try telling numba to use a single thread in each of the worker processes. I think I've got that working by creating a script containing import os; os.environ["NUMBA_NUM_THREADS"] = "1" and passing that to Client(preload=["path/to/script.py"]). Is there a way I could just pass a dict of environment variables?
Activity
TomAugspurger commentedon Aug 6, 2019
I notice that the tasks finish when the workers are started with one thread per worker (
Client(threads_per_worker=1) Do you know how if UMAP interacts well with multiple threads?jrbourbeau commentedon Aug 6, 2019
UMAP utilizes
@numba.njit(parallel=True)throughout its codebase. Numba and Dask aren't currently able to share threadpools, so using multi-threaded Numba and multi-threaded Dask can lead to the type of hanging you're seeing @ivirshup. See #5132 for another example. I'd recommend either using single-threaded Dask (as @TomAugspurger pointed out), or using single-threaded Numbaivirshup commentedon Aug 7, 2019
Thanks! Setting the
threads_per_worker=1worked great! Should I also expect potential halting with any library that might multithread its operations?I'd like to try telling numba to use a single thread in each of the worker processes. I think I've got that working by creating a script containing
import os; os.environ["NUMBA_NUM_THREADS"] = "1"and passing that toClient(preload=["path/to/script.py"]). Is there a way I could just pass a dict of environment variables?TomAugspurger commentedon Aug 7, 2019
It depends. https://docs.dask.org/en/latest/array-best-practices.html?highlight=OMP_NUM_THREADS#avoid-oversubscribing-threads may be worth reading.
Depends on which cluster manager you're using. https://docs.dask.org/en/latest/setup.html. If you're using a LocalCluster like in the original example, I think the subprocess inherits them from the process creating the LocalCluster.
LMK if there are other issues remaining here, and I'll reopen.
flying-sheep commentedon May 13, 2025
Joblib has a bigger array of env variables that it sets, you should use the same list:
https://github.com/joblib/joblib/blob/ed0806a497268005ad7dad30f79e1d563927d7c6/joblib/_parallel_backends.py#L59-L67