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

Aperta
#4,552 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
machine-learning, python

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Python
Stelle
2.6k
Fork
809
Merge medio
1g 1h
PR unite (30g)
79

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di scverse/scanpy

Tutte le issue di scverse/scanpy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.