Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

9.1 KB
Raw Blame
#!/bin/bash
# ============================================================================
# ODS macOS Installer -- Tier Map
# ============================================================================
# Part of: installers/macos/lib/
# Purpose: Map hardware tier to model name, GGUF file, URL, and context size
#
# Canonical source: installers/lib/tier-map.sh (keep values byte-identical)
#
# Modder notes:
#   Add new tiers or change model assignments here.
#   Each tier maps to a specific GGUF quantization and context window.
#
#   Apple Silicon unified memory:
#   All system RAM is shared between macOS, Docker, and the LLM.
#   ~8GB is consumed by system overhead, so tier thresholds are
#   set conservatively compared to discrete-GPU platforms.
# ============================================================================

normalize_model_profile() {
    local profile="${1:-${MODEL_PROFILE:-qwen}}"
    profile="$(printf '%s' "$profile" | tr '[:upper:]' '[:lower:]')"
    case "$profile" in
        auto)                 echo "auto" ;;
        gemma|gemma4|gemma-4) echo "gemma4" ;;
        *)                    echo "qwen" ;;
    esac
}

effective_model_profile() {
    local tier="$1"
    local requested
    requested="$(normalize_model_profile "${2:-}")"
    if [[ "$requested" == "auto" ]]; then
        case "$tier" in
            CLOUD|0) echo "qwen" ;;
            *)       echo "gemma4" ;;
        esac
    else
        echo "$requested"
    fi
}

configure_llama_runtime_defaults() {
    LLAMA_CPP_RELEASE_TAG_OVERRIDE=""
    case "$MODEL_PROFILE_EFFECTIVE" in
        gemma4) LLAMA_CPP_RELEASE_TAG_OVERRIDE="b9014" ;;
    esac
}

set_qwen_tier_config() {
    local tier="$1"

    case "$tier" in
        CLOUD)
            TIER_NAME="Cloud (API)"
            LLM_MODEL="anthropic/claude-sonnet-4-6"
            GGUF_FILE=""
            GGUF_URL=""
            GGUF_SHA256=""
            MAX_CONTEXT=200000
            ;;
        4)
            TIER_NAME="Enterprise"
            LLM_MODEL="qwen3.6-35b-a3b"
            GGUF_FILE="Qwen3.6-35B-A3B-UD-Q4_K_M.gguf"
            GGUF_URL="https://huggingface.co/unsloth/Qwen3.6-35B-A3B-GGUF/resolve/a483e9e6cbd595906af30beda3187c2663a1118c/Qwen3.6-35B-A3B-UD-Q4_K_M.gguf"
            GGUF_SHA256="ac0e2c1189e055faa36eff361580e79c5bd6f8e76bffb4ce547f167d53e31a61"
            MAX_CONTEXT=131072
            ;;
        3)
            TIER_NAME="Pro"
            LLM_MODEL="qwen3.6-35b-a3b"
            GGUF_FILE="Qwen3.6-35B-A3B-UD-Q4_K_M.gguf"
            GGUF_URL="https://huggingface.co/unsloth/Qwen3.6-35B-A3B-GGUF/resolve/a483e9e6cbd595906af30beda3187c2663a1118c/Qwen3.6-35B-A3B-UD-Q4_K_M.gguf"
            GGUF_SHA256="ac0e2c1189e055faa36eff361580e79c5bd6f8e76bffb4ce547f167d53e31a61"
            MAX_CONTEXT=131072
            ;;
        2)
            TIER_NAME="Prosumer"
            LLM_MODEL="qwen3.5-9b"
            GGUF_FILE="Qwen3.5-9B-Q4_K_M.gguf"
            GGUF_URL="https://huggingface.co/unsloth/Qwen3.5-9B-GGUF/resolve/3885219b6810b007914f3a7950a8d1b469d598a5/Qwen3.5-9B-Q4_K_M.gguf"
            GGUF_SHA256="03b74727a860a56338e042c4420bb3f04b2fec5734175f4cb9fa853daf52b7e8"
            MAX_CONTEXT=32768
            ;;
        0)
            TIER_NAME="Lightweight"
            LLM_MODEL="qwen3.5-2b"
            GGUF_FILE="Qwen3.5-2B-Q4_K_M.gguf"
            GGUF_URL="https://huggingface.co/unsloth/Qwen3.5-2B-GGUF/resolve/f6d5376be1edb4d416d56da11e5397a961aca8ae/Qwen3.5-2B-Q4_K_M.gguf"
            GGUF_SHA256="aaf42c8b7c3cab2bf3d69c355048d4a0ee9973d48f16c731c0520ee914699223"
            MAX_CONTEXT=8192
            ;;
        1)
            TIER_NAME="Entry Level"
            LLM_MODEL="qwen3.5-9b"
            GGUF_FILE="Qwen3.5-9B-Q4_K_M.gguf"
            GGUF_URL="https://huggingface.co/unsloth/Qwen3.5-9B-GGUF/resolve/3885219b6810b007914f3a7950a8d1b469d598a5/Qwen3.5-9B-Q4_K_M.gguf"
            GGUF_SHA256="03b74727a860a56338e042c4420bb3f04b2fec5734175f4cb9fa853daf52b7e8"
            MAX_CONTEXT=16384
            ;;
        *)
            ai_err "Invalid tier: $tier. Valid tiers: 0, 1, 2, 3, 4, CLOUD"
            exit 1
            ;;
    esac
}

set_gemma4_tier_config() {
    local tier="$1"

    case "$tier" in
        CLOUD)
            TIER_NAME="Cloud (API)"
            LLM_MODEL="anthropic/claude-sonnet-4-6"
            GGUF_FILE=""
            GGUF_URL=""
            GGUF_SHA256=""
            MAX_CONTEXT=200000
            ;;
        4)
            TIER_NAME="Enterprise"
            LLM_MODEL="gemma-4-31b-it"
            GGUF_FILE="gemma-4-31B-it-Q4_K_M.gguf"
            GGUF_URL="https://huggingface.co/unsloth/gemma-4-31B-it-GGUF/resolve/c1ac76e99d5513b141e8adde7288b85c3f9c32ec/gemma-4-31B-it-Q4_K_M.gguf"
            GGUF_SHA256="38bd64c852c4b460434cc7162fa9bdcf242faf86502581a754cb72956bb17f84"
            MAX_CONTEXT=65536
            ;;
        3)
            TIER_NAME="Pro"
            LLM_MODEL="gemma-4-26b-a4b-it"
            GGUF_FILE="gemma-4-26B-A4B-it-UD-Q4_K_M.gguf"
            GGUF_URL="https://huggingface.co/unsloth/gemma-4-26B-A4B-it-GGUF/resolve/c099eb48e663fd284577b04978a94ffccb261841/gemma-4-26B-A4B-it-UD-Q4_K_M.gguf"
            GGUF_SHA256="f2c28b3dc4776931ac6f879e11f203dec637ea0f14267a86ec8f6165f63f293f"
            MAX_CONTEXT=16384
            ;;
        2)
            TIER_NAME="Prosumer"
            LLM_MODEL="gemma-4-e4b-it"
            GGUF_FILE="gemma-4-E4B-it-Q4_K_M.gguf"
            GGUF_URL="https://huggingface.co/unsloth/gemma-4-E4B-it-GGUF/resolve/bfc15c382204943c3a8fff0c750b94ae2364d7a3/gemma-4-E4B-it-Q4_K_M.gguf"
            GGUF_SHA256="85a896a047553e842f25297ee5b031d64ff30147d9c4af17b1e4b394cd1fab87"
            MAX_CONTEXT=32768
            ;;
        0)
            TIER_NAME="Lightweight"
            LLM_MODEL="qwen3.5-2b"
            GGUF_FILE="Qwen3.5-2B-Q4_K_M.gguf"
            GGUF_URL="https://huggingface.co/unsloth/Qwen3.5-2B-GGUF/resolve/f6d5376be1edb4d416d56da11e5397a961aca8ae/Qwen3.5-2B-Q4_K_M.gguf"
            GGUF_SHA256="aaf42c8b7c3cab2bf3d69c355048d4a0ee9973d48f16c731c0520ee914699223"
            MAX_CONTEXT=8192
            ;;
        1)
            TIER_NAME="Entry Level"
            LLM_MODEL="gemma-4-e2b-it"
            GGUF_FILE="gemma-4-E2B-it-Q4_K_M.gguf"
            GGUF_URL="https://huggingface.co/unsloth/gemma-4-E2B-it-GGUF/resolve/0314792d7f1f7e229411f620751375812bb9faf2/gemma-4-E2B-it-Q4_K_M.gguf"
            GGUF_SHA256="740185b21d22ceb83a11c3aa62ad5842ef32c70f6096d756bbee85a1e4ec34b8"
            MAX_CONTEXT=16384
            ;;
        *)
            ai_err "Invalid tier: $tier. Valid tiers: 0, 1, 2, 3, 4, CLOUD"
            exit 1
            ;;
    esac
}

resolve_tier_config() {
    local tier="$1"

    MODEL_PROFILE_REQUESTED="$(normalize_model_profile)"
    MODEL_PROFILE_EFFECTIVE="$(effective_model_profile "$tier" "$MODEL_PROFILE_REQUESTED")"

    case "$MODEL_PROFILE_EFFECTIVE" in
        gemma4)
            if ! set_gemma4_tier_config "$tier"; then
                return 1
            fi
            ;;
        *)
            if ! set_qwen_tier_config "$tier"; then
                return 1
            fi
            ;;
    esac

    configure_llama_runtime_defaults
}

# Auto-select tier based on Apple Silicon unified memory
#
# Unlike discrete GPUs, Apple Silicon shares all system RAM between
# macOS (~4-5GB), Docker + services (~2-3GB), and the LLM model.
# Effective free memory ≈ total RAM minus ~8GB system overhead.
#
# Thresholds are set conservatively so the model + KV cache fit
# comfortably alongside everything else.
auto_select_tier() {
    local ram_gb="$1"
    local chip_variant="${2:-base}"

    if [[ "$ram_gb" -ge 64 ]]; then
        echo "4"
    elif [[ "$ram_gb" -ge 48 ]]; then
        echo "3"
    elif [[ "$ram_gb" -ge 32 ]]; then
        echo "2"
    elif [[ "$ram_gb" -ge 16 ]]; then
        # 16–31 GB unified → 9B model
        echo "1"
    else
        # < 16 GB unified → ultra-lightweight 2B model
        echo "0"
    fi
}

# ============================================================================
# Bootstrap Fast-Start
# ============================================================================

BOOTSTRAP_GGUF_FILE="Qwen3.5-2B-Q4_K_M.gguf"
BOOTSTRAP_GGUF_URL="https://huggingface.co/unsloth/Qwen3.5-2B-GGUF/resolve/f6d5376be1edb4d416d56da11e5397a961aca8ae/Qwen3.5-2B-Q4_K_M.gguf"
BOOTSTRAP_GGUF_SHA256="aaf42c8b7c3cab2bf3d69c355048d4a0ee9973d48f16c731c0520ee914699223"
BOOTSTRAP_LLM_MODEL="qwen3.5-2b"
# Hermes requires at least a 64K context window. Keep the fast-start model at
# that floor so Hermes works during the first-run bootstrap experience too.
BOOTSTRAP_MAX_CONTEXT=65536

macos_tier_rank() {
    case "$1" in
        4)          echo 4 ;;
        3)          echo 3 ;;
        2)          echo 2 ;;
        1)          echo 1 ;;
        0)          echo 0 ;;
        *)          echo 1 ;;
    esac
}

bootstrap_needed() {
    local tier="$1"
    local install_dir="$2"
    local gguf_file="$3"

    [[ "${NO_BOOTSTRAP:-false}" == "true" ]] && return 1
    [[ "${CLOUD_MODE:-false}" == "true" ]] && return 1
    [[ "${OFFLINE_MODE:-false}" == "true" ]] && return 1
    [[ "$(macos_tier_rank "$tier")" -le 0 ]] && return 1
    [[ -f "${install_dir}/data/models/${gguf_file}" ]] && return 1
    return 0
}