```bash
squeue --job $SLURM_JOB_ID --json | jq -r '.jobs[0].gres_detail'
```
```
[
"gpu:b200:3(IDX:1-2,4)"
]
```

Is there a known way to expand the GPU index to have `1,2,4` instead?
Mar 29, 11:49pm

Yes! You can use jq to extract and expand the GPU indices from the gres_detail field. Here’s how you can do it:

Command to Extract and Expand GPU Indices

bash
squeue --job $SLURM_JOB_ID --json | jq -r '.jobs[0].gres_detail' | \
  grep -oP 'IDX:\K[^)]+' | \
  tr ',' '\n' | \
  sed 's/-/,/g' | \
  tr '\n' ',' | \
  sed 's/,$//'

Explanation:

  1. squeue --job $SLURM_JOB_ID --json | jq -r '.jobs[0].gres_detail'
    Extracts the gres_detail field as a string.

  2. grep -oP 'IDX:\K[^)]+'
    Extracts the part after IDX: and before the closing parenthesis, e.g., 1-2,4.

  3. tr ',' '\n'
    Replaces commas with newlines to process each index range separately.

  4. sed 's/-/,/g'
    Replaces the hyphen in ranges like 1-2 with a comma, turning it into 1,2.

  5. tr '\n' ','
    Joins all indices with commas.

  6. sed 's/,$//'
    Removes the trailing comma.


Result

For your example input:

text
[
  "gpu:b200:3(IDX:1-2,4)"
]

The output will be:

text
1,2,4

Mar 29, 11:49pm

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