ray.train.v2.api.context.TrainContext.get_world_size#
- TrainContext.get_world_size() int [source]#
Get the current world size (i.e. total number of workers) for this run.
import ray from ray import train from ray.train import ScalingConfig from ray.train.tensorflow import TensorflowTrainer NUM_WORKERS = 2 def train_loop_per_worker(config): assert train.get_context().get_world_size() == NUM_WORKERS trainer = TensorflowTrainer( train_loop_per_worker, scaling_config=ScalingConfig(num_workers=NUM_WORKERS), ) trainer.fit()