refactor: update deploy script to match cyron pattern
This commit is contained in:
@@ -1,43 +1,79 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
# Update a GPU-server clone of agenx-lora-training and run the training.
|
||||||
# LoRA Training Deployment Script
|
|
||||||
# Clones the repo and trains the LoRA adapter on the server
|
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# bash deploy-and-train.sh
|
# bash deploy-and-train.sh
|
||||||
#
|
#
|
||||||
# This will:
|
# Optional overrides:
|
||||||
# 1. Clone the repo to /opt/loras/agenx-lora-training
|
# LORA_DEPLOY_REPO_URL=https://gitea.cyaren.com/cmedina/agenx-lora-training.git
|
||||||
# 2. Setup Python environment with GPU support
|
# LORA_DEPLOY_REPO_DIR=/opt/loras/agenx-lora-training
|
||||||
# 3. Prepare the dataset
|
# LORA_DEPLOY_BRANCH=main
|
||||||
# 4. Train the LoRA adapter
|
|
||||||
#
|
#
|
||||||
|
|
||||||
set -e
|
set -euo pipefail
|
||||||
|
|
||||||
# Configuration
|
# Load credentials from env file if it exists (override with env vars).
|
||||||
REPO_URL="https://gitea.cyaren.com/cmedina/agenx-lora-training.git"
|
if [ -f /home/cyaren/.deploy.env ]; then
|
||||||
INSTALL_DIR="/opt/loras/agenx-lora-training"
|
set -a; source /home/cyaren/.deploy.env; set +a
|
||||||
PYTHON_VERSION="3.10"
|
|
||||||
|
|
||||||
echo "=============================================="
|
|
||||||
echo "LoRA Training Deployment"
|
|
||||||
echo "=============================================="
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Step 1: Create installation directory
|
|
||||||
echo "[1/5] Creating installation directory..."
|
|
||||||
mkdir -p /opt/loras
|
|
||||||
if [ -d "$INSTALL_DIR" ]; then
|
|
||||||
echo " Directory already exists: $INSTALL_DIR"
|
|
||||||
echo " Removing old clone..."
|
|
||||||
rm -rf "$INSTALL_DIR"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Step 2: Clone the repository
|
DEPLOY_USER="${LORA_DEPLOY_USER:-}"
|
||||||
echo "[2/5] Cloning repository..."
|
DEPLOY_TOKEN="${LORA_DEPLOY_TOKEN:-}"
|
||||||
git clone "$REPO_URL" "$INSTALL_DIR"
|
|
||||||
echo " Repository cloned to: $INSTALL_DIR"
|
# Build the repo URL; embed user:token for HTTPS auth when provided.
|
||||||
|
if [ -n "${DEPLOY_USER}" ] && [ -n "${DEPLOY_TOKEN}" ]; then
|
||||||
|
REPO_URL="${LORA_DEPLOY_REPO_URL:-https://${DEPLOY_USER}:${DEPLOY_TOKEN}@gitea.cyaren.com/cmedina/agenx-lora-training.git}"
|
||||||
|
else
|
||||||
|
REPO_URL="${LORA_DEPLOY_REPO_URL:-https://gitea.cyaren.com/cmedina/agenx-lora-training.git}"
|
||||||
|
fi
|
||||||
|
REPO_DIR="${LORA_DEPLOY_REPO_DIR:-/opt/loras/agenx-lora-training}"
|
||||||
|
BRANCH="${LORA_DEPLOY_BRANCH:-main}"
|
||||||
|
REMOTE="${LORA_DEPLOY_REMOTE:-origin}"
|
||||||
|
|
||||||
|
RUN_USER="${SUDO_USER:-$(id -un)}"
|
||||||
|
RUN_GROUP="$(id -gn "${RUN_USER}" 2>/dev/null || id -gn)"
|
||||||
|
REPO_PARENT="$(dirname "${REPO_DIR}")"
|
||||||
|
|
||||||
|
echo "=== LoRA Training Git Deploy ==="
|
||||||
|
echo "Repo: ${REPO_URL}"
|
||||||
|
echo "Dir: ${REPO_DIR}"
|
||||||
|
echo "Branch: ${BRANCH}"
|
||||||
|
|
||||||
|
if [ ! -d "${REPO_PARENT}" ]; then
|
||||||
|
sudo install -d -m 0755 -o "${RUN_USER}" -g "${RUN_GROUP}" "${REPO_PARENT}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "${REPO_DIR}/.git" ]; then
|
||||||
|
git clone --branch "${BRANCH}" "${REPO_URL}" "${REPO_DIR}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "${REPO_DIR}"
|
||||||
|
|
||||||
|
# Ensure the remote URL matches the authenticated HTTPS URL.
|
||||||
|
git remote set-url "${REMOTE}" "${REPO_URL}"
|
||||||
|
|
||||||
|
git fetch "${REMOTE}" "${BRANCH}"
|
||||||
|
git checkout "${BRANCH}"
|
||||||
|
git pull --ff-only "${REMOTE}" "${BRANCH}"
|
||||||
|
|
||||||
|
# Setup Python environment and train
|
||||||
|
echo ""
|
||||||
|
echo "=== Setting up Python environment ==="
|
||||||
|
python3 -m venv venv
|
||||||
|
source venv/bin/activate
|
||||||
|
pip install --upgrade pip
|
||||||
|
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
|
||||||
|
pip install transformers datasets trl peft accelerate bitsandbytes
|
||||||
|
|
||||||
|
# Prepare dataset
|
||||||
|
echo ""
|
||||||
|
echo "=== Preparing dataset ==="
|
||||||
|
python3 training/scripts/prepare_dataset.py --input dataset/combined_20k.jsonl --output training/data
|
||||||
|
|
||||||
|
# Train
|
||||||
|
echo ""
|
||||||
|
echo "=== Starting LoRA training ==="
|
||||||
|
python3 training/scripts/train.py --config training/configs/llama2-7b-lora.yaml
|
||||||
|
|
||||||
# Step 3: Setup Python environment
|
# Step 3: Setup Python environment
|
||||||
echo "[3/5] Setting up Python environment..."
|
echo "[3/5] Setting up Python environment..."
|
||||||
|
|||||||
Reference in New Issue
Block a user