models.lsi_dispatcher
– Dispatcher for distributed LSI¶Dispatcher process which orchestrates distributed LsiModel
computations.
Run this script only once, on any node in your cluster.
Notes
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.
Install needed dependencies (Pyro4)
pip install gensim[distributed]
Setup serialization (on each machine)
export PYRO_SERIALIZERS_ACCEPTED=pickle
export PYRO_SERIALIZER=pickle
Run nameserver
python -m Pyro4.naming -n 0.0.0.0 &
Run workers (on each machine)
python -m gensim.models.lsi_worker &
Run dispatcher
python -m gensim.models.lsi_dispatcher &
Run LsiModel
in distributed mode:
>>> from gensim.test.utils import common_corpus, common_dictionary >>> from gensim.models import LsiModel >>> >>> model = LsiModel(common_corpus, id2word=common_dictionary, distributed=True)
...
positional arguments:
maxsize Maximum number of jobs to be kept pre-fetched in the queue.
optional arguments:
-h, --help show this help message and exit
gensim.models.lsi_dispatcher.
Dispatcher
(maxsize=0)¶Bases: object
Dispatcher object that communicates and coordinates individual workers.
Warning
There should never be more than one dispatcher running at any one time.
Partly initialize 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.
exit
()¶Terminate all registered workers and then the dispatcher.
getjob
(worker_id)¶Atomically pop a job from the queue.
worker_id (int) – The worker that requested the job.
The corpus in BoW format.
iterable of iterable of (int, float)
getstate
()¶Merge projections from across all workers and get the final projection.
The current projection of the total model.
getworkers
()¶Get pyro URIs of all registered workers.
The pyro URIs for each worker.
list of URIs
initialize
(**model_params)¶Fully initialize the dispatcher and all its workers.
**model_params – Keyword parameters used to initialize individual workers
(gets handed all the way down to gensim.models.lsi_worker.Worker.initialize()
).
See LsiModel
.
RuntimeError – When no workers are found (the gensim.model.lsi_worker
script must be ran beforehand).
jobdone
(workerid)¶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.lsi_dispatcher.Dispatcher.jobdone()
and gensim.models.lsi_worker.Worker.requestjob()
.
workerid (int) – The ID of the worker that finished the job (used for logging).
jobsdone
()¶Wrap _jobsdone
, needed for remote access through proxies.
Number of jobs already completed.
int
putjob
(job)¶Atomically add a job to the queue.
job (iterable of list of (int, float)) – The corpus in BoW format.
reset
()¶Re-initialize all workers for a new decomposition.