Run on one machine
With the role both, your script and the workers run on the same machine. This is the default
when no cluster address is set.
Configuration
runner:
plugin: ray
options:
workers_per_node: 4
hosts_per_worker: 16
Or in code:
from nornir_ray import RayRunner
nr = nr.with_runner(RayRunner(workers_per_node=4, hosts_per_worker=16))
What the runner does with Ray
At the first run, the runner looks for a Ray in the Python process:
- Ray is already started in the process, because your script called
ray.init(). The runner uses it and never stops it. - No Ray is started. The runner starts a new local Ray on this machine. It does so even
when the machine has joined a cluster with
ray start. The runner stops this Ray when the last open runner of the process closes, or when the process exits.
Do not set an address with the role both
An address tells the runner which cluster to join. The role both never joins a cluster, so
an address with this role is an error: the run fails with RunnerSettingsError before any host
starts.
This applies to the environment variable RAY_ADDRESS too. If your shell sets RAY_ADDRESS,
do one of these:
- unset the variable for this script;
- set the role
workerorserverto run on the cluster at that address.
Choose the number of workers
workers_per_node × hosts_per_worker hosts run at the same time. The defaults give 64.
- Each worker is one Python process. More workers use more processor cores and more memory.
- Sync tasks run in threads inside a worker. Async tasks run on the worker's event loop.
- This documentation makes no performance claim. Measure with your own tasks and devices before you change the defaults.
Stop the workers
nr.runner.close()
close() stops the workers of the runner when no other open runner in the process shares them.
When the runner started Ray, close() also stops that Ray once no other open runner in the
process uses it. The runner does the same when the process exits.