gensim logo

gensim tagline

Get Expert Help From The Gensim Authors

Consulting in Machine Learning & NLP

• Commercial document similarity engine:

Corporate trainings in Python Data Science and Deep Learning

models.lda_dispatcher – Dispatcher for distributed LDA

models.lda_dispatcher – Dispatcher for distributed LDA

Dispatcher process which orchestrates distributed Latent Dirichlet Allocation (LDA, LdaModel) computations. Run this script only once, on any node in your cluster.


The dispatcher expects to find worker scripts already running. Make sure you run as many workers as you like on your machines before launching the dispatcher.

How to use distributed LdaModel

  1. Install needed dependencies (Pyro4)

    pip install gensim[distributed]
  2. Setup serialization (on each machine)

    export PYRO_SERIALIZER=pickle
  3. Run nameserver

    python -m Pyro4.naming -n &
  4. Run workers (on each machine)

    python -m gensim.models.lda_worker &
  5. Run dispatcher

    python -m gensim.models.lda_dispatcher &
  6. Run LdaModel in distributed mode

    >>> from gensim.test.utils import common_corpus,common_dictionary
    >>> from gensim.models import LdaModel
    >>> model = LdaModel(common_corpus, id2word=common_dictionary, distributed=True)

Command line arguments

  -h, --help         show this help message and exit
  --maxsize MAXSIZE  How many jobs (=chunks of N documents) to keep 'pre-fetched' in a queue (default: 10)
  --host HOST        Nameserver hostname (default: None)
  --port PORT        Nameserver port (default: None)
  --no-broadcast     Disable broadcast (default: True)
  --hmac HMAC        Nameserver hmac key (default: None)
  -v, --verbose      Verbose flag
class gensim.models.lda_dispatcher.Dispatcher(maxsize=10, ns_conf=None)

Dispatcher object that communicates and coordinates individual workers.


There should never be more than one dispatcher running at any one time.

Partly initializes the dispatcher.

A full initialization (including initialization of the workers) requires a call to initialize()

  • maxsize (int, optional) – Maximum number of jobs to be kept pre-fetched in the queue.
  • ns_conf (dict of (str, object)) – Sets up the name server configuration for the pyro daemon server of dispatcher. This also helps to keep track of your objects in your network by using logical object names instead of exact object name(or id) and its location.

Terminate all registered workers and then the dispatcher.


Atomically pop a job from the queue.

Parameters:worker_id (int) – The worker that requested the job.
Returns:The corpus in BoW format.
Return type:iterable of list of (int, float)

Merge states from across all workers and return the result.

Returns:Merged resultant state
Return type:LdaState

Return pyro URIs of all registered workers.

Returns:The pyro URIs for each worker.
Return type:list of URIs

Fully initialize the dispatcher and all its workers.

Parameters:**model_params – Keyword parameters used to initialize individual workers, see LdaModel.
Raises:RuntimeError – When no workers are found (the gensim.models.lda_worker script must be ran beforehand).
jobdone(*args, **kwargs)

A worker has finished its job. Log this event and then asynchronously transfer control back to the worker.

Callback used by workers to notify when their job is done.

The job done event is logged and then control is asynchronously transfered back to the worker (who can then request another job). In this way, control flow basically oscillates between gensim.models.lda_dispatcher.Dispatcher.jobdone() and gensim.models.lda_worker.Worker.requestjob().

Parameters:workerid (int) – The ID of the worker that finished the job (used for logging).

Wrap _jobsdone needed for remote access through proxies.

Returns:Number of jobs already completed.
Return type:int

Atomically add a job to the queue.

Parameters:job (iterable of list of (int, float)) – The corpus in BoW format.

Reinitialize all workers for a new EM iteration.

Parameters:state (LdaState) – State of LdaModel.