TorchftConfig#

class ray.train.torch.TorchftConfig(lighthouse_kwargs: Dict[str, Any], **kwargs)[source]#

Bases: TorchConfig

Configuration for fault-tolerant training with torchft.

Pass this as the torch_config of a TorchTrainer to train with torchft. Ray Train then starts the torchft Lighthouse server as an actor on the node that runs the Ray Train controller, which is usually the head node. It sets the TORCHFT_LIGHTHOUSE environment variable on every training worker and creates one process group per replica group instead of one process group across all workers. Each Ray Train worker is its own replica group. When a worker fails, Ray Train replaces only that replica group instead of restarting the whole worker group, and the replacement recovers model and optimizer state from a live peer through torchft.

Your training function must also create a torchft.Manager and wrap the model and optimizer with the torchft primitives. See Fault-tolerant training with torchft for a complete example.

Example

from ray.train import FailureConfig, RunConfig, ScalingConfig
from ray.train.torch import TorchftConfig, TorchTrainer

trainer = TorchTrainer(
    train_func,
    scaling_config=ScalingConfig(num_workers=2),
    torch_config=TorchftConfig(
        lighthouse_kwargs={"min_replicas": 1},
        backend="gloo",
    ),
    run_config=RunConfig(
        failure_config=FailureConfig(max_failures=3),
    ),
)
Parameters:
  • lighthouse_kwargs (Dict[str, Any]) – Keyword arguments for the torchft.coordination.LighthouseServer constructor. min_replicas is required: the minimum number of replica groups that must be alive to form a quorum and keep training. bind defaults to "[::]:0", which binds the Lighthouse to a free port on the Lighthouse’s node. The torchft version you install defines the remaining keys, such as join_timeout_ms, quorum_tick_ms, and heartbeat_timeout_ms.

  • **kwargs – Additional keyword arguments for the TorchConfig constructor, such as backend="gloo" or backend="nccl".

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

Methods

Attributes

backend

backend_cls

The Backend class that sets up this framework on the workers.

framework

The training framework this config sets up.

init_method

timeout_s

train_func_context

The context manager class wrapping each worker's training function.