CoolFace
Apppublic

knoxel/bitnet-cpp-explorer

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
start.sh76 linesDownload Raw Back to root
1#!/bin/bash2set -e3 4WORK_DIR="/home/user/app"5BITNET_DIR="$WORK_DIR/BitNet"6MODEL_PATH="$WORK_DIR/BitNet/models/bitnet-b1.58-2B-4T-gguf/ggml-model-i2_s.gguf"7SERVER_BIN="$WORK_DIR/BitNet/build/bin/llama-server"8 9# ─── Step 1: Clone and build bitnet.cpp if not already done ──────────────────10if [ ! -f "$SERVER_BIN" ]; then11    echo "=== First run: building bitnet.cpp ==="12    echo "This takes ~5 minutes. Subsequent restarts will be fast."13    echo ""14 15    if [ ! -d "$BITNET_DIR" ]; then16        echo "[1/3] Cloning bitnet.cpp..."17        git clone --depth 1 --recursive https://github.com/microsoft/BitNet.git "$BITNET_DIR"18        pip install --no-cache-dir -r "$BITNET_DIR/requirements.txt"19    fi20 21    echo "[2/3] Building with I2_S kernel..."22    cd "$BITNET_DIR"23    python setup_env.py --hf-repo microsoft/bitnet-b1.58-2B-4T-gguf -q i2_s24    echo "Build complete!"25    cd "$WORK_DIR"26else27    echo "bitnet.cpp already built, skipping..."28fi29 30# ─── Step 2: Verify model exists ─────────────────────────────────────────────31if [ ! -f "$MODEL_PATH" ]; then32    echo "[3/3] Downloading model..."33    python -c "34from huggingface_hub import hf_hub_download35hf_hub_download(36    repo_id='microsoft/bitnet-b1.58-2B-4T-gguf',37    filename='ggml-model-i2_s.gguf',38    local_dir='$BITNET_DIR/models/bitnet-b1.58-2B-4T-gguf'39)40print('Model downloaded!')41"42fi43 44# ─── Step 3: Start llama-server ──────────────────────────────────────────────45echo ""46echo "=== Starting bitnet.cpp llama-server ==="47$SERVER_BIN \48    -m "$MODEL_PATH" \49    --host 127.0.0.1 \50    --port 8080 \51    -t 2 \52    -c 4096 \53    --log-disable &54 55SERVER_PID=$!56 57# Wait for server58echo "Waiting for server..."59for i in $(seq 1 120); do60    if curl -s http://127.0.0.1:8080/health > /dev/null 2>&1; then61        echo "Server ready! (${i}s)"62        break63    fi64    if [ $i -eq 120 ]; then65        echo "ERROR: Server failed to start"66        # Try to show what went wrong67        $SERVER_BIN -m "$MODEL_PATH" --host 127.0.0.1 --port 8081 -t 2 -c 512 2>&1 | head -2068        exit 169    fi70    sleep 171done72 73# ─── Step 4: Start Gradio ────────────────────────────────────────────────────74echo "Starting Gradio app..."75exec python app.py76