get_world_rank#

abstractmethod TrainContext.get_world_rank() → int[source]#

Get the world rank of this worker.

Examples

>>> import ray.train
>>> from ray.train.torch import TorchTrainer
>>> def train_fn_per_worker(config):
...     if ray.train.get_context().get_world_rank() == 0:
...         print("Worker 0")
>>> trainer = TorchTrainer(
...     train_fn_per_worker,
...     scaling_config=ray.train.ScalingConfig(num_workers=2),
... )
>>> print("[ignore]"); trainer.fit()
[ignore]...
Returns:

This worker’s rank among all workers in this run.

Return type:

int