Yes! You can use jq to extract and expand the GPU indices from the gres_detail field. Here’s how you can do it:
jq
gres_detail
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/,$//'
squeue --job $SLURM_JOB_ID --json | jq -r '.jobs[0].gres_detail' Extracts the gres_detail field as a string.
squeue --job $SLURM_JOB_ID --json | jq -r '.jobs[0].gres_detail'
grep -oP 'IDX:\K[^)]+' Extracts the part after IDX: and before the closing parenthesis, e.g., 1-2,4.
grep -oP 'IDX:\K[^)]+'
IDX:
1-2,4
tr ',' '\n' Replaces commas with newlines to process each index range separately.
tr ',' '\n'
sed 's/-/,/g' Replaces the hyphen in ranges like 1-2 with a comma, turning it into 1,2.
sed 's/-/,/g'
1-2
1,2
tr '\n' ',' Joins all indices with commas.
tr '\n' ','
sed 's/,$//' Removes the trailing comma.
sed 's/,$//'
For your example input:
[ "gpu:b200:3(IDX:1-2,4)" ]
The output will be:
1,2,4
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