-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerrun
More file actions
executable file
·69 lines (55 loc) · 2.34 KB
/
dockerrun
File metadata and controls
executable file
·69 lines (55 loc) · 2.34 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
#!/bin/bash
# `./dockerrun <args>`
# docker run wrapper that maps ENV to local paths
# further wrapped with ./dokrun -i imagename
# extension `docker run` with extra arg `--cache` which maps to env and volume: -e and -v
# to names and paths, with the purpose of replacing ~/.cache with a mounted volume for selected env variables
source config.sh # PROVIDES ENVS: linked to cache
# DEFINE Docker ENV Variables, new ENV require a names/paths pair < moved to config
# names=(TORCH_HOME TORCH_EXTENSIONS_DIR DNNLIB_CACHE_DIR HUGGINGFACE_HOME TTS_HOME)
# DEFINE local subfolders of "${WEIGHTS_ROOT}" defined in ./config.sh
# paths=("torch" "torch_extensions" "dnnlib" "huggingface" "tts")
docker_args=()
cache_arg=()
volume_arg=()
image=""
while [[ $# -gt 0 ]]; do
case "$1" in
--cache)
volume_arg+=(-v "${2}")
IFS=":"
read -ra parts <<< "${2}"
cache_arg+=(-e "XDG_CACHE_HOME=${parts[1]}")
i=0
for name in "${ENVS[@]}"; do
cache_arg+=(-e "${name}=${parts[1]}/${ENV_HOMES[$i]}")
i=$((i + 1))
done
shift 2
;;
*)
if [[ $# -eq 1 ]]; then
image="$1"
else
docker_args+=("$1")
fi
shift
;;
esac
done
echo " ${0} expands to:"
if [ "${#cache_arg[@]}" -eq 0 ]; then
echo " docker run "${docker_args[@]}" "$image";"
docker run "${docker_args[@]}" "$image"
else
echo " docker run "${docker_args[@]}" "${volume_arg[@]}" "${cache_arg[@]}" "$image";"
docker run "${docker_args[@]}" "${volume_arg[@]}" "${cache_arg[@]}" "$image";
fi
# run example
# ./dockerrun --user 1000 --name torch --gpus device=0 --cpuset-cpus="0-10" --cache /mnt/Data/weights:/home/weights -v /mnt/Data/data:/home/data --network=host -it --rm xvdp/cuda1180-ubuntu2204_ssh_mamba_torch
# -> calls
# docker run --user 1000 --name torch --gpus device=0 --cpuset-cpus=0-10 --network=host -it --rm -v /mnt/Data/weights:/home/weights \
# -e XDG_CACHE_HOME=/home/weights -e TORCH_HOME=/home/weights/torch -e TORCH_EXTENSIONS_DIR=/home/weights/torch_extensions -e DNNLIB_CACHE_DIR=/home/weights/dnnlib -e HUGGINGFACE_HOME=/home/weights/huggingface \
# xvdp/cuda1180-ubuntu2204_ssh_mamba_torch
# alternatively
# dokrun -i xvdp/cuda1180-ubuntu2204_ssh_mamba_torch