|
| 1 | +#!/bin/bash |
| 2 | +# TurboQuant.cpp — One-command quickstart |
| 3 | +# Downloads Qwen3.5-0.8B, builds the engine, converts the model, and runs inference. |
| 4 | +# |
| 5 | +# Usage: |
| 6 | +# bash scripts/quickstart.sh |
| 7 | +# bash scripts/quickstart.sh "Your prompt here" |
| 8 | + |
| 9 | +set -e |
| 10 | + |
| 11 | +PROMPT="${1:-What is deep learning?}" |
| 12 | +THREADS="${2:-4}" |
| 13 | +ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 14 | +cd "$ROOT" |
| 15 | + |
| 16 | +echo "=== TurboQuant.cpp Quickstart ===" |
| 17 | +echo "" |
| 18 | + |
| 19 | +# Step 1: Build |
| 20 | +if [ ! -f build/tq_run ]; then |
| 21 | + echo "[1/4] Building..." |
| 22 | + cmake -B build -DCMAKE_BUILD_TYPE=Release -DTQ_BUILD_TESTS=OFF -DTQ_BUILD_BENCH=OFF -Wno-dev 2>/dev/null |
| 23 | + cmake --build build -j"$(nproc 2>/dev/null || sysctl -n hw.ncpu)" --target tq_run --target tq_convert 2>&1 | tail -3 |
| 24 | + echo " Done." |
| 25 | +else |
| 26 | + echo "[1/4] Build found." |
| 27 | +fi |
| 28 | + |
| 29 | +# Step 2: Download model if not cached |
| 30 | +MODEL_DIR="$HOME/.cache/huggingface/hub/models--Qwen--Qwen3.5-0.8B" |
| 31 | +if [ ! -d "$MODEL_DIR" ]; then |
| 32 | + echo "[2/4] Downloading Qwen3.5-0.8B (~1.5 GB)..." |
| 33 | + if command -v huggingface-cli &>/dev/null; then |
| 34 | + huggingface-cli download Qwen/Qwen3.5-0.8B --local-dir-use-symlinks True |
| 35 | + elif command -v python3 &>/dev/null; then |
| 36 | + python3 -c " |
| 37 | +from huggingface_hub import snapshot_download |
| 38 | +snapshot_download('Qwen/Qwen3.5-0.8B') |
| 39 | +print('Download complete.') |
| 40 | +" 2>/dev/null || { |
| 41 | + echo " Installing huggingface_hub..." |
| 42 | + pip3 install --quiet huggingface_hub 2>/dev/null || pip3 install --quiet --break-system-packages huggingface_hub 2>/dev/null |
| 43 | + python3 -c " |
| 44 | +from huggingface_hub import snapshot_download |
| 45 | +snapshot_download('Qwen/Qwen3.5-0.8B') |
| 46 | +print('Download complete.') |
| 47 | +" |
| 48 | + } |
| 49 | + else |
| 50 | + echo "Error: python3 or huggingface-cli required for model download." |
| 51 | + echo " Install: pip3 install huggingface_hub" |
| 52 | + echo " Or download manually: https://huggingface.co/Qwen/Qwen3.5-0.8B" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | + echo " Done." |
| 56 | +else |
| 57 | + echo "[2/4] Model found in cache." |
| 58 | +fi |
| 59 | + |
| 60 | +# Step 3: Convert to TQM |
| 61 | +if [ ! -f model.tqm ]; then |
| 62 | + echo "[3/4] Converting to TQM format..." |
| 63 | + ./build/tq_convert -o model.tqm -j "$THREADS" |
| 64 | + echo " Done." |
| 65 | +else |
| 66 | + echo "[3/4] model.tqm found." |
| 67 | +fi |
| 68 | + |
| 69 | +# Step 4: Run inference |
| 70 | +echo "[4/4] Running inference..." |
| 71 | +echo "" |
| 72 | +./build/tq_run model.tqm -p "$PROMPT" -j "$THREADS" -n 100 |
0 commit comments