DeepSpeed
8bdd8f19 - Honor --include/--exclude in the SLURM launcher (#8304)

Commit
71 days ago
Honor --include/--exclude in the SLURM launcher (#8304) ## Problem `SlurmRunner.get_cmd()` forwards DeepSpeed's own `--include` / `--exclude` strings to `srun` and sizes the job from the unfiltered hostfile. With a two-node, four-slot hostfile: ``` deepspeed --launcher slurm --include worker-1:0,2 train.py ``` builds ``` srun -n 8 --include worker-1:0,2 --export=ALL python -u train.py ``` Two things are wrong with that line: 1. `srun` has no `--include` option, so it exits with `unrecognized option '--include'` and the job never starts. 2. `-n 8` counts every slot in the pool. The user asked for 2. `--exclude` is broken the same way. `srun` does accept that flag, but DeepSpeed's `NAME[:SLOT[,SLOT ...]]` syntax is not a slurm hostlist (`--exclude worker-1:0` names no node slurm knows), and `-n` still ignores the filter, so `--exclude worker-1` asks for 8 tasks on the 4 slots that are left. ## Fix `runner.py` already resolves both flags into `active_resources` before calling `get_cmd()`, and it passes that dict in as the second argument. The other runners either use it (`PDSHRunner`) or explicitly reject the flags in `validate_args()`; `SlurmRunner` was the only one accepting them and then ignoring the resolved result. So take the process count and the host list from `active_resources`, and give `srun` `--nodelist`, which is the flag it actually has: ``` srun -n 2 --nodelist worker-1 --nodes 1 --export=ALL python -u train.py ``` `--nodelist` alone is only an upper bound. SchedMD documents that "a lower node or processor count may only require a subset of the supplied node list", so `-n 7 --nodelist worker-0,worker-1` could put all seven ranks on `worker-0` and silently drop a host the filter kept. `--nodes` pins the count (a single number is used as both minimum and maximum). It cannot collide with the `--nodes` the branch below emits, because `runner.py` raises `Cannot specify num_nodes/gpus with include/exclude`, so `args.num_nodes` is always `-1` on this path. Slot-level selection still cannot be expressed to `srun`, but the task count and the node set are now what the user asked for, instead of an invalid command line. ## Wider scope, stated rather than left implicit Sizing from `active_resources` is unconditional, so it also moves `-n` for `--num_gpus` and `--num_nodes`, which `runner.py` trims the same dict for (L521 and L529): ``` base head control (no flags) -n 8 -n 8 --include worker-1:0,2 -n 8 -n 2 --exclude worker-1:0 -n 8 -n 7 --num_gpus 2 -n 8 -n 4 --num_nodes 1 -n 8 -n 4 ``` The bottom two are corrections rather than regressions: `world_info_base64` is encoded from that same trimmed dict at L543, so `-n 8` against a four-rank world info was already inconsistent. Both are now covered by tests. To pin them without a hand-rolled copy of `main()`'s trim in the test, those lines move verbatim into `apply_num_nodes_and_gpus()` next to `parse_inclusion_exclusion`, and `main()` calls it. Pure extraction, no behaviour change. ## Test Added `test_slurm_runner_resource_filter` to `tests/unit/launcher/test_multinode_runner.py`, covering `--include` with slots, `--exclude` with slots, and `--exclude` of a whole host, asserting the host list, the node count and the task count for each. `test_slurm_runner` also now asserts the unfiltered count and passes `get_cmd()` the slot lists that `runner.py` really hands it, rather than the raw hostfile counts. `test_slurm_runner_num_nodes_and_gpus` covers the two flags above, asserting `-n 4` for each plus that the resource-filter branch stays silent, so `--nodelist` is absent and `--nodes` appears exactly once. ``` # before the fix, with the new tests 5 failed, 7 passed # after 12 passed ``` The rest of `tests/unit/launcher/` is unchanged at `9 failed, 23 passed` on a clean tree and `9 failed, 28 passed` here; the 9 are pre-existing `test_user_args.py` failures in this environment because the `deepspeed` console script is not installed, and they reproduce identically on a clean tree. `yapf --style .style.yapf -d` and `flake8 --config .flake8` are clean on both changed files. --------- Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com> Co-authored-by: Olatunji Ruwase <tunji.ruwase@snowflake.com> Co-authored-by: Masahiro Tanaka <81312776+tohtana@users.noreply.github.com>
Author
Parents
Loading