Skip to content

Commit 44220b1

Browse files
fix random port generation (#46)
1 parent 6938996 commit 44220b1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

scripts/run_llmc.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@ nnodes=1
1212
nproc_per_node=1
1313

1414

15-
MASTER_ADDR=127.0.0.1
16-
MASTER_PORT=$((10000 + RANDOM % 20000))
15+
find_unused_port() {
16+
while true; do
17+
port=$(shuf -i 10000-60000 -n 1)
18+
if ! ss -tuln | grep -q ":$port "; then
19+
echo "$port"
20+
return 0
21+
fi
22+
done
23+
}
24+
UNUSED_PORT=$(find_unused_port)
25+
1726

18-
RANDOM=$(python -c 'import uuid; print(uuid.uuid4())')
19-
task_id=$RANDOM
27+
MASTER_ADDR=127.0.0.1
28+
MASTER_PORT=$UNUSED_PORT
29+
task_id=$UNUSED_PORT
2030

2131
nohup \
2232
torchrun \

0 commit comments

Comments
 (0)