-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_model.sh
More file actions
executable file
·84 lines (69 loc) · 2.74 KB
/
train_model.sh
File metadata and controls
executable file
·84 lines (69 loc) · 2.74 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
#!/bin/bash
# @Author: ArthurBernard
# @Email: arthur.bernard.92@gmail.com
# @Date: 2024-11-21 16:40:18
# @Last modified by: ArthurBernard
# @Last modified time: 2024-11-21 18:41:10
# Train and quantize the MiniChatBot model
set -e # Stop on error
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
SIZE="1B"
ORIGINAL_MODEL="Llama-3.2"
TRAINED_MODEL="MiniChatBot-1.0"
INSTRUCT="-Instruct"
QUANT_TYPE="q8_0"
# MODEL_URL="https://huggingface.co/meta-llama/${ORIGINAL_MODEL}-${SIZE}${INSTRUCT}"
MODEL_URL="git@hf.co:meta-llama/Llama-3.2-${SIZE}${INSTRUCT}"
MODEL_DIR="./models/${ORIGINAL_MODEL}-${SIZE}${INSTRUCT}/"
LORA_WEIGHTS="./models/LoRA_${TRAINED_MODEL}-${SIZE}${INSTRUCT}/"
TRAINED_MODEL_DIR="./models/${TRAINED_MODEL}-${SIZE}${INSTRUCT}/"
GGUF_MODEL="./models/${TRAINED_MODEL}-${SIZE}${INSTRUCT}-${QUANT_TYPE}.gguf"
echo -e "${YELLOW}Starting training pipeline...${NC}"
# Create logs directory
LOG_DIR="./logs"
if [ ! -d "$LOG_DIR" ]; then
echo -e "${YELLOW}Directory $LOG_DIR does not exist. Creating it...${NC}"
mkdir -p "$LOG_DIR"
else
echo -e "${GREEN}Directory $LOG_DIR already exists.${NC}"
fi
# Step 1: Download initial model if not exists
if [ ! -d "$MODEL_DIR" ]; then
echo -e "${RED}Model does not exist, please downloading it manually.${NC}"
exit 1
# Check if git-lfs is installed
if ! command -v git-lfs &>/dev/null; then
echo -e "${RED}git-lfs is not installed. Installing it...${NC}"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt update && sudo apt install -y git-lfs
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew install git-lfs
else
echo -e "${RED}Please install git-lfs manually.${NC}"
exit 1
fi
git lfs install
fi
echo -e "${YELLOW}Downloading Llama-3.2-${SIZE}-Instruct model...${NC}"
git lfs install
git clone "$MODEL_URL" "$MODEL_DIR"
else
echo -e "${YELLOW}Model already exists in $MODEL_DIR. Skipping download.${NC}"
fi
# Activate Python virtual environment
echo -e "${YELLOW}Activate Python virtual environment...${NC}"
source ~/venv/bin/activate
# Step 2: Train the model
echo -e "${YELLOW}Training the model...${NC}"
python src/trainer_instruct.py --model "$MODEL_DIR" --lora_weights "$LORA_WEIGHTS"
# Step 3: Merge LoRA weights
echo -e "${YELLOW}Merging LoRA weights...${NC}"
python src/lora_merger.py --model "$MODEL_DIR" --lora "$LORA_WEIGHTS" --output_path "$TRAINED_MODEL_DIR"
# Step 4: Quantize the model
echo -e "${YELLOW}Quantizing the model...${NC}"
python llama.cpp/convert_hf_to_gguf.py "$TRAINED_MODEL_DIR" --outfile "$GGUF_MODEL" --outtype "$QUANT_TYPE"
echo -e "${GREEN}Training pipeline complete. Quantized model saved at ${GGUF_MODEL}.${NC}"