Repository navigation
Tseah/torchft prototype - #59989
Tseah/torchft prototype#59989TimothySeah wants to merge 20 commits into
Conversation
Signed-off-by: Lonnie Liu <[email protected]>
cherrypick ray-project#59494 Signed-off-by: Lonnie Liu <[email protected]>
… 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]>
There was a problem hiding this comment.
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.
|
|
||
|
|
||
| def train_func(): | ||
| os.environ["TORCHFT_LIGHTHOUSE"] = "http://ip-10-0-50-13:29510" |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
| 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}') | |
| ") |
| # 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 |
There was a problem hiding this comment.
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.
| lighthouse = LighthouseServer( | ||
| bind="[::]:0", min_replicas=1, join_timeout_ms=60000 | ||
| ) | ||
| env_vars.setdefault( | ||
| TORCHFT_LIGHTHOUSE_ENV_VAR, | ||
| lighthouse.address(), | ||
| ) |
There was a problem hiding this comment.
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]>
6fd5712 to
5e5fd88
Compare
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]>
This reverts commit 436def7.
Signed-off-by: Timothy Seah <[email protected]>
Signed-off-by: Timothy Seah <[email protected]>
|
This prototype works: intentionally closing. |
Signed-off-by: Timothy Seah <[email protected]>
Signed-off-by: Timothy Seah <[email protected]>
|
Intentionally closing working prototype |
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:
Testing
I tested this prototype by:
Replacing a faulty worker takes ~5s:
and the next step happens ~18s after that, but that number depends on checkpoint size.
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}