```bash
sbatch --array 1-2 --gpus-per-task 1 --cpus-per-task 32 --wrap 'bash -c "echo $SLURM_ARRAY_TASK_ID"'
```

works fine, but not:

```bash
sbatch --array 1-2 --gpus-per-task 1 --cpus-per-task 32 --wrap 'bash -c "echo $SLURM_ARRAY_TASK_ID"'
```
```
sbatch: error: Failed to validate job spec. --gpus-per-task or --tres-per-task used without either --gpus or -n/--ntasks is not allowed.
sbatch: error: Invalid generic resource (gres) specification
```

How to solve this issue?
Jun 4, 11:25pm

The error occurs because Slurm requires either --gpus or --ntasks (or -n) to be specified when using --gpus-per-task or --tres-per-task. The --wrap option does not implicitly set --ntasks, so you need to explicitly define the number of tasks.

Solution

Add --ntasks=1 (or -n 1) to your command to specify that each array job should run as a single task. This resolves the validation error.

Corrected Command:

bash
sbatch --array 1-2 --ntasks=1 --gpus-per-task 1 --cpus-per-task 32 --wrap 'bash -c "echo $SLURM_ARRAY_TASK_ID"'

Why This Works

  • --ntasks=1: Explicitly sets the number of tasks per job to 1, which is required when using --gpus-per-task.
  • The rest of the options (--gpus-per-task, --cpus-per-task, --wrap) remain unchanged.

This should now submit your array job without errors.

Jun 4, 11:25pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more