Skip to content

Tseah/torchft prototype - #59989

Closed
TimothySeah wants to merge 20 commits into
ray-project:masterfrom
TimothySeah:tseah/torchft-prototype
Closed

TimothySeah wants to merge 20 commits into
ray-project:masterfrom
TimothySeah:tseah/torchft-prototype

Conversation

@TimothySeah

@TimothySeah TimothySeah commented Jan 9, 2026 •

Copy link
Copy Markdown
Contributor

The description below is mostly accurate, but please look at #60820 instead, which correctly replaces replica groups instead of individual workers.

Summary

This is a prototype not intended for submission. It does the following:

  1. Modifies the Ray Train PyTorch example to use the same torchft primitives as this torchft example.
  2. DataParallelTrainer creates a LighthouseServer and passes that information to the train controller and workers
  3. When the Controller detects worker failures, it creates new workers with the same information (e.g. env vars, train context) and schedules them on the existing placement group.

Testing

I tested this prototype by:

  1. Running the driver script (2 workers)
  2. Killing the rank 1 main RayTrainWorker process. Note that killing the rank 0 main RayTrainWorker process causes training to fail entirely because rank 0 contains the TCPStore (used by MASTER_ADDR).
  3. Waiting for Ray Train to replace rank 1 and finish training.

Replacing a faulty worker takes ~5s:

2026-01-12 18:25:46.332 | Detected 1 bad/non-running workers. Replacing workers at world ranks: [1]
-- | --
I | 2026-01-12 18:25:46.334 | Replacing 1 workers at world ranks: [1]
I | 2026-01-12 18:25:46.336 | Retrieved distributed env vars from surviving worker: {'MASTER_ADDR': '10.0.105.178', 'MASTER_PORT': '46297'}
I | 2026-01-12 18:25:48.189 | Set distributed env vars on new workers: {'MASTER_ADDR': '10.0.105.178', 'MASTER_PORT': '46297'} (plus worker-specific RANK and LOCAL_RANK)
I | 2026-01-12 18:25:51.431 | Successfully replaced workers: - (ip=10.0.119.203, pid=39311) world_rank=1, local_rank=0, node_rank=1
I | 2026-01-12 18:25:51.432 | [State Transition] SCHEDULING -> RUNNING.

and the next step happens ~18s after that, but that number depends on checkpoint size.

2026-01-12T18:26:09.266 [INFO] [torchft::lighthouse] - Quorum! Quorum { quorum_id: 2, participants: [QuorumMember { replica_id: "train_ddp_0:983f2668-b891-44cc-9caf-28c29588352d", address: "http://ip-10-0-105-178:33689", store_address: "10.0.105.178:46297", step: 62, world_size: 1, shrink_only: false, commit_failures: 1, data: "" }, QuorumMember { replica_id: "train_ddp_1:b9c83efb-419b-4f22-a28c-170322b9d131", address: "http://ip-10-0-119-203:37793", store_address: "10.0.105.178:46297", step: 0, world_size: 1, shrink_only: false, commit_failures: 0, data: "" }], created: Some(Timestamp { seconds: 1768271169, nanos: 266410680 }) }

Appendix

Note that the statefuldataloader state_dict looks like this

{'_snapshot': {'_snapshot_step': 100, '_last_yielded_worker_id': 1, '_main_snapshot': {'_num_workers': 2, '_sampler_iter_state': {'samples_yielded': 6400}, '_index_sampler_state': None, '_sampler_iter_yielded': 100, '_IterableDataset_len_called': None, '_shared_seed': None, '_base_seed': 6301677103399260047}, '_worker_snapshots': {'worker_0': {'worker_id': 0, 'dataset_state': None, 'fetcher_state': None}, 'worker_1': {'worker_id': 1, 'dataset_state': None, 'fetcher_state': None}}}, '_steps_since_snapshot': 0, '_iterator_finished': False}

aslonnie and others added 5 commits December 16, 2025 14:30
… you request 0 GPUs on CPU-only cluster (ray-project#59516)

Cherry-pick of ray-project#59514

Signed-off-by: Balaji Veeramani <[email protected]>
…ct#59519)

EWMA_ALPHA
Update EWMA_ALPHA from 0.2->0.1. This makes adjusting level to be more in-favor of limiting concurrency by being more sensitive to downstreaming queuing.

K_DEV
Update K_DEV from 2.0->1.0. This makes stddev to be more in-favor of limiting concurrency by being more sensitive to downstreaming queuing.

cherry-pick of ray-project#59392
…oject#59606)

Created by release automation bot.

Update with commit 0de2118

Signed-off-by: Lonnie Liu <[email protected]>
Co-authored-by: Lonnie Liu <[email protected]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a prototype for integrating torchft with Ray Train to provide fault tolerance capabilities. The core changes include adding logic to replace failed workers in a WorkerGroup instead of restarting the entire group, and integrating torchft's LighthouseServer for coordination. The changes in ray.train.v2._internal.execution.controller and ray.train.v2._internal.execution.worker_group are well-structured to support this new worker replacement feature.

My review includes feedback on a hardcoded IP address in the example driver, a potential resource leak with LighthouseServer, improving debuggability in the copier.sh script, and a code duplication issue that affects maintainability. Overall, this is a solid prototype for the intended functionality.

Comment thread driver.py Outdated


def train_func():
os.environ["TORCHFT_LIGHTHOUSE"] = "http://ip-10-0-50-13:29510"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The TORCHFT_LIGHTHOUSE environment variable is hardcoded to a specific IP address. This will cause the example to fail on any machine other than the one with this IP. Since the changes in data_parallel_trainer.py automatically start a LighthouseServer and set this environment variable, this line is unnecessary and should be removed.

Comment thread copier.sh Outdated
Comment on lines +26 to +45
NODE_INFO=$(python -c "
import ray
ray.init(ignore_reinit_error=True)
nodes = ray.nodes()
head_ip = None
worker_ips = []
for node in nodes:
if node['Alive']:
ip = node['NodeManagerAddress']
if node.get('Resources', {}).get('node:__internal_head__'):
head_ip = ip
else:
worker_ips.append(ip)
# If no explicit head marker, use first node as head
if head_ip is None and worker_ips:
head_ip = worker_ips.pop(0)
print(f'HEAD:{head_ip or \"\"}')
for ip in worker_ips:
print(f'WORKER:{ip}')
" 2>/dev/null)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Python script to get node info redirects stderr to /dev/null. This can hide important error messages, for example if ray is not installed or if ray.init() fails. This makes debugging harder. It's better to let stderr be printed so that the user can see the actual error. The script already has a check for empty output, which will still work.

Suggested change
NODE_INFO=$(python -c "
import ray
ray.init(ignore_reinit_error=True)
nodes = ray.nodes()
head_ip = None
worker_ips = []
for node in nodes:
if node['Alive']:
ip = node['NodeManagerAddress']
if node.get('Resources', {}).get('node:__internal_head__'):
head_ip = ip
else:
worker_ips.append(ip)
# If no explicit head marker, use first node as head
if head_ip is None and worker_ips:
head_ip = worker_ips.pop(0)
print(f'HEAD:{head_ip or \"\"}')
for ip in worker_ips:
print(f'WORKER:{ip}')
" 2>/dev/null)
NODE_INFO=$(python -c "
import ray
ray.init(ignore_reinit_error=True)
nodes = ray.nodes()
head_ip = None
worker_ips = []
for node in nodes:
if node['Alive']:
ip = node['NodeManagerAddress']
if node.get('Resources', {}).get('node:__internal_head__'):
head_ip = ip
else:
worker_ips.append(ip)
# If no explicit head marker, use first node as head
if head_ip is None and worker_ips:
head_ip = worker_ips.pop(0)
print(f'HEAD:{head_ip or \"\"}')
for ip in worker_ips:
print(f'WORKER:{ip}')
")

Comment on lines +699 to +711
# Get train context args from callbacks
train_context_args = {}
for callback in self._callbacks:
args = callback.before_init_train_context(new_workers)
for arg, arg_values in args.items():
assert len(arg_values) == len(new_workers), (
f"Callback {callback} returned {arg} with "
f"{len(arg_values)} values, expected {len(new_workers)}."
)
assert (
arg not in train_context_args
), f"Callback {callback} returned {arg} which is already set."
train_context_args[arg] = arg_values

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for getting train_context_args from callbacks is duplicated. A similar block of code exists in the _start_impl method.

To improve maintainability and reduce code duplication, consider extracting this logic into a private helper method, for example _get_train_context_args_from_callbacks(self, workers), which would take the list of workers and return the train_context_args dictionary. This new method could then be called from both replace_workers and _start_impl.

Comment on lines +264 to +270
lighthouse = LighthouseServer(
bind="[::]:0", min_replicas=1, join_timeout_ms=60000
)
env_vars.setdefault(
TORCHFT_LIGHTHOUSE_ENV_VAR,
lighthouse.address(),
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

A LighthouseServer instance is created, but its lifecycle is not managed. If the LighthouseServer starts a background process or thread, it might not be properly shut down when the trainer finishes, potentially leading to resource leaks. Please ensure that the LighthouseServer is properly cleaned up. If it supports a context manager protocol (with statement) or has a shutdown()/close() method, it should be used.

Signed-off-by: Timothy Seah <[email protected]>
Signed-off-by: Timothy Seah <[email protected]>
Signed-off-by: Timothy Seah <[email protected]>
Signed-off-by: Timothy Seah <[email protected]>
Signed-off-by: Timothy Seah <[email protected]>
@TimothySeah
TimothySeah force-pushed the tseah/torchft-prototype branch from 6fd5712 to 5e5fd88 Compare January 9, 2026 01:34
@TimothySeah

Copy link
Copy Markdown
Contributor Author

This prototype works: intentionally closing.

@TimothySeah TimothySeah reopened this Jan 19, 2026
Signed-off-by: Timothy Seah <[email protected]>
@TimothySeah

Copy link
Copy Markdown
Contributor Author

Intentionally closing working prototype

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants