ray.air.session.get_local_world_size#

ray.air.session.get_local_world_size() int[source]#

Get the local rank of this worker (rank of the worker on its node).

Example

>>> import ray
>>> from ray.air import session
>>> from ray.air.config import ScalingConfig
>>> from ray.train.torch import TorchTrainer
>>>
>>> def train_loop_per_worker():
...     return session.get_local_world_size()
>>>
>>> train_dataset = ray.data.from_items(
...     [{"x": x, "y": x + 1} for x in range(32)])
>>> trainer = TorchTrainer(train_loop_per_worker,
...     scaling_config=ScalingConfig(num_workers=1),
...     datasets={"train": train_dataset})
>>> trainer.fit()