Repository navigation
Distributed policy_runner on multi-gpu - #411
Conversation
alexmillane
left a comment
There was a problem hiding this comment.
Thanks for adding this capability. This is really awesome. I had a couple of small comments.
| Test the policy in 10 parallel environments on each GPU with 2 GPUs total run: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| python -m torch.distributed.run --nnode=1 --nproc_per_node=2 isaaclab_arena/evaluation/policy_runner.py \ | ||
| --policy_type isaaclab_arena_gr00t.policy.gr00t_closedloop_policy.Gr00tClosedloopPolicy \ | ||
| --policy_config_yaml_path isaaclab_arena_gr00t/policy/config/gr1_manip_gr00t_closedloop_config.yaml \ | ||
| --num_steps 2000 \ | ||
| --num_envs 10 \ | ||
| --enable_cameras \ | ||
| --headless \ | ||
| --distributed \ | ||
| gr1_open_microwave \ | ||
| --embodiment gr1_joint |
| isaac_lab_group.add_argument( | ||
| "--seed", type=int, default=None, help="Optional seed for the random number generator." | ||
| ) | ||
| isaac_lab_group.add_argument("--seed", type=int, default=42, help="Optional seed for the random number generator.") |
There was a problem hiding this comment.
This seems to be a behaviour change, we've moved to always having a seed? Is the intention here that we get the same results (ish) every time we run?
I'm thinking that this is probably a good change. It will make our results more deterministic.
What was your thinking here?
There was a problem hiding this comment.
Yes, I think it's important that locking the seed to make the run more deterministic from eval perspective.
| world_size = int(os.environ.get("WORLD_SIZE", "1")) | ||
| # Setting device to local rank before SimulationAppContext | ||
| if is_distributed(args_cli): | ||
| args_cli.distributed = True |
There was a problem hiding this comment.
Why set this True? It's checked in is_distributed, I'm wondering if there's some specific reason to set it here.
There was a problem hiding this comment.
great catch. forgot to remove, done.
| if seed is not None: | ||
| env.seed(seed) | ||
| torch.manual_seed(seed) | ||
| np.random.seed(seed) | ||
| random.seed(seed) |
There was a problem hiding this comment.
This is not from this MR, but shall we move this to isaaclab_arena/utils/random.py with a function called set_seeds()
| local_rank = int(os.environ.get("LOCAL_RANK", "0")) | ||
| # world size is the number of processes running the script, set by torchrun command | ||
| world_size = int(os.environ.get("WORLD_SIZE", "1")) |
There was a problem hiding this comment.
Suggestion to wrap these in isaaclab_arena/utils/multiprocess.py with functions like get_local_rank and get_world_size
| world_size = int(os.environ.get("WORLD_SIZE", "1")) | ||
| if world_size > 1 and "cuda" in config.policy_device: | ||
| local_rank = int(os.environ.get("LOCAL_RANK", "0")) |
There was a problem hiding this comment.
Suggestion to use functions (suggested above) for these
| if is_distributed(args_cli) and hasattr(cfg, "recorders") and cfg.recorders is not None: | ||
| base = getattr(cfg.recorders, "dataset_filename", "dataset") | ||
| cfg.recorders.dataset_filename = f"{base}_rank{local_rank}" |
There was a problem hiding this comment.
What do you think about moving this into the ArenaEnvBuilder. The arena env builder could take an optional argument distributed=False. If True, we can update the file name where the recorder manager where it is composed.
Solving it in the ArenaEnvBuilder, rather than this script, means that the fix works where ever arena environments are built.
There was a problem hiding this comment.
great suggestion. done
| .. tab:: Distribute Multi-GPU Evaluation | ||
|
|
||
| Test the policy in 5 parallel environments on each GPU with 2 GPUs total run: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| python -m torch.distributed.run --nnode=1 --nproc_per_node=2 isaaclab_arena/evaluation/policy_runner.py \ | ||
| --policy_type isaaclab_arena_gr00t.policy.gr00t_closedloop_policy.Gr00tClosedloopPolicy \ | ||
| --policy_config_yaml_path isaaclab_arena_gr00t/policy/config/g1_locomanip_gr00t_closedloop_config.yaml \ | ||
| --num_steps 1200 \ | ||
| --num_envs 5 \ | ||
| --enable_cameras \ | ||
| --device cuda \ | ||
| --policy_device cuda \ | ||
| --distributed \ | ||
| --headless \ | ||
| galileo_g1_locomanip_pick_and_place \ | ||
| --object brown_box \ | ||
| --embodiment g1_wbc_joint |
Deprecate multi-GPU evaluation with `torchrun` and `policy_runner.py --distributed`, and remove it from the evaluation tutorials. To use several GPUs, run an Experiment on OSMO, which runs each Run on its own GPU and combines the results; `policy_runner.py --distributed` still works but prints a `FutureWarning` until `policy_runner.py` is removed. ## Why this change? `torchrun` evaluation is one of the reasons the docs still send users to `policy_runner.py`, which we plan to deprecate in favor of `experiment_runner.py`. We decided to drop it rather than port it, because its results were never combined into one evaluation. Running in parallel itself works: `torchrun` starts one `policy_runner.py` process per GPU, and each process runs the full step or episode budget with `--seed` plus its rank, so more GPUs evaluate more episodes in the same time. What doesn't work is everything after the rollouts: - **There is no combined result.** Each process prints its own `Metrics:` line, and nothing adds them up into one success rate. - **The report can miss results.** Only the process with local rank 0 calls `build_report`, right after its own `env.close()`, without waiting for the others. It reads only its own output directory, and each process picks a timestamped directory (`timestamped_run_dir`) after Isaac Sim starts, so processes that get there in different seconds write to different directories. - **Videos can overwrite each other.** Video file names don't include the rank, so processes that share a directory write over each other's videos. - **Seeds repeat across machines.** The seed offset is the rank within one machine (`LOCAL_RANK`), so with more than one machine every machine runs the same episodes. The tutorials only use one machine. No test or CI job covers it. It was added in #411 for multi-GPU benchmarking of Arena environments. Each process ran its own simulation and its own local GR00T policy (`Gr00tClosedloopPolicy`). #662 removed `Gr00tClosedloopPolicy`. ## What changes? - `policy_runner.py` emits a `FutureWarning` when it gets `--distributed`. The warning also says that ranks do not merge their metrics and that the report from local rank 0 can miss results from other ranks. The shared `--distributed` flag itself stays unchanged, because `environment_registration_callback` reads it when it starts the app for RL training. - The "Distribute Multi-GPU Evaluation" tabs are removed from `step_5_evaluation.rst` in `sequential_static_manipulation` and `locomanipulation`. The single-GPU commands remain. The parallel command on the `sequential_static_manipulation` page also gets the `--viz kit` it was missing. - The "Choosing a runner" note in `docs/pages/concepts/concept_arena_experiments.rst` and the "Hand off other workflows" list in `skills/user/run-experiment/SKILL.md` no longer mention `torchrun`. **Using several GPUs instead:** - **On one machine:** evaluate in one process with more environments (`environment_builder.num_envs` in an Experiment). - **On several GPUs:** submit the Experiment to OSMO with `osmo/submit_arena_experiment.py` (see the Multi-Node Evaluation page). `ArenaExperimentWorkflow` runs each Run in its own OSMO group, starts its policy server next to it if needed, and collects all Runs into one Experiment result and report. A single Run uses one GPU, so spreading one configuration over several GPUs means splitting it into several Runs, for example with different seeds. - **Limitation:** `Gr00tServerTask` on OSMO only serves the GR00T DROID checkpoint, so the GR1 and G1 GR00T tutorials that lose their multi-GPU tab cannot move to OSMO as they are. The RL training page `reinforcement_learning/step_2_policy_training.rst` still passes `--distributed` to `train.py`. There, Isaac Lab's training CLI and Arena's `environment_registration_callback` both read it, and multi-GPU training is not deprecated. The release notes are written when a release is cut, so the deprecation should be listed in the next release's notes. ## Validation - Rebased onto `main` at `9b9e5b8350`. Before the rebase, CI passed: Run tests, Run tests with subprocess, GR00T closed-loop E2E, the docs build, and pre-commit. - Locally, in an Arena Docker image built from `main`: `test_distributed_evaluation_warns_about_deprecation` passes, `make SPHINXOPTS=-W html` in `docs/` passes, and `pre-commit` passes. - Not run locally: tests that start Isaac Sim. The image built from `main` uses PyTorch built for CUDA 13.0, which needs a newer NVIDIA driver than the test machine has. --------- Signed-off-by: Clemens Volk <[email protected]>
Summary
Product/PerfLab requires multi-gpu supports for benchmarking ILA envs. The ask is kinda urgent -- 'by early Feb'. It also introduces a great potential to support running large-scale eval, e.g. on cloud.
Detailed description
Results
TODO
Notes for discussion
Arch
CI
Heterogeneous env