File size: 5,515 Bytes
91c4cd9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Lambda Mindlink Memotron β€” Windows installer
# Run:
#   powershell -NoProfile -ExecutionPolicy Bypass -File install.ps1
#   .\install.ps1 -Backend cpu      # non-interactive: cuda | cpu
[CmdletBinding()]
param(
    [ValidateSet("cuda", "cpu", "")]
    [string]$Backend = ""
)
$ErrorActionPreference = "Stop"

function Info($msg) { Write-Host "[INFO] $msg" -ForegroundColor Green }
function Warn($msg) { Write-Host "[WARN] $msg" -ForegroundColor Yellow }
function Die($msg)  { Write-Host "[ERROR] $msg" -ForegroundColor Red; exit 1 }

$RepoUrl = "https://huggingface.co/AIMindLink/lambda-mindlink-memotron"

# ── 1. Choose backend ────────────────────────────────────────────────
if (-not $Backend) {
    $suggest = 2
    if (Get-Command nvidia-smi -ErrorAction SilentlyContinue) { $suggest = 1 }
    Write-Host ""
    Write-Host "Select llama-cpp-python backend:"
    Write-Host "  1) CUDA  - NVIDIA GPU"
    Write-Host "  2) CPU   - no GPU (slow)"
    $choice = Read-Host "Choice [1-2, default $suggest]"
    if (-not $choice) { $choice = "$suggest" }
    if     ($choice -in "1","cuda") { $Backend = "cuda" }
    elseif ($choice -in "2","cpu")  { $Backend = "cpu" }
    else   { Die "Unknown choice '$choice'" }
}
Info "Backend: $Backend"

# ── 2. Python check ──────────────────────────────────────────────────
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
    Die "Python not found on PATH. Install 3.11/3.12 from python.org and tick 'Add Python to PATH'."
}
$pyver = ((python --version) 2>&1 | Out-String).Trim()
if ($pyver -notmatch '^Python 3\.\d+') {
    Die "Could not read Python version (got '$pyver'). Is the Windows Store python alias interfering?"
}
if ($pyver -notmatch '^Python 3\.(11|12)\.') {
    Warn "Found $pyver β€” the project targets 3.11/3.12. Continuing anyway."
}
Info "Found $pyver"

# ── 3. Get the repo (skip clone if run from inside the repo) ─────────
if (-not (Test-Path "main.py")) {
    if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
        Die "git not found. Install from git-scm.com, or download the project ZIP and re-run from inside the folder."
    }
    Info "Cloning repository..."
    git clone $RepoUrl
    Set-Location "lambda-mindlink-memotron"
}

# ── 4. Virtual environment ───────────────────────────────────────────
if (-not (Test-Path ".venv")) {
    Info "Creating virtual environment..."
    python -m venv .venv
}
# Use the venv's python.exe directly β€” sidesteps Activate.ps1 execution-policy issues
$py = Join-Path (Get-Location) ".venv\Scripts\python.exe"
Info "Upgrading pip..."
& $py -m pip install --upgrade pip

# ── 5. llama-cpp-python ──────────────────────────────────────────────
if ($Backend -eq "cuda") {
    # Detect CUDA tag: nvcc (toolkit) first, then nvidia-smi (driver)
    $detected = ""
    if (Get-Command nvcc -ErrorAction SilentlyContinue) {
        if ((nvcc --version | Out-String) -match 'release (\d+)\.(\d+)') { $detected = "cu$($Matches[1])$($Matches[2])" }
    }
    if (-not $detected -and (Get-Command nvidia-smi -ErrorAction SilentlyContinue)) {
        if ((nvidia-smi | Out-String) -match 'CUDA Version:\s*(\d+)\.(\d+)') { $detected = "cu$($Matches[1])$($Matches[2])" }
    }
    if (-not $detected -or $detected -notin "cu118","cu121","cu122","cu123","cu124") {
        if (-not $detected) { $detected = "cu121" }
        else { Warn "Detected $detected has no prebuilt wheel β€” defaulting to cu121."; $detected = "cu121" }
    }
    $tag = Read-Host "CUDA wheel tag [default: $detected] (cu118, cu121, cu122, cu123, cu124)"
    if (-not $tag) { $tag = $detected }
    Info "Installing llama-cpp-python (CUDA wheel: $tag)..."
    & $py -m pip install llama-cpp-python --extra-index-url "https://abetlen.github.io/llama-cpp-python/whl/$tag"
    Warn "If pip says 'Building wheel for llama-cpp-python', no wheel matched β€” re-run with another tag."
}
else {
    Info "Installing llama-cpp-python (CPU only)..."
    & $py -m pip install llama-cpp-python
    Warn "If pip compiles from source, install 'Visual Studio Build Tools' with the C++ workload."
}

# ── 6. Remaining dependencies + ai folder ─────────────────────────────
Info "Installing requirements.txt..."
& $py -m pip install -r requirements.txt
New-Item -ItemType Directory -Force -Path "ai" | Out-Null

# ── 7. Done ──────────────────────────────────────────────────────────
Write-Host ""
Info "Installation complete."
Write-Host "Next steps:"
Write-Host "  1. Copy your .gguf files into: $(Get-Location)\ai\"
Write-Host "  2. Edit config.py (_ALPHA_INTELLIGENCE_TO_LOAD, _MODEL_TYPE)"
Write-Host "  3. Start the app:"
Write-Host "       .\.venv\Scripts\Activate.ps1"
Write-Host "       python main.py"
```

Optionally add a tiny `install.bat` so Windows users can just double-click:

```bat
@echo off
rem Double-click-friendly wrapper for install.ps1
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0install.ps1" %*
pause