Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/MojoLlama/blob/main/src/mojollama/docker-entrypoint.sh # MojoLlama Archived Mojo/MAX quantizer and serving research repository (read-only history) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `MojoLlama / src / mojollama / docker-entrypoint.sh` 87 lines · 3437 bytes Raw Blame History 1 #!/bin/bash 2 # ============================================================ 3 # MojoLlama Docker Entrypoint 4 # ============================================================ 5 # Features: 6 # - Auto-tunes MojoLlama engine on first model load 7 # - Caches per-model tuning in ~/.mojollama/config.json 8 # - Sets OMP_NUM_THREADS from tuned config 9 # - Falls back to sensible defaults 10 # ============================================================ 11 12 set -e 13 14 # ── Locate model file ────────────────────────────────── 15 MODEL="" 16 for arg in "$@"; do 17 case "$arg" in 18 -m|--model) 19 shift 20 MODEL="$1" 21 ;; 22 *.gguf) 23 if [ -z "$MODEL" ] && [ -f "$arg" ]; then 24 MODEL="$arg" 25 fi 26 ;; 27 esac 28 done 29 30 # ── Auto-download model from HuggingFace if not found locally ── 31 if [ -n "$MODEL" ] && [ ! -f "$MODEL" ] && [ -n "$HF_REPO" ] && [ -n "$HF_FILE" ]; then 32 echo "==================================================" 33 echo " Downloading $HF_REPO/$HF_FILE ..." 34 echo "==================================================" 35 python3 -c " 36 from huggingface_hub import hf_hub_download 37 import os 38 os.makedirs(os.path.dirname('$MODEL'), exist_ok=True) 39 path = hf_hub_download(repo_id='$HF_REPO', filename='$HF_FILE', 40 local_dir=os.path.dirname('$MODEL') or '/models') 41 print(f'Downloaded to {path}') 42 " 43 if [ -f "$MODEL" ]; then 44 echo " ✓ Download complete" 45 else 46 echo " ⚠ Download may have failed; check HF_REPO/HF_FILE" 47 fi 48 fi 49 50 # ── Auto-tune on first model load ────────────────────── 51 # Skip if AUTO_TUNE=false or the model doesn't exist 52 if [ "${AUTO_TUNE:-true}" = "true" ] && [ -n "$MODEL" ] && [ -f "$MODEL" ]; then 53 MODEL_HASH=$(md5sum "$MODEL" 2>/dev/null | cut -d' ' -f1 || echo "unknown") 54 TUNE_CACHE="$HOME/.mojollama/tune_cache_${MODEL_HASH}.done" 55 56 if [ ! -f "$TUNE_CACHE" ]; then 57 echo "==================================================" 58 echo " MojoLlama AutoTune" 59 echo " Model: $(basename "$MODEL")" 60 echo " Running fast engine + concurrency sweep..." 61 echo "==================================================" 62 python3 -m mojollama autotune --model "$MODEL" --quick --mojollama 2>&1 63 mkdir -p "$HOME/.mojollama" 64 touch "$TUNE_CACHE" 65 echo " ✓ Tuning cached. Delete $TUNE_CACHE to re-tune." 66 echo "" 67 fi 68 69 # ── Apply tuned OMP threads ────────────────────────── 70 if [ -f "$HOME/.mojollama/config.json" ]; then 71 TUNED_THREADS=$(python3 -c " 72 import json 73 cfg = json.load(open('$HOME/.mojollama/config.json')) 74 print(cfg.get('mojollama_engine', {}).get('omp_threads', '')) 75 " 2>/dev/null || echo "") 76 if [ -n "$TUNED_THREADS" ]; then 77 export OMP_NUM_THREADS="$TUNED_THREADS" 78 echo " OMP_NUM_THREADS=$TUNED_THREADS (auto-tuned)" 79 fi 80 fi 81 fi 82 83 # ── Fallback OMP threads ────────────────────────────── 84 export OMP_NUM_THREADS="${OMP_NUM_THREADS:-$(nproc 2>/dev/null || echo 32)}" 85 86 # ── Launch mojollama ────────────────────────────────── 87 exec python3 -m mojollama "$@"