ray.train.context.TrainContext.get_node_rank#

TrainContext.get_node_rank() int[source]#

Get the rank of this node.

Example

import ray
from ray import train
from ray.train import ScalingConfig
from ray.train.torch import TorchTrainer

def train_loop_per_worker():
    print(train.get_context().get_node_rank())

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()

PublicAPI (beta): This API is in beta and may change before becoming stable.