ray.train.context.TrainContext.get_world_rank#
- TrainContext.get_world_rank() int [source]#
Get the world rank of this worker.
import ray from ray import train from ray.train import ScalingConfig from ray.train.tensorflow import TensorflowTrainer def train_loop_per_worker(config): if train.get_context().get_world_rank() == 0: print("Worker 0") train_dataset = ray.data.read_csv("s3://anonymous@ray-example-data/iris.csv") trainer = TensorflowTrainer( train_loop_per_worker, scaling_config=ScalingConfig(num_workers=2), datasets={"train": train_dataset} ) trainer.fit()
PublicAPI (beta): This API is in beta and may change before becoming stable.