-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(train): add auto-scaling option for Multi-GPU Training #2254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nijkah
wants to merge
7
commits into
huggingface:main
Choose a base branch
from
nijkah:feature/auto_scale
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+169
−25
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
396106a
feat(train): add auto-scale for multi-GPU
nijkah 33a0faf
docs(multi-gpu): document --auto_scale flag and cadence note
nijkah b9011ed
feat(train): apply LR scaling to policy
nijkah 77c5fc4
Use explicit warning for the attribution error
nijkah d1dceb9
Update src/lerobot/scripts/lerobot_train.py
nijkah ed6f84f
Update src/lerobot/scripts/lerobot_train.py
nijkah 2677421
Merge branch 'main' into feature/auto_scale
pkooij File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| import os | ||
| import subprocess | ||
| import tempfile | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
|
|
||
| def get_num_available_gpus(): | ||
| if not torch.cuda.is_available(): | ||
| return 0 | ||
| return torch.cuda.device_count() | ||
|
|
||
|
|
||
| def run_training_with_auto_scale(config_args, num_processes=2, temp_dir=None): | ||
| config_path = Path(temp_dir) / "accelerate_config.yaml" | ||
|
|
||
| with open(config_path, "w") as f: | ||
| f.write("compute_environment: LOCAL_MACHINE\n") | ||
| f.write("distributed_type: MULTI_GPU\n") | ||
| f.write("mixed_precision: 'no'\n") | ||
| f.write(f"num_processes: {num_processes}\n") | ||
| f.write("use_cpu: false\n") | ||
| f.write("gpu_ids: all\n") | ||
| f.write("downcast_bf16: 'no'\n") | ||
| f.write("machine_rank: 0\n") | ||
| f.write("main_training_function: main\n") | ||
| f.write("num_machines: 1\n") | ||
| f.write("rdzv_backend: static\n") | ||
| f.write("same_network: true\n") | ||
|
|
||
| cmd = [ | ||
| "accelerate", | ||
| "launch", | ||
| "--config_file", | ||
| str(config_path), | ||
| "-m", | ||
| "lerobot.scripts.lerobot_train", | ||
| ] + config_args | ||
|
|
||
| result = subprocess.run( | ||
| cmd, | ||
| capture_output=True, | ||
| text=True, | ||
| env={**os.environ, "CUDA_VISIBLE_DEVICES": ",".join(map(str, range(num_processes)))} | ||
| ) | ||
|
|
||
| return result | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| get_num_available_gpus() < 2, | ||
| reason="Auto-scale test requires at least 2 GPUs", | ||
| ) | ||
| def test_auto_scale_steps_and_lr(): | ||
| with tempfile.TemporaryDirectory() as temp_dir: | ||
| output_dir = Path(temp_dir) / "outputs" | ||
|
|
||
| base_steps = 20 | ||
| args = [ | ||
| "--dataset.repo_id=lerobot/pusht", | ||
| "--dataset.episodes=[0]", | ||
| "--policy.type=act", | ||
| "--policy.device=cuda", | ||
| "--policy.push_to_hub=false", | ||
| f"--output_dir={output_dir}", | ||
| "--batch_size=4", | ||
| f"--steps={base_steps}", | ||
| "--eval_freq=-1", | ||
| "--log_freq=5", | ||
| "--save_freq=10", | ||
| "--seed=42", | ||
| "--num_workers=0", | ||
| "--auto_scale=true", | ||
| ] | ||
|
|
||
| result = run_training_with_auto_scale(args, num_processes=2, temp_dir=temp_dir) | ||
|
|
||
| assert result.returncode == 0, ( | ||
| f"Training failed with auto-scale enabled.\nSTDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}" | ||
| ) | ||
|
|
||
| # Check for auto-scale log message indicating steps were scaled | ||
| combined = result.stdout + "\n" + result.stderr | ||
| assert "Auto-scale enabled with world_size=2" in combined | ||
| assert "steps 20 -> 10" in combined or "steps 20 " in combined |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.