Document and classify `n_jobs` related things to be done to be robust against oversubscription

Abierto
#4,552 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
38/100
Tipo de issue
Documentación
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
machine-learning, python

Línea de trabajo

Start by reviewing the listed work items and the linked fast-array-utils issue #245, which the proposed scheduler guidance depends on. The issue calls for documenting LocalCluster setup and use, scheduler behavior, and BLAS oversubscription nuances; it does not name documentation files or tests. Done means those behaviors and recommendations are documented after the related kernel and scheduler work is complete.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Meta

Here I blissfuly ignore the fact that BLAS related oversubscriptions mainly because:

  • They already exist, with or without my following suggestions
  • It is caused by our usage of dask-ml and we can't do anything about it except to switch defaults from dask-ml. In their documentation they left the BLAS up to the user to set.
  • We can wrap our gram_block with the threadpool_limits(1, user_api="blas") but we'd need concrete evidence it hurts performance before

If we release the GIL or parallelize ourselves all of our kernels, the reasons to use LocalCluster would narrow down to:

  • .persist() of data larger than RAM. Only distributed can spill to disk and enforce memory limits
  • h5py-backed lazy data. h5py takes a global lock, so threads read one at a time. Separate processes can each open the file.

This would then be a narrow use case IMO and since LocalCluster is the only case I can think of which causes oversubscription (this is true only after https://github.com/scverse/fast-array-utils/issues/245) , we can just explicitly document usage of LocalCluster as the following

import dask
dask.config.set({"distributed.nanny.pre-spawn-environ.NUMBA_NUM_THREADS": "1"})
cluster = LocalCluster(...)  # must come after

Then we can safely have defaults which would maximize the utilization of cores.

Still need to do:

  • Make the 29 numba kernels of scanpy to respect the n_jobs ( I think this is why no one actually complained about speed so far, even though the default is only 4)
  • We can also make BLAS kernels respect n_jobs but I feel like this is ignored in general. The problem with BLAS kernals happens when they are inside dask tasks.
  • https://github.com/scverse/fast-array-utils/issues/245 for fixing oversubscribing via the dask scheduler=threaded path.
  • Set nogil=True in our scanpy cases like _sum_and_sum_squares_clipped
  • Document scheduler=processes should not be used unless you know what you are doing. (We can't say this atm, the user now needs to know implementation details to use process based scheduler is optimal for performance or not). When we fix https://github.com/scverse/fast-array-utils/issues/245, we can say we work optimally for scheduler=threaded for all of our functions.
  • Document how to handle LocalCluster and when to use it.
  • Document the BLAS related nuances for oversubscription, it happens only when

In short after these are done, for scanpy we can say:

  • in-memory input: kernels on the main thread use n_jobs threads
  • dask input: chunk tasks are limited by dask's num_workers, and each task runs serially after scverse/fast-array-utils#245
Lenguaje dominante
Python
Estrellas
2.6k
Forks
809
Merge medio
1 d 1 h
PR fusionados (30 d)
79

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de scverse/scanpy

Todos los issues de scverse/scanpy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.