-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker.sh
More file actions
executable file
·166 lines (162 loc) · 3.51 KB
/
Copy pathdocker.sh
File metadata and controls
executable file
·166 lines (162 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
#set -x
dry_run=0
interactive=0
grep_value=
cmd=
it=" -it"
USER=${USER:-$(whoami)}
image=${USER}_vllm
suffix=
name=${USER}_vllm
extra_args=
while : ; do
docker ps --format "{{.Names}}" | grep -sw $name$suffix &> /dev/null || break
suffix=$(( suffix + 1 ))
done
name=$name$suffix
entrypoint=
models_arg="--mount type=bind,source=/data/models,target=/models"
if [ -f ~/.models ] ; then
models_arg=$(cat ~/.models | awk 'NF' | awk -F: '{printf "--mount type=bind,source=%s,target=%s ", $1, $2}')
fi
pull=1
no_gfx=0
no_rename=0
nethost=
shmem_arg="--shm-size 8G"
user_args=
while [[ $# -gt 0 ]] ; do
i=$1
case $i in
-n|--name)
name="$2"
shift
;;
--dry-run)
dry_run=1
no_rename=1
;;
-g|--grep)
grep_value="$2"
shift
;;
-i|--interactive)
interactive=1
;;
--noit)
it=
;;
-c|--cmd)
cmd="$2"
shift
;;
--shmem)
shmem_arg="--shm-size $2"
shift
;;
--no-shmem)
shmem_arg=
;;
-m)
models_arg="--mount type=bind,source=${2},target=/models"
shift
;;
-e|--entrypoint)
entrypoint="--entrypoint $2"
shift
;;
--nopull)
pull=0
;;
--env-file)
extra_args="${extra_args} --env-file $2"
shift
;;
--no-gfx)
no_gfx=1
;;
--nethost)
nethost="--network=host"
;;
--no-rename)
no_rename=1
;;
-u)
TMP_DIR=$(mktemp -d)
user_args="--user $(id -u):$(id -g) -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro -v ${TMP_DIR}:/home/${USER} --workdir /home/${USER}"
;;
--)
shift
cmd="$@"
break
;;
*)
image=$1
;;
esac
shift
done
echo $command
extra_args="$extra_args $nethost $shmem_arg -e VLLM_DISABLE_COMPILE_CACHE=1 -e AITER_LOG_LEVEL=ERROR"
if [[ $interactive == 1 ]] ; then
grep_arg=
if [[ $grep_value != "" ]] ; then
grep_arg=" | grep $grep_value"
fi
interactive_cmd="docker images | awk '{print \$1 \":\" \$2}' | grep -v none | grep -v REPOSITORY:TAG $grep_arg"
images=$(eval $interactive_cmd)
i=0
for im in $images ; do
echo "$i $im"
i=$((i+1))
done
read -p "Select image: " selection
images_arr=($images)
image=${images_arr[$selection]}
read -p "Container name: " name
fi
echo "Image: $image"
name_arg=
if [[ $name != "" ]] ; then
name_arg=" --name $name -e CONTAINER_NAME=$name"
fi
if command -v nvidia-smi ; then
echo "Found CUDA"
IS_CUDA=1
gpu_args="--runtime nvidia --gpus all"
elif command -v rocm-smi ; then
echo "Found ROCm"
IS_ROCM=1
gpu_args="--device=/dev/kfd --device=/dev/dri --group-add video"
if [[ $no_gfx == 0 ]] ; then
gpu_args="$gpu_args -e PYTORCH_ROCM_ARCH=$(/opt/rocm/lib/llvm/bin/amdgpu-arch | sort | uniq)"
fi
elif [ -d /dev/dri ] ; then
echo "No ROCm or CUDA installation found but /dev/dri exists, assuming AMD GPU"
IS_ROCM=1
gpu_args="--device=/dev/kfd --device=/dev/dri --group-add video"
else
echo "No GPU found"
exit 1
fi
if [[ $no_rename == 0 ]] ; then
tmux rename-window "Docker:$name"
fi
if [[ $pull == 1 ]] ; then
docker pull $image
fi
full_cmd="docker run ${it} --rm ${gpu_args} -v /tmp/tmux-$(id -u):/tmp/tmux --mount type=bind,source=${HOME}/Projects,target=/projects ${user_args} ${models_arg} --ulimit core=0:0 --ulimit memlock=-1:-1 $entrypoint $extra_args --cap-add=SYS_PTRACE $name_arg $image"
if [[ $dry_run != 1 ]] ; then
if [[ $cmd == "" ]] ; then
${full_cmd}
else
${full_cmd} bash -c "$cmd"
fi
if [[ $no_rename == 0 ]] ; then
tmux setw automatic-rename on
fi
echo "Finished docker image $image"
else
echo "Dry run: $full_cmd"
fi