-
Notifications
You must be signed in to change notification settings - Fork 7
/
install.sh
165 lines (139 loc) · 3.87 KB
/
install.sh
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
#!/bin/bash
set -e
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
NC='\033[0m' # No Color
function log() {
TIME=$(date +'%Y-%m-%d %H:%M:%S')
echo -e "${GREEN}$TIME${NC}" "$1"
}
function log_warning() {
TIME=$(date +'%Y-%m-%d %H:%M:%S')
echo -e "${YELLOW}$TIME${NC}" "$1"
}
function log_error() {
TIME=$(date +'%Y-%m-%d %H:%M:%S')
echo -e "${RED}$TIME${NC}" "$1"
}
error_handler() {
log_error "Error occurred in script at line: $1"
log_error "Line exited with status: $2"
exit $2
}
trap 'error_handler ${LINENO} $?' ERR
function helpFunction()
{
echo ""
echo "Usage: $0 --env_name=ENV_NAME --py_ver=PY_VER --cuda=CUDA --torch_dir=TORCH_DIR"
echo "Example: $0 --env_name=dreamllm --py_ver=3.10 --cuda=118 --torch_dir=/data/torch-2.1.2/"
echo -e "\t--env_name: conda environment name, default name is \`dreamllm\`"
echo -e "\t--py_ver: python version, default version is 3.10"
echo -e "\t--cuda: cuda version, used to install pytorch, default version is 118"
echo -e "\t--torch_dir: directory address containing torch whl, if specified, the cuda version will be ignored"
echo -e "\t-h or --help: show help information"
echo ""
}
for i in "$@"
do
case $i in
--env_name=*)
ENV_NAME="${i#*=}"
shift # past argument=value
;;
--py_ver=*)
PY_VER="${i#*=}"
shift # past argument=value
;;
--cuda=*)
CUDA="${i#*=}"
shift # past argument=value
;;
--torch_dir=*)
TORCH_DIR="${i#*=}"
shift # past argument=value
;;
-h|--help)
HELP=1
shift # past argument with no value
;;
*)
# unknown option
;;
esac
done
if [ $HELP ]
then
helpFunction
exit 0
fi
if [ ! "$ENV_NAME" ]
then
ENV_NAME="dreamllm"
fi
if [ ! "$PY_VER" ]
then
PY_VER="3.10"
fi
if [ ! "$CUDA" ]
then
CUDA="118"
fi
if [ ! "$TORCH_DIR" ]
then
TORCH_DIR=""
fi
log "Environment name = ${ENV_NAME}"
log "Python version = ${PY_VER}"
log "CUDA version = ${CUDA}"
log "Torch directory = ${TORCH_DIR}"
# Check if environment exists
if ! conda info --envs | grep "$ENV_NAME"; then
log "Conda environment '$ENV_NAME' does not exist. Creating..."
conda create -n "$ENV_NAME" python=$PY_VER -y
else
log_warning "Conda environment '$ENV_NAME' already exists."
fi
# activate environment
source activate "$ENV_NAME"
log "Conda environment '$ENV_NAME' has been activated."
log "Installing torch ..."
if [ ! -z "$TORCH_DIR" ]; then
# install torch
for wheel in "$TORCH_DIR"/*.whl; do
log "Installing $wheel ..."
pip install "$wheel"
done
elif [ ! -z "$CUDA" ]; then
log_warning "If installing torch gets stuck here, please download the whl file in advance to a folder and then specify the directory."
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu$CUDA
else
log_error "Please specify the cuda version or the directory of torch whl files."
exit 1
fi
log "torch has been installed."
log "Installing accelerate ..."
pip install accelerate==0.23.0 -c constraints.txt
log "accelerate has been installed."
# Install flash-attn
log "Installing flash-attn ..."
pip install packaging
pip install ninja
pip install flash-attn --no-build-isolation
log "flash-attn has been installed."
# Install the current directory as a package
log "Installing the current directory as a package ..."
pip install -e .
log "The current directory has been installed as a package."
# Install every project in the third_party directory
log "Installing packages in third_party directory ..."
THIRD_PARTY_DIR="./third_party"
for project_dir in "$THIRD_PARTY_DIR"/*; do
# check if it is a folder
if [ -d "$project_dir" ]; then
log "Installing package in $project_dir ..."
pip install -e "$project_dir"
fi
done
log "All packages in $THIRD_PARTY_DIR have been installed."
log "Successfully setup the environment."