File size: 3,036 Bytes
5a28a50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash
# =============================================================
#  Spam Classifier — Rebuild GGUF + Reload Server
#  Run this after retraining to bake the new adapter into
#  spam-classifier-F16.gguf and reload the llama.cpp server.
# =============================================================

LIQUID_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJ_DIR="$(dirname "$LIQUID_DIR")"
GGUF_FILE="$PROJ_DIR/spam-classifier-F16.gguf"
MERGED_DIR="$PROJ_DIR/merged-liquid-full"

echo "============================================================"
echo "  Spam Classifier — Rebuild GGUF"
echo "============================================================"
echo ""
echo "  Adapter: $LIQUID_DIR/adapters"
echo "  Output:  $PROJ_DIR/spam-classifier-F16.gguf"
echo ""

# ── Check adapter exists ──
if [[ ! -d "$LIQUID_DIR/adapters" ]]; then
    echo "  ERROR: No adapter found at $LIQUID_DIR/adapters/"
    echo "  Run retrain.command first."
    echo ""
    read -n 1 -s -r -p "Press any key to close..."
    exit 1
fi

# ── Remove cached merge so new adapter is actually baked in ──
if [[ -d "$MERGED_DIR" ]]; then
    echo "  Removing cached merged model (so new adapter is used)..."
    rm -rf "$MERGED_DIR"
    echo "  Done."
    echo ""
fi

# ── Run merge + GGUF conversion ──
echo "  Merging adapter into base model and converting to GGUF..."
echo "  (This takes ~5-10 minutes and uses ~8 GB of RAM)"
echo ""

cd "$PROJ_DIR"
source "$LIQUID_DIR/venv/bin/activate"
python3 merge_and_convert_gguf.py
BUILD_STATUS=$?
deactivate

echo ""
if [[ $BUILD_STATUS -ne 0 ]]; then
    echo "  ERROR: GGUF build failed (exit $BUILD_STATUS)."
    echo ""
    read -n 1 -s -r -p "Press any key to close..."
    exit 1
fi

GGUF_SIZE_MB=$(du -m "$GGUF_FILE" 2>/dev/null | cut -f1)
echo "  GGUF rebuilt: spam-classifier-F16.gguf (${GGUF_SIZE_MB} MB)"
echo ""

# ── Upload to HuggingFace ──
echo "------------------------------------------------------------"
echo "  Upload new GGUF to HuggingFace? [y/N] "
read -n 1 -s -r hf_choice
echo "$hf_choice"
echo ""

if [[ "$hf_choice" == "y" || "$hf_choice" == "Y" ]]; then
    echo "  Uploading spam-classifier-F16.gguf..."
    python3 - <<PYEOF
from huggingface_hub import HfApi
api = HfApi()
import os
gguf_file = "$GGUF_FILE"
repo_id = "VoltageVagabond/spam-classifier-liquid-GGUF"
print(f"  Uploading to {repo_id}...")
api.upload_file(
    path_or_fileobj=gguf_file,
    path_in_repo="spam-classifier-F16.gguf",
    repo_id=repo_id,
    repo_type="model",
    commit_message="Rebuild GGUF after full retrain",
)
print(f"  Done! https://huggingface.co/{repo_id}")
PYEOF
    echo ""
fi

# ── Remind to restart server ──
echo "============================================================"
echo "  Done! To load the new model into llama.cpp:"
echo ""
echo "  1. Double-click StopServer.command"
echo "  2. Double-click StartServer.command"
echo "============================================================"
echo ""
read -n 1 -s -r -p "Press any key to close..."