From 3521de7040573a8253306dae3ca1d5abcb283383 Mon Sep 17 00:00:00 2001 From: Roland Tannous Date: Sat, 28 Feb 2026 07:45:40 +0000 Subject: [PATCH] Build llama.cpp in-tree, auto-detect driver CUDA version for compatible toolkit --- setup.ps1 | 7 +++---- studio/backend/core/inference/llama_cpp.py | 6 +++--- test_llama_cpp.ps1 | 1 + 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/setup.ps1 b/setup.ps1 index c213dcbf50..1269467368 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -556,12 +556,13 @@ $ErrorActionPreference = $prevEAP # ========================================================================== # PHASE 4: Build llama.cpp with CUDA for GGUF inference + export # ========================================================================== -# Builds at ~/.unsloth/llama.cpp/ (persistent across pip upgrades). +# Builds in-tree at $REPO/llama.cpp/ (same as setup.sh on Linux). +# This directory is already in .gitignore. # We build: # - llama-server: for GGUF model inference # - llama-quantize: for GGUF export quantization # Prerequisites (git, cmake, VS Build Tools, CUDA Toolkit) already installed in Phase 1. -$LlamaCppDir = Join-Path $env:USERPROFILE ".unsloth\llama.cpp" +$LlamaCppDir = Join-Path $PSScriptRoot "llama.cpp" $BuildDir = Join-Path $LlamaCppDir "build" $LlamaServerBin = Join-Path $BuildDir "bin\Release\llama-server.exe" @@ -588,8 +589,6 @@ if (Test-Path $LlamaServerBin) { $FailedStep = "" # -- Step A: Clone or pull llama.cpp -- - $UnslothDir = Join-Path $env:USERPROFILE ".unsloth" - if (-not (Test-Path $UnslothDir)) { New-Item -ItemType Directory -Path $UnslothDir -Force | Out-Null } if (Test-Path (Join-Path $LlamaCppDir ".git")) { Write-Host " llama.cpp repo already cloned, pulling latest..." -ForegroundColor Gray diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py index cf4494df30..7ae9bd142a 100644 --- a/studio/backend/core/inference/llama_cpp.py +++ b/studio/backend/core/inference/llama_cpp.py @@ -100,13 +100,13 @@ class LlamaCppBackend: if build_path.is_file(): return str(build_path) - # 3. Windows MSVC build (setup.ps1 builds here — Release config) + # 3. Windows MSVC build (Release config, in-tree — matches setup.ps1) if sys.platform == "win32": - # In-tree + # In-tree (primary — setup.ps1 now builds here) win_path = project_root / "llama.cpp" / "build" / "bin" / "Release" / binary_name if win_path.is_file(): return str(win_path) - # ~/.unsloth (setup.ps1 default location) + # Legacy: ~/.unsloth (older setup.ps1 versions built here) home_path = Path.home() / ".unsloth" / "llama.cpp" / "build" / "bin" / "Release" / binary_name if home_path.is_file(): return str(home_path) diff --git a/test_llama_cpp.ps1 b/test_llama_cpp.ps1 index 6e16057640..b98177eac6 100644 --- a/test_llama_cpp.ps1 +++ b/test_llama_cpp.ps1 @@ -32,6 +32,7 @@ if ($BinaryPath) { $RepoRoot = $PSScriptRoot $SearchPaths += Join-Path $RepoRoot "llama.cpp\build\bin\Release\llama-server.exe" $SearchPaths += Join-Path $RepoRoot "llama.cpp\build\bin\llama-server.exe" +# Legacy: older setup.ps1 built under ~/.unsloth $SearchPaths += Join-Path $env:USERPROFILE ".unsloth\llama.cpp\build\bin\Release\llama-server.exe" # Check LLAMA_SERVER_PATH env var