Skip to content

Dask hangs when running certain tasks depending on number of nodes  #5229

Closed

Description

@ivirshup

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.

from umap import UMAP
import dask
from dask.distributed import Client
import numpy as np
from functools import reduce

def run_umap(data, n_neighbors, min_dist) -> np.ndarray:
    return UMAP(n_neighbors=n_neighbors, min_dist=min_dist).fit_transform(data)

def sum_all(x):
    return reduce(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 larger
data = np.random.random_sample((100, 100))
comps = []

for n in np.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":

bokeh_plot

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!

Activity

  1. TomAugspurger commented on Aug 6, 2019

    @TomAugspurger
    Member

    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?

  2. jrbourbeau commented on Aug 6, 2019

    @jrbourbeau
    Member

    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

  3. ivirshup commented on Aug 7, 2019

    @ivirshup
    Author

    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?

  4. TomAugspurger commented on Aug 7, 2019

    @TomAugspurger
    Member

    Should I also expect potential halting with any library that might multithread its operations?

    It depends. https://docs.dask.org/en/latest/array-best-practices.html?highlight=OMP_NUM_THREADS#avoid-oversubscribing-threads may be worth reading.

    Is there a way I could just pass a dict of environment variables?

    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.

  5. flying-sheep commented on May 13, 2025

    @flying-sheep
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions