File size: 4,793 Bytes
18e0633
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────────
# Selential Core β€” Setup Script
# ─────────────────────────────────────────────────────────────
# Downloads the base model (Qwen3.5) and configures the build.
#
# Usage:
#   chmod +x setup.sh
#   ./setup.sh                # GPU (CUDA) β€” default
#   ./setup.sh --cpu          # CPU-only
#   ./setup.sh --big          # Full 35B model (24GB+ VRAM)
#   ./setup.sh --cpu --big    # CPU-only + big model
# ─────────────────────────────────────────────────────────────

set -euo pipefail

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'

echo -e "${CYAN}╔══════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}β•‘     Selential Core β€” Setup                   β•‘${NC}"
echo -e "${CYAN}β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•${NC}"
echo ""

# ── Parse arguments ──
USE_CUDA=true
USE_BIG=false
for arg in "$@"; do
    case "$arg" in
        --cpu) USE_CUDA=false ;;
        --big) USE_BIG=true   ;;
    esac
done

# ── Select model ──
if [ "$USE_BIG" = true ]; then
    MODEL_REPO="Qwen/Qwen3.5-35B-A3B-UD-GGUF"
    MODEL_FILENAME="qwen3.5-35b-a3b-ud-q4_k_m.gguf"
    MODEL_FILE="Qwen3.5-35B-A3B-UD-Q4_K_M.gguf"
    MODEL_SIZE="22 GB"
    MIN_VRAM=24
else
    MODEL_REPO="Qwen/Qwen3.5-0.8B-GGUF"
    MODEL_FILENAME="qwen3.5-0.8b-q4_k_m.gguf"
    MODEL_FILE="Qwen3.5-0.8B-Q4_K_M.gguf"
    MODEL_SIZE="508 MB"
    MIN_VRAM=2
fi

MODEL_URL="https://huggingface.co/${MODEL_REPO}/resolve/main/${MODEL_FILENAME}"

# ── Check prerequisites ──
echo -e "${YELLOW}[1/3] Checking prerequisites...${NC}"

if ! command -v curl &> /dev/null; then
    echo -e "${RED}Error: curl is required. Install it with: sudo apt install curl${NC}"
    exit 1
fi

if ! command -v cargo &> /dev/null; then
    echo -e "${RED}Error: Rust/Cargo not found. Install: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh${NC}"
    exit 1
fi

# ── Configure CUDA feature in Cargo.toml ──
echo ""
echo -e "${YELLOW}[2/3] Configuring build...${NC}"

if [ "$USE_CUDA" = true ]; then
    if command -v nvcc &> /dev/null; then
        echo -e "${GREEN}  βœ… CUDA toolkit found${NC}"
        # Ensure CUDA feature is enabled in Cargo.toml
        if grep -q 'features = \["cuda"\]' Cargo.toml; then
            echo -e "  CUDA feature already enabled"
        else
            echo -e "  Enabling CUDA feature..."
            sed -i 's/llama-cpp-2 = { version = "0.1"/llama-cpp-2 = { version = "0.1", features = ["cuda"]/' Cargo.toml
            sed -i 's/llama-cpp-sys-2 = { version = "0.1"/llama-cpp-sys-2 = { version = "0.1", features = ["cuda"]/' Cargo.toml
        fi
    else
        echo -e "${YELLOW}  ⚠️  nvcc not found β€” falling back to CPU${NC}"
        # Remove CUDA feature
        sed -i 's/, features = \["cuda"\]//g' Cargo.toml
        USE_CUDA=false
    fi
else
    echo -e "${YELLOW}  CPU-only build (no CUDA overhead)${NC}"
    # Remove CUDA feature for CPU-only compilation
    sed -i 's/, features = \["cuda"\]//g' Cargo.toml
fi

# ── Download model ──
echo ""
echo -e "${YELLOW}[3/3] Downloading model (~${MODEL_SIZE})...${NC}"
echo -e "${CYAN}  ${MODEL_FILE}${NC}"
echo ""

if [ -f "$MODEL_FILE" ]; then
    echo -e "${GREEN}  βœ… Already exists: ${MODEL_FILE}${NC}"
else
    echo -e "  Downloading from HuggingFace..."
    echo -e "  ${MODEL_URL}"
    echo ""
    curl -L --progress-bar -o "$MODEL_FILE" "$MODEL_URL"
    echo -e "${GREEN}  βœ… Downloaded: ${MODEL_FILE}${NC}"
fi

# ── Done ──
echo ""
echo -e "${GREEN}╔══════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}β•‘     Setup Complete!                          β•‘${NC}"
echo -e "${GREEN}β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•${NC}"
echo ""
echo -e "  πŸ“¦ Model: ${MODEL_FILE}"
echo -e "  πŸ–₯️  Mode: $([ "$USE_CUDA" = true ] && echo 'GPU (CUDA)' || echo 'CPU')"
echo ""
echo -e "  ${CYAN}Next:${NC}"
echo -e "    cargo run --release -- interactive"
echo ""