Repository: microsoft/DeepSpeed

Issue:
[BUG] Multi node autotune do not use all GPUs, even explicitly set
**Describe the bug**
![image](https://github.com/microsoft/DeepSpeed/assets/39079736/8a6a72e3-6a72-4d03-82d9-362477b19bed)


**To Reproduce**
```sh
deepspeed  --autotuning=run --hostfile=/root/space/xxx/hostfile --include=v1004:0,1,2,3@v1002:0,1  xxx/sft_train.py \
    --deepspeed /root/space/rxxx/configs/ds_config_auto.json \
    --model_name_or_path /root/space/models/codellama/CodeLlama-13b-Instruct-hf/main \
    --do_train \
    --dataset $traindata \
    --max_source_length 4096 \
    --max_target_length 256 \
    --template llama2 \
    --finetuning_type lora \
    --lora_rank 2 \
    --lora_alpha 32 \
    --lora_target q_proj \
    --output_dir dbgpt_hub/output/adapter/CodeLlama-13b-Instruct-hf-$(date +"%Y%m%d_%H%M%S")-xds-auto-qv-${traindata}/ \
    --overwrite_cache \
    --overwrite_output_dir \
    --per_device_train_batch_size 1 \
    --gradient_accumulation_steps 1 \
    --lr_scheduler_type cosine_with_restarts \
    --logging_steps 25 \
    --save_steps 1 \
    --learning_rate 2e-4 \
    --num_train_epochs 10000 \
    --plot_loss
```
**Expected behavior**
Use all gpus 

**ds_report output**
```
--------------------------------------------------
DeepSpeed C++/CUDA extension op report
--------------------------------------------------
NOTE: Ops not installed will be just-in-time (JIT) compiled at
      runtime if needed. Op compatibility means that your system
      meet the required dependencies to JIT install the op.
--------------------------------------------------
JIT compiled ops requires ninja
ninja .................. [OKAY]
--------------------------------------------------
op name ................ installed .. compatible
--------------------------------------------------
 [WARNING]  async_io requires the dev libaio .so object and headers but these were not found.
 [WARNING]  async_io: please install the libaio-devel package with yum
 [WARNING]  If libaio is already installed (perhaps from source), try setting the CFLAGS and LDFLAGS environment variables to where it can be found.
async_io ............... [NO] ....... [NO]
fused_adam ............. [NO] ....... [OKAY]
cpu_adam ............... [NO] ....... [OKAY]
cpu_adagrad ............ [NO] ....... [OKAY]
cpu_lion ............... [NO] ....... [OKAY]
 [WARNING]  Please specify the CUTLASS repo directory as environment variable $CUTLASS_PATH
evoformer_attn ......... [NO] ....... [NO]
fused_lamb ............. [NO] ....... [OKAY]
fused_lion ............. [NO] ....... [OKAY]
inference_core_ops ..... [NO] ....... [OKAY]
cutlass_ops ............ [NO] ....... [OKAY]
quantizer .............. [NO] ....... [OKAY]
ragged_device_ops ...... [NO] ....... [OKAY]
ragged_ops ............. [NO] ....... [OKAY]
random_ltd ............. [NO] ....... [OKAY]
 [WARNING]  sparse_attn requires a torch version >= 1.5 and < 2.0 but detected 2.1
 [WARNING]  using untested triton version (2.1.0), only 1.0.0 is known to be compatible
sparse_attn ............ [NO] ....... [NO]
spatial_inference ...... [NO] ....... [OKAY]
transformer ............ [NO] ....... [OKAY]
stochastic_transformer . [NO] ....... [OKAY]
transformer_inference .. [NO] ....... [OKAY]
--------------------------------------------------
DeepSpeed general environment info:
torch install path ............... ['/root/space/conda_envs/hubc12/lib/python3.10/site-packages/torch']
torch version .................... 2.1.1
deepspeed install path ........... ['/root/space/conda_envs/hubc12/lib/python3.10/site-packages/deepspeed']
deepspeed info ................... 0.13.0, unknown, unknown
torch cuda version ............... 12.1
torch hip version ................ None
nvcc version ..................... 12.1
deepspeed wheel compiled w. ...... torch 2.1, cuda 12.1
shared memory (/dev/shm) size .... 78.33 GB
```

**Screenshots**
If applicable, add screenshots to help explain your problem.

**System info (please complete the following information):**
 - OS: centos7
 - GPU count and types 2*V100 + 4*V100 
 - Interconnects (if applicable) [e.g., two machines connected with 100 Gbps IB]
 - Python version   3.10.13
 - Any other relevant info about your setup

**Launcher context**
Are you launching your experiment with the `deepspeed` launcher, MPI, or something else?

**Docker context**
Are you using a specific docker image that you can share?

**Additional context**
Add any other context about the problem here.



Discussion:

Resolving patch:
diff --git a/deepspeed/autotuning/autotuner.py b/deepspeed/autotuning/autotuner.py
--- a/deepspeed/autotuning/autotuner.py
+++ b/deepspeed/autotuning/autotuner.py
@@ -683,6 +683,7 @@ def model_info_profile_run(self):
         exp_config[DS_CONFIG] = ds_config
         exp_config['num_gpus'] = self.exp_num_gpus
         exp_config['num_nodes'] = self.exp_num_nodes
+        exp_config['hostfile'] = self.args.hostfile
         exp_path = os.path.join(self.exps_dir, f'{exp_name}.json')
 
         with open(exp_path, 'w', buffering=BUFSIZE) as fd:
@@ -761,6 +762,7 @@ def run_tuning_micro_batch_sizes(self, tuning_micro_batch_sizes, max_train_batch
             exp_config[DS_CONFIG] = ds_config
             exp_config['num_gpus'] = self.exp_num_gpus
             exp_config['num_nodes'] = self.exp_num_nodes
+            exp_config['hostfile'] = self.args.hostfile
             exp_path = os.path.join(self.exps_dir, f'{exp_name}.json')
 
             with open(exp_path, 'w', buffering=BUFSIZE) as fd:
@@ -1055,6 +1057,7 @@ def run_ds_config(self, ds_config, exp_name):
         exp_config[DS_CONFIG] = ds_config
         exp_config['num_gpus'] = self.exp_num_gpus
         exp_config['num_nodes'] = self.exp_num_nodes
+        exp_config['hostfile'] = self.args.hostfile
         exp_path = os.path.join(self.exps_dir, f'{exp_name}.json')
 
         logger.debug(f'run_ds_config exp_name = {exp_name}')
diff --git a/deepspeed/autotuning/scheduler.py b/deepspeed/autotuning/scheduler.py
--- a/deepspeed/autotuning/scheduler.py
+++ b/deepspeed/autotuning/scheduler.py
@@ -316,7 +316,10 @@ def run_experiment(exp: dict, reservations, user_script, user_args):
         include_str += f"{reservation.node.host}:{slots}@"
     include_str = include_str[:-1]
     master_port = exp["master_port"]
+    hostfile = exp["hostfile"]
     exp["launcher_args"] = [
+        "--hostfile",
+        f"{hostfile}",
         "--include",
         f"{include_str}",
         "--master_port",


Test patch: