-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.sh
executable file
·94 lines (79 loc) · 2.99 KB
/
setup.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
#!/bin/bash
################################################################################
# Script: setup.sh
# Description: Automates the setup of a virtual environment and installs project
# requirements.
################################################################################
set -euo pipefail
# Main script starts here.
CURRENT_DIR="$(pwd)"
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
VENV_DIR="$SCRIPT_DIR/venv"
# Set default folder paths for AWQ weights
LLAMA2_AWQ_WEIGHTS_FOLDER="$CURRENT_DIR/models/llama-2-7b-chat-autoawq"
MISTRAL_AWQ_WEIGHTS_FOLDER="$CURRENT_DIR/models/mistral-7b-v0.1-instruct-autoawq"
check_python() {
if command -v python &> /dev/null; then
PYTHON_CMD="python"
elif command -v python3 &> /dev/null; then
PYTHON_CMD="python3"
else
echo "Python is not installed."
exit 1
fi
}
download_awq_weights() {
local MODEL_NAME="$1"
# Set download directory based on MODEL_NAME
if [ "$MODEL_NAME" = "llama" ]; then
DOWNLOAD_DIR="$LLAMA2_AWQ_WEIGHTS_FOLDER"
MODEL_IDENTIFIER="TheBloke/Llama-2-7B-Chat-AWQ"
elif [ "$MODEL_NAME" = "mistral" ]; then
DOWNLOAD_DIR="$MISTRAL_AWQ_WEIGHTS_FOLDER"
MODEL_IDENTIFIER="TheBloke/Mistral-7B-Instruct-v0.1-AWQ"
else
echo "Invalid MODEL_NAME. Supported values: 'llama', 'mistral'"
exit 1
fi
# Check if weights folder exists
echo "$DOWNLOAD_DIR"
if [ ! -d "$DOWNLOAD_DIR" ]; then
# Download weights using huggingface-cli
echo "Downloading weights to $DOWNLOAD_DIR..."
huggingface-cli download "$MODEL_IDENTIFIER" --local-dir "$DOWNLOAD_DIR" --exclude "*.git*" "*.md" "Notice" "LICENSE"
else
echo "Weights already downloaded"
fi
}
check_python
if [ ! -d "$VENV_DIR" ]; then
"$PYTHON_CMD" -m venv "$VENV_DIR"
echo "Virtual environment '$VENV_DIR' created."
# Activate virtual environment using specified activation scripts
if [ -f "$VENV_DIR/bin/activate" ]; then
# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate"
elif [ -f "$VENV_DIR/Scripts/activate" ]; then
# shellcheck disable=SC1091
source "$VENV_DIR/Scripts/activate"
else
echo "Error: Unable to find virtual environment activation script."
exit 1
fi
"$PYTHON_CMD" -m pip install --upgrade pip > /dev/null
"$PYTHON_CMD" -m pip install -r "$SCRIPT_DIR/requirements.txt" --no-cache-dir > /dev/null
else
# Activate virtual environment using specified activation scripts
if [ -f "$VENV_DIR/bin/activate" ]; then
# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate"
elif [ -f "$VENV_DIR/Scripts/activate" ]; then
# shellcheck disable=SC1091
source "$VENV_DIR/Scripts/activate"
else
echo "Error: Unable to find virtual environment activation script."
exit 1
fi
fi
MODEL_NAME="${1:-"llama"}" # Use the first argument as MODEL_NAME if provided
download_awq_weights "$MODEL_NAME"