Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

fix windows llama.cpp compile from source issue (#4793)

DoubleMathew7ae9b7f45f96
diff --git a/studio/install_llama_prebuilt.py b/studio/install_llama_prebuilt.py
index 61e57614a81..13382d3c164 100755
--- a/studio/install_llama_prebuilt.py
+++ b/studio/install_llama_prebuilt.py
@@ -14,6 +14,7 @@ import json
import os
import platform
import random
+import re
import shutil
import site
import socket
@@ -561,6 +562,33 @@ def windows_cuda_upstream_asset_names(llama_tag: str, runtime: str) -> list[str]
]
+def windows_cuda_asset_aliases(
+ asset_name: str,
+ *,
+ compatibility_tag: str | None = None,
+) -> list[str]:
+ aliases: list[str] = []
+ legacy_match = re.fullmatch(
+ r"llama-(?P<tag>[^/]+)-bin-win-cuda-(?P<runtime>\d+\.\d+)-x64\.zip",
+ asset_name,
+ )
+ if legacy_match:
+ runtime = legacy_match.group("runtime")
+ aliases.append(f"cudart-llama-bin-win-cuda-{runtime}-x64.zip")
+ if compatibility_tag:
+ aliases.append(f"llama-{compatibility_tag}-bin-win-cuda-{runtime}-x64.zip")
+ return aliases
+
+ current_match = re.fullmatch(
+ r"cudart-llama-bin-win-cuda-(?P<runtime>\d+\.\d+)-x64\.zip",
+ asset_name,
+ )
+ if current_match and compatibility_tag:
+ runtime = current_match.group("runtime")
+ aliases.append(f"llama-{compatibility_tag}-bin-win-cuda-{runtime}-x64.zip")
+ return aliases
+
+
def format_byte_count(num_bytes: float) -> str:
units = ["B", "KiB", "MiB", "GiB", "TiB"]
value = float(num_bytes)
@@ -3867,9 +3895,7 @@ def apply_approved_hashes(
checksums: ApprovedReleaseChecksums,
) -> list[AssetChoice]:
def approved_hash_for_attempt(attempt: AssetChoice) -> ApprovedArtifactHash | None:
- approved = checksums.artifacts.get(attempt.name)
- if approved is not None:
- return approved
+ candidate_names = [attempt.name]
if (
isinstance(attempt.tag, str)
and attempt.tag
@@ -3883,7 +3909,19 @@ def apply_approved_hashes(
if attempt.name.startswith(legacy_prefix)
else attempt.name
)
- approved = checksums.artifacts.get(compatibility_name)
+ candidate_names.append(compatibility_name)
+ candidate_names.extend(
+ windows_cuda_asset_aliases(
+ attempt.name,
+ compatibility_tag = checksums.upstream_tag,
+ )
+ )
+ seen_names: set[str] = set()
+ for candidate_name in candidate_names:
+ if candidate_name in seen_names:
+ continue
+ seen_names.add(candidate_name)
+ approved = checksums.artifacts.get(candidate_name)
if approved is not None:
return approved
return None
diff --git a/studio/setup.ps1 b/studio/setup.ps1
index 396a04486fe..382de89b9f3 100644
--- a/studio/setup.ps1
+++ b/studio/setup.ps1
@@ -71,6 +71,12 @@ function Refresh-Environment {
$env:Path = "$machinePath;$userPath"
}
+# PowerShell 5.1 compatibility helper: avoid relying on New-TemporaryFile.
+function New-UnslothTemporaryFile {
+ $tempPath = [System.IO.Path]::GetTempFileName()
+ return Get-Item -LiteralPath $tempPath
+}
+
# Find nvcc on PATH, CUDA_PATH, or standard toolkit dirs.
# Returns the path to nvcc.exe, or $null if not found.
function Find-Nvcc {
@@ -1599,20 +1605,67 @@ $LlamaCppDir = Join-Path $UnslothHome "llama.cpp"
$NeedLlamaSourceBuild = $false
$SkipPrebuiltInstall = $false
$RequestedLlamaTag = if ($env:UNSLOTH_LLAMA_TAG) { $env:UNSLOTH_LLAMA_TAG } else { $DefaultLlamaTag }
-# Force all installs to use mainline llama.cpp from ggml-org.
-# Previously: $HelperReleaseRepo = if ($env:UNSLOTH_LLAMA_RELEASE_REPO) { $env:UNSLOTH_LLAMA_RELEASE_REPO } else { "unslothai/llama.cpp" }
$HelperReleaseRepo = "ggml-org/llama.cpp"
$LlamaPr = if ($env:UNSLOTH_LLAMA_PR) { $env:UNSLOTH_LLAMA_PR.Trim() } else { "" }
$LlamaPrForce = if ($env:UNSLOTH_LLAMA_PR_FORCE) { $env:UNSLOTH_LLAMA_PR_FORCE.Trim() } else { $DefaultLlamaPrForce }
-# Force mainline source -- no env var override.
-# Previously: $LlamaSource = if ($env:UNSLOTH_LLAMA_SOURCE) { $env:UNSLOTH_LLAMA_SOURCE.Trim() } else { $DefaultLlamaSource }
$LlamaSource = $DefaultLlamaSource
if ($LlamaSource.EndsWith('.git')) { $LlamaSource = $LlamaSource.Substring(0, $LlamaSource.Length - 4) }
$ResolvedSourceUrl = $LlamaSource
$ResolvedSourceRef = $RequestedLlamaTag
$ResolvedSourceRefKind = "tag"
+if ($env:UNSLOTH_LLAMA_FORCE_COMPILE -eq "1") {
+ $NeedLlamaSourceBuild = $true
+ $SkipPrebuiltInstall = $true
+}
+
+function Invoke-LlamaHelper {
+ param(
+ [string[]]$Arguments,
+ [string]$StderrPath = $null
+ )
+
+ $previousErrorActionPreference = $ErrorActionPreference
+ $previousNativeErrorPreference = $null
+ $restoreNativeErrorPreference = $false
+ $ErrorActionPreference = "Continue"
+ if ($PSVersionTable.PSVersion.Major -ge 7) {
+ $previousNativeErrorPreference = $PSNativeCommandUseErrorActionPreference
+ $PSNativeCommandUseErrorActionPreference = $false
+ $restoreNativeErrorPreference = $true
+ }
+
+ try {
+ # Capture all output (stdout + stderr) so that PowerShell does not
+ # convert stderr lines into visible ErrorRecord objects. Separate
+ # stdout from stderr afterwards.
+ $allOutput = & python "$PSScriptRoot\install_llama_prebuilt.py" @Arguments 2>&1
+ $exitCode = $LASTEXITCODE
+ $stdoutLines = @()
+ $stderrLines = @()
+ foreach ($line in $allOutput) {
+ if ($line -is [System.Management.Automation.ErrorRecord]) {
+ $stderrLines += $line.ToString()
+ } else {
+ $stdoutLines += $line
+ }
+ }
+ if ($StderrPath -and $stderrLines.Count -gt 0) {
+ $stderrLines | Out-File -FilePath $StderrPath -Encoding utf8
+ }
+ return [pscustomobject]@{
+ Output = $stdoutLines
+ ExitCode = $exitCode
+ }
+ } finally {
+ $ErrorActionPreference = $previousErrorActionPreference
+ if ($restoreNativeErrorPreference) {
+ $PSNativeCommandUseErrorActionPreference = $previousNativeErrorPreference
+ }
+ }
+}
+
if ($LlamaSource -ne "https://github.com/ggml-org/llama.cpp") {
step "llama.cpp" "custom source: $LlamaSource -- forcing source build" "Yellow"
$NeedLlamaSourceBuild = $true
@@ -1640,11 +1693,14 @@ if ($LlamaPr) {
# Custom source or other override already forced source build; skip the
# prebuilt release resolution. When building from a custom fork, the fork
# may not carry upstream bNNNN tags.
- if ($LlamaSource -eq "https://github.com/ggml-org/llama.cpp") {
+ if ($env:UNSLOTH_LLAMA_FORCE_COMPILE -eq "1") {
+ $ResolvedLlamaTag = $RequestedLlamaTag
+ } elseif ($LlamaSource -eq "https://github.com/ggml-org/llama.cpp") {
$resolveTagArgs = @("--resolve-llama-tag", $RequestedLlamaTag, "--published-repo", $HelperReleaseRepo, "--output-format", "json")
if ($env:UNSLOTH_LLAMA_RELEASE_TAG) { $resolveTagArgs += @("--published-release-tag", $env:UNSLOTH_LLAMA_RELEASE_TAG) }
- $fallbackOutput = & python "$PSScriptRoot\install_llama_prebuilt.py" @resolveTagArgs 2>$null
- $fallbackExit = $LASTEXITCODE
+ $fallbackResult = Invoke-LlamaHelper -Arguments $resolveTagArgs
+ $fallbackOutput = $fallbackResult.Output
+ $fallbackExit = $fallbackResult.ExitCode
$ResolvedLlamaTag = if ($fallbackExit -eq 0 -and $fallbackOutput) {
try {
(($fallbackOutput | Out-String) | ConvertFrom-Json).llama_tag
@@ -1660,9 +1716,10 @@ if ($LlamaPr) {
} else {
$resolveInstallArgs = @("--resolve-install-tag", $RequestedLlamaTag, "--published-repo", $HelperReleaseRepo, "--output-format", "json")
if ($env:UNSLOTH_LLAMA_RELEASE_TAG) { $resolveInstallArgs += @("--published-release-tag", $env:UNSLOTH_LLAMA_RELEASE_TAG) }
- $resolveErrorLog = New-TemporaryFile
- $resolveOutput = & python "$PSScriptRoot\install_llama_prebuilt.py" @resolveInstallArgs 2>$resolveErrorLog
- $resolveExit = $LASTEXITCODE
+ $resolveErrorLog = New-UnslothTemporaryFile
+ $resolveResult = Invoke-LlamaHelper -Arguments $resolveInstallArgs -StderrPath $resolveErrorLog
+ $resolveOutput = $resolveResult.Output
+ $resolveExit = $resolveResult.ExitCode
$ResolvedLlamaTag = if ($resolveOutput) {
try {
(($resolveOutput | Out-String) | ConvertFrom-Json).llama_tag
@@ -1679,8 +1736,9 @@ if ($LlamaPr) {
# before falling back to the bleeding-edge ggml-org/llama.cpp tag.
$resolveFallbackArgs = @("--resolve-llama-tag", $RequestedLlamaTag, "--published-repo", $HelperReleaseRepo, "--output-format", "json")
if ($env:UNSLOTH_LLAMA_RELEASE_TAG) { $resolveFallbackArgs += @("--published-release-tag", $env:UNSLOTH_LLAMA_RELEASE_TAG) }
- $fallbackOutput = & python "$PSScriptRoot\install_llama_prebuilt.py" @resolveFallbackArgs 2>$null
- $fallbackExit = $LASTEXITCODE
+ $fallbackResult = Invoke-LlamaHelper -Arguments $resolveFallbackArgs
+ $fallbackOutput = $fallbackResult.Output
+ $fallbackExit = $fallbackResult.ExitCode
$ResolvedLlamaTag = if ($fallbackExit -eq 0 -and $fallbackOutput) {
try {
(($fallbackOutput | Out-String) | ConvertFrom-Json).llama_tag
@@ -1723,16 +1781,29 @@ if ($env:UNSLOTH_LLAMA_FORCE_COMPILE -eq "1") {
}
$prevEAPPrebuilt = $ErrorActionPreference
$ErrorActionPreference = "Continue"
- if ($script:UnslothVerbose) {
- # Show live output in verbose mode while still capturing for error log
- $prebuiltLog = Join-Path $env:TEMP "unsloth-prebuilt-$PID.log"
- & python @prebuiltArgs 2>&1 | Tee-Object -FilePath $prebuiltLog | Out-Host
- $prebuiltExit = $LASTEXITCODE
- $prebuiltOutput = if (Test-Path $prebuiltLog) { Get-Content $prebuiltLog -Raw } else { "" }
- Remove-Item $prebuiltLog -ErrorAction SilentlyContinue
- } else {
- $prebuiltOutput = & python @prebuiltArgs 2>&1 | Out-String
- $prebuiltExit = $LASTEXITCODE
+ $previousNativeErrorPreference = $null
+ $restoreNativeErrorPreference = $false
+ if ($PSVersionTable.PSVersion.Major -ge 7) {
+ $previousNativeErrorPreference = $PSNativeCommandUseErrorActionPreference
+ $PSNativeCommandUseErrorActionPreference = $false
+ $restoreNativeErrorPreference = $true
+ }
+ try {
+ if ($script:UnslothVerbose) {
+ # Show live output in verbose mode while still capturing for error log
+ $prebuiltLog = Join-Path $env:TEMP "unsloth-prebuilt-$PID.log"
+ & python @prebuiltArgs 2>&1 | Tee-Object -FilePath $prebuiltLog | Out-Host
+ $prebuiltExit = $LASTEXITCODE
+ $prebuiltOutput = if (Test-Path $prebuiltLog) { Get-Content $prebuiltLog -Raw } else { "" }
+ Remove-Item $prebuiltLog -ErrorAction SilentlyContinue
+ } else {
+ $prebuiltOutput = & python @prebuiltArgs 2>&1 | Out-String
+ $prebuiltExit = $LASTEXITCODE
+ }
+ } finally {
+ if ($restoreNativeErrorPreference) {
+ $PSNativeCommandUseErrorActionPreference = $previousNativeErrorPreference
+ }
}
$ErrorActionPreference = $prevEAPPrebuilt
@@ -1847,7 +1918,10 @@ if (Test-Path $LlamaServerBin) {
if (-not $NeedLlamaSourceBuild) {
Write-Host ""
step "llama.cpp" "prebuilt (validated)"
-} elseif ((Test-Path $LlamaServerBin) -and -not $NeedRebuild) {
+} elseif ((Test-Path $LlamaServerBin) -and -not $NeedRebuild -and $RequestedLlamaTag -ne "master") {
+ # Skip rebuild only for pinned tags (e.g. b8635). When the requested
+ # tag is "master" (a moving target), always rebuild so the binary picks
+ # up new model architecture support (e.g. Gemma 4).
Write-Host ""
step "llama.cpp" "already built"
} elseif (-not $HasCmakeForBuild) {
@@ -1906,8 +1980,9 @@ if (-not $NeedLlamaSourceBuild) {
if ($LlamaSource -eq "https://github.com/ggml-org/llama.cpp") {
$resolveSourceArgs = @("--resolve-source-build", $RequestedLlamaTag, "--published-repo", $HelperReleaseRepo, "--output-format", "json")
if ($env:UNSLOTH_LLAMA_RELEASE_TAG) { $resolveSourceArgs += @("--published-release-tag", $env:UNSLOTH_LLAMA_RELEASE_TAG) }
- $sourcePlanOutput = & python "$PSScriptRoot\install_llama_prebuilt.py" @resolveSourceArgs 2>$null
- $sourcePlanExit = $LASTEXITCODE
+ $sourcePlanResult = Invoke-LlamaHelper -Arguments $resolveSourceArgs
+ $sourcePlanOutput = $sourcePlanResult.Output
+ $sourcePlanExit = $sourcePlanResult.ExitCode
if ($sourcePlanExit -eq 0 -and $sourcePlanOutput) {
try {
$sourcePlan = ($sourcePlanOutput | Out-String) | ConvertFrom-Json
diff --git a/studio/setup.sh b/studio/setup.sh
index 116dc12e082..76fd79e7a2c 100755
--- a/studio/setup.sh
+++ b/studio/setup.sh
@@ -483,19 +483,22 @@ _LLAMA_CPP_DEGRADED=false
_LLAMA_FORCE_COMPILE="${UNSLOTH_LLAMA_FORCE_COMPILE:-0}"
_REQUESTED_LLAMA_TAG="${UNSLOTH_LLAMA_TAG:-${_DEFAULT_LLAMA_TAG}}"
# Force all installs to use mainline llama.cpp from ggml-org.
-# Previously: _HELPER_RELEASE_REPO="${UNSLOTH_LLAMA_RELEASE_REPO:-unslothai/llama.cpp}"
_HELPER_RELEASE_REPO="ggml-org/llama.cpp"
_LLAMA_PR="${UNSLOTH_LLAMA_PR:-}"
_LLAMA_PR_FORCE="${UNSLOTH_LLAMA_PR_FORCE:-${_DEFAULT_LLAMA_PR_FORCE}}"
-# Force mainline source -- no env var override.
-# Previously: _LLAMA_SOURCE="${UNSLOTH_LLAMA_SOURCE:-${_DEFAULT_LLAMA_SOURCE}}"
+# Force mainline source -- no env var override for now.
_LLAMA_SOURCE="${_DEFAULT_LLAMA_SOURCE}"
_LLAMA_SOURCE="${_LLAMA_SOURCE%.git}" # normalize: strip trailing .git
_RESOLVED_SOURCE_URL="$_LLAMA_SOURCE"
_RESOLVED_SOURCE_REF="$_REQUESTED_LLAMA_TAG"
_RESOLVED_SOURCE_REF_KIND="tag"
+if [ "$_LLAMA_FORCE_COMPILE" = "1" ]; then
+ _NEED_LLAMA_SOURCE_BUILD=true
+ _SKIP_PREBUILT_INSTALL=true
+fi
+
# Non-default source URL forces source build (fork has different code than prebuilt).
if [ "$_LLAMA_SOURCE" != "https://github.com/ggml-org/llama.cpp" ]; then
step "llama.cpp" "custom source: $_LLAMA_SOURCE -- forcing source build" "$C_WARN"
@@ -527,7 +530,9 @@ elif [ "${_SKIP_PREBUILT_INSTALL:-false}" = true ]; then
# the prebuilt release resolution entirely. When building from a custom
# fork, the fork may not carry upstream bNNNN tags, so resolve the tag
# only when the source is the default ggml-org repo.
- if [ "$_LLAMA_SOURCE" = "https://github.com/ggml-org/llama.cpp" ]; then
+ if [ "$_LLAMA_FORCE_COMPILE" = "1" ]; then
+ _RESOLVED_LLAMA_TAG="$_REQUESTED_LLAMA_TAG"
+ elif [ "$_LLAMA_SOURCE" = "https://github.com/ggml-org/llama.cpp" ]; then
_RESOLVE_TAG_ARGS=(--resolve-llama-tag "$_REQUESTED_LLAMA_TAG" --published-repo "$_HELPER_RELEASE_REPO")
_RESOLVE_TAG_ARGS+=(--output-format json)
if [ -n "${UNSLOTH_LLAMA_RELEASE_TAG:-}" ]; then
diff --git a/tests/studio/install/test_llama_pr_force_and_source.py b/tests/studio/install/test_llama_pr_force_and_source.py
index 44cbda4c71e..114680f4580 100644
--- a/tests/studio/install/test_llama_pr_force_and_source.py
+++ b/tests/studio/install/test_llama_pr_force_and_source.py
@@ -1,11 +1,11 @@
"""
-Tests for UNSLOTH_LLAMA_PR_FORCE and UNSLOTH_LLAMA_SOURCE in setup.sh / setup.ps1.
+Tests for the current llama.cpp wrapper policy in setup.sh / setup.ps1.
Tests cover:
- Bash subprocess: PR_FORCE promotion, user-override, zero/empty/invalid ignored
- - Bash subprocess: custom source URL forces build, clone URL uses variable
- - Static source checks: defaults present, clone URLs parameterized
- - PowerShell subprocess: PR_FORCE promotion, user-override parity
+ - Bash subprocess: source remains pinned to ggml-org even if env source is set
+ - Static source checks: mainline repo/source are hardcoded for now
+ - PowerShell subprocess: PR_FORCE promotion and fixed-source parity
Run: pytest tests/studio/install/test_llama_pr_force_and_source.py -v
"""
@@ -109,7 +109,7 @@ def make_mock_git(tmp_path: Path, *, fail_on: str = "") -> tuple[Path, Path]:
# =========================================================================
-# Bash fragment that exercises PR_FORCE and _LLAMA_SOURCE resolution
+# Bash fragment that exercises PR_FORCE and fixed _LLAMA_SOURCE resolution
# =========================================================================
def _bash_resolution_fragment(
llama_pr: str = "",
@@ -125,7 +125,8 @@ def _bash_resolution_fragment(
_DEFAULT_LLAMA_SOURCE={shlex.quote(default_source)}
_LLAMA_PR_FORCE={shlex.quote(llama_pr_force) if llama_pr_force else '"$_DEFAULT_LLAMA_PR_FORCE"'}
- _LLAMA_SOURCE={shlex.quote(llama_source) if llama_source else '"$_DEFAULT_LLAMA_SOURCE"'}
+ export UNSLOTH_LLAMA_SOURCE={shlex.quote(llama_source) if llama_source else '""'}
+ _LLAMA_SOURCE="$_DEFAULT_LLAMA_SOURCE"
_LLAMA_SOURCE="${{_LLAMA_SOURCE%.git}}"
_NEED_LLAMA_SOURCE_BUILD=false
@@ -225,20 +226,10 @@ class TestBashPrForcePromotion:
# =========================================================================
-# TEST GROUP B: Bash custom source URL (subprocess)
+# TEST GROUP B: Bash fixed mainline source (subprocess)
# =========================================================================
-class TestBashCustomSource:
- """Custom _LLAMA_SOURCE forces source build."""
-
- def test_custom_source_forces_build(self):
- script = _bash_resolution_fragment(
- llama_source = "https://github.com/unslothai/llama.cpp",
- )
- r = run_bash(script)
- assert r.returncode == 0
- assert "NEED_SOURCE=true" in r.stdout
- assert "SKIP_PREBUILT=true" in r.stdout
- assert "custom source:" in r.stdout
+class TestBashFixedMainlineSource:
+ """Source remains pinned to ggml-org while the temporary policy is active."""
def test_default_source_no_force(self):
script = _bash_resolution_fragment()
@@ -248,32 +239,23 @@ class TestBashCustomSource:
assert "SKIP_PREBUILT=false" in r.stdout
assert "custom source:" not in r.stdout
- def test_trailing_git_stripped(self):
+ def test_env_source_override_is_ignored(self):
script = _bash_resolution_fragment(
llama_source = "https://github.com/unslothai/llama.cpp.git",
)
r = run_bash(script)
assert r.returncode == 0
- assert "LLAMA_SOURCE=https://github.com/unslothai/llama.cpp" in r.stdout
- assert "NEED_SOURCE=true" in r.stdout
-
- def test_baked_in_source_forces_build(self):
- script = _bash_resolution_fragment(
- default_source = "https://github.com/unslothai/llama.cpp",
- )
- r = run_bash(script)
- assert r.returncode == 0
- assert "NEED_SOURCE=true" in r.stdout
+ assert "LLAMA_SOURCE=https://github.com/ggml-org/llama.cpp" in r.stdout
+ assert "NEED_SOURCE=false" in r.stdout
+ assert "SKIP_PREBUILT=false" in r.stdout
- def test_env_source_overrides_baked_in(self):
- """User UNSLOTH_LLAMA_SOURCE overrides _DEFAULT_LLAMA_SOURCE."""
+ def test_baked_in_source_stays_mainline(self):
script = _bash_resolution_fragment(
- llama_source = "https://github.com/custom/llama.cpp",
- default_source = "https://github.com/unslothai/llama.cpp",
+ default_source = "https://github.com/ggml-org/llama.cpp",
)
r = run_bash(script)
assert r.returncode == 0
- assert "LLAMA_SOURCE=https://github.com/custom/llama.cpp" in r.stdout
+ assert "LLAMA_SOURCE=https://github.com/ggml-org/llama.cpp" in r.stdout
# =========================================================================
@@ -386,7 +368,7 @@ class TestBashCloneUrlParameterized:
# TEST GROUP D: Static source patterns -- setup.sh
# =========================================================================
class TestSourcePatternsSh:
- """Verify setup.sh has the new defaults and parameterized clone URLs."""
+ """Verify setup.sh keeps the temporary mainline-only llama.cpp policy."""
@pytest.fixture(autouse = True)
def _load_source(self):
@@ -404,8 +386,21 @@ class TestSourcePatternsSh:
def test_has_pr_force_env_read(self):
assert "UNSLOTH_LLAMA_PR_FORCE" in self.content
- def test_has_source_env_read(self):
- assert "UNSLOTH_LLAMA_SOURCE" in self.content
+ def test_source_env_override_removed(self):
+ assert "UNSLOTH_LLAMA_SOURCE:-${_DEFAULT_LLAMA_SOURCE}" not in self.content
+ assert '_LLAMA_SOURCE="${_DEFAULT_LLAMA_SOURCE}"' in self.content
+
+ def test_release_repo_override_removed(self):
+ assert "UNSLOTH_LLAMA_RELEASE_REPO:-unslothai/llama.cpp" not in self.content
+ assert '_HELPER_RELEASE_REPO="ggml-org/llama.cpp"' in self.content
+
+ def test_force_compile_skips_prebuilt_resolution_early(self):
+ assert 'if [ "$_LLAMA_FORCE_COMPILE" = "1" ]; then' in self.content
+ assert "_SKIP_PREBUILT_INSTALL=true" in self.content
+
+ def test_force_compile_uses_requested_tag_without_helper(self):
+ assert 'if [ "$_LLAMA_FORCE_COMPILE" = "1" ]; then' in self.content
+ assert '_RESOLVED_LLAMA_TAG="$_REQUESTED_LLAMA_TAG"' in self.content
def test_pr_force_resolution_block(self):
assert '_LLAMA_PR="$_LLAMA_PR_FORCE"' in self.content
@@ -425,16 +420,13 @@ class TestSourcePatternsSh:
assert "ggml-org/llama.cpp.git" not in pr_block
def test_clone_urls_parameterized_tag_path(self):
- """Non-PR clone path uses ${_LLAMA_SOURCE}.git, not hardcoded URL."""
+ """Non-PR clone path uses the resolved source URL, not a hardcoded URL."""
# Find the non-PR clone line (after _CLONE_ARGS)
idx = self.content.index("_CLONE_ARGS=(git clone --depth 1)")
block = self.content[idx : idx + 400]
- assert '"${_LLAMA_SOURCE}.git"' in block
+ assert '"${_RESOLVED_SOURCE_URL}.git"' in block
assert "ggml-org/llama.cpp.git" not in block
- def test_custom_source_forces_build(self):
- assert "custom source: $_LLAMA_SOURCE -- forcing source build" in self.content
-
def test_no_hardcoded_clone_urls(self):
"""No remaining hardcoded ggml-org clone URLs in clone commands."""
lines = self.content.splitlines()
@@ -449,7 +441,7 @@ class TestSourcePatternsSh:
# TEST GROUP E: Static source patterns -- setup.ps1
# =========================================================================
class TestSourcePatternsPs1:
- """Verify setup.ps1 has the new defaults and parameterized clone URLs."""
+ """Verify setup.ps1 keeps the temporary mainline-only llama.cpp policy."""
@pytest.fixture(autouse = True)
def _load_source(self):
@@ -467,8 +459,24 @@ class TestSourcePatternsPs1:
def test_has_pr_force_env_read(self):
assert "$env:UNSLOTH_LLAMA_PR_FORCE" in self.content
- def test_has_source_env_read(self):
- assert "$env:UNSLOTH_LLAMA_SOURCE" in self.content
+ def test_source_env_override_removed(self):
+ assert "$LlamaSource = if ($env:UNSLOTH_LLAMA_SOURCE)" not in self.content
+ assert "$LlamaSource = $DefaultLlamaSource" in self.content
+
+ def test_release_repo_override_removed(self):
+ assert (
+ "$HelperReleaseRepo = if ($env:UNSLOTH_LLAMA_RELEASE_REPO)"
+ not in self.content
+ )
+ assert '$HelperReleaseRepo = "ggml-org/llama.cpp"' in self.content
+
+ def test_force_compile_skips_prebuilt_resolution_early(self):
+ assert 'if ($env:UNSLOTH_LLAMA_FORCE_COMPILE -eq "1") {' in self.content
+ assert "$SkipPrebuiltInstall = $true" in self.content
+
+ def test_force_compile_uses_requested_tag_without_helper(self):
+ assert 'if ($env:UNSLOTH_LLAMA_FORCE_COMPILE -eq "1") {' in self.content
+ assert "$ResolvedLlamaTag = $RequestedLlamaTag" in self.content
def test_pr_force_promotion_block(self):
assert "$LlamaPr = $LlamaPrForce" in self.content
@@ -487,15 +495,12 @@ class TestSourcePatternsPs1:
assert "ggml-org/llama.cpp.git" not in pr_block
def test_clone_urls_parameterized_tag_path(self):
- """Non-PR clone path uses $LlamaSource.git, not hardcoded URL."""
+ """Non-PR clone path uses the resolved source URL, not a hardcoded URL."""
clone_args_idx = self.content.index('$cloneArgs = @("clone"')
block = self.content[clone_args_idx : clone_args_idx + 400]
- assert '"$LlamaSource.git"' in block
+ assert '"$ResolvedSourceUrl.git"' in block
assert "ggml-org/llama.cpp.git" not in block
- def test_custom_source_forces_build(self):
- assert "custom source: $LlamaSource -- forcing source build" in self.content
-
def test_no_hardcoded_clone_urls(self):
"""No remaining hardcoded ggml-org clone URLs in clone commands."""
lines = self.content.splitlines()
@@ -511,7 +516,7 @@ class TestSourcePatternsPs1:
# =========================================================================
@requires_pwsh
class TestPwshPrForcePromotion:
- """PR_FORCE promotion and source URL logic via pwsh subprocess."""
+ """PR_FORCE promotion and fixed-source logic via pwsh subprocess."""
FRAGMENT_TEMPLATE = textwrap.dedent("""\
function step($a, $b, $c) { Write-Output "step:$a`:$b" }
@@ -521,7 +526,7 @@ class TestPwshPrForcePromotion:
$LlamaPr = if ($env:UNSLOTH_LLAMA_PR) { $env:UNSLOTH_LLAMA_PR.Trim() } else { "" }
$LlamaPrForce = if ($env:UNSLOTH_LLAMA_PR_FORCE) { $env:UNSLOTH_LLAMA_PR_FORCE.Trim() } else { $DefaultLlamaPrForce }
- $LlamaSource = if ($env:UNSLOTH_LLAMA_SOURCE) { $env:UNSLOTH_LLAMA_SOURCE.Trim() } else { $DefaultLlamaSource }
+ $LlamaSource = $DefaultLlamaSource
if ($LlamaSource.EndsWith('.git')) { $LlamaSource = $LlamaSource.Substring(0, $LlamaSource.Length - 4) }
$NeedLlamaSourceBuild = $false
@@ -561,7 +566,6 @@ class TestPwshPrForcePromotion:
# Ensure env vars are unset by default
run_env["UNSLOTH_LLAMA_PR"] = ""
run_env["UNSLOTH_LLAMA_PR_FORCE"] = ""
- run_env["UNSLOTH_LLAMA_SOURCE"] = ""
if env:
run_env.update(env)
return run_pwsh(script, env = run_env)
@@ -599,15 +603,16 @@ class TestPwshPrForcePromotion:
assert r.returncode == 0
assert "baked-in PR_FORCE" not in r.stdout
- def test_custom_source_forces_build(self):
+ def test_env_source_override_is_ignored(self):
r = self._run(
env = {
"UNSLOTH_LLAMA_SOURCE": "https://github.com/unslothai/llama.cpp",
}
)
assert r.returncode == 0
- assert "NEED_SOURCE=True" in r.stdout
- assert "SKIP_PREBUILT=True" in r.stdout
+ assert "LLAMA_SOURCE=https://github.com/ggml-org/llama.cpp" in r.stdout
+ assert "NEED_SOURCE=False" in r.stdout
+ assert "SKIP_PREBUILT=False" in r.stdout
def test_default_source_no_force(self):
r = self._run()
@@ -615,16 +620,16 @@ class TestPwshPrForcePromotion:
assert "NEED_SOURCE=False" in r.stdout
assert "SKIP_PREBUILT=False" in r.stdout
- def test_trailing_git_stripped(self):
+ def test_trailing_git_override_is_ignored(self):
r = self._run(
env = {
"UNSLOTH_LLAMA_SOURCE": "https://github.com/unslothai/llama.cpp.git",
}
)
assert r.returncode == 0
- assert "LLAMA_SOURCE=https://github.com/unslothai/llama.cpp" in r.stdout
+ assert "LLAMA_SOURCE=https://github.com/ggml-org/llama.cpp" in r.stdout
- def test_baked_in_source_forces_build(self):
- r = self._run(default_source = "https://github.com/unslothai/llama.cpp")
+ def test_baked_in_source_stays_mainline(self):
+ r = self._run(default_source = "https://github.com/ggml-org/llama.cpp")
assert r.returncode == 0
- assert "NEED_SOURCE=True" in r.stdout
+ assert "LLAMA_SOURCE=https://github.com/ggml-org/llama.cpp" in r.stdout
diff --git a/tests/studio/install/test_pr4562_bugfixes.py b/tests/studio/install/test_pr4562_bugfixes.py
index f5a423d1300..7fa654d8450 100644
--- a/tests/studio/install/test_pr4562_bugfixes.py
+++ b/tests/studio/install/test_pr4562_bugfixes.py
@@ -778,6 +778,34 @@ class TestSourceCodePatterns:
assert "$ResolvedSourceRefKind" in content
assert "$ResolvedSourceRef" in content
+ def test_setup_ps1_prebuilt_install_disables_native_error_abort(self):
+ """PS1 prebuilt install should not abort setup on helper stderr."""
+ content = SETUP_PS1.read_text()
+ install_idx = content.index("& python @prebuiltArgs 2>&1")
+ block = content[max(0, install_idx - 800) : install_idx + 800]
+ assert "$PSNativeCommandUseErrorActionPreference = $false" in block
+ assert "$restoreNativeErrorPreference = $true" in block
+ assert (
+ "$PSNativeCommandUseErrorActionPreference = $previousNativeErrorPreference"
+ in block
+ )
+
+ def test_setup_ps1_helper_disables_error_action_abort(self):
+ """Helper resolution should suppress terminating NativeCommandError on PS 5.1."""
+ content = SETUP_PS1.read_text()
+ helper_idx = content.index("function Invoke-LlamaHelper")
+ block = content[helper_idx : helper_idx + 1200]
+ assert "$previousErrorActionPreference = $ErrorActionPreference" in block
+ assert '$ErrorActionPreference = "Continue"' in block
+ assert "$ErrorActionPreference = $previousErrorActionPreference" in block
+
+ def test_setup_ps1_uses_local_tempfile_helper(self):
+ """PS1 should not depend on New-TemporaryFile being available."""
+ content = SETUP_PS1.read_text()
+ assert "function New-UnslothTemporaryFile" in content
+ assert "$resolveErrorLog = New-UnslothTemporaryFile" in content
+ assert "$resolveErrorLog = New-TemporaryFile" not in content
+
def test_binary_env_linux_has_binary_parent(self):
"""The Linux branch of binary_env should include binary_path.parent."""
content = MODULE_PATH.read_text()
diff --git a/tests/studio/install/test_selection_logic.py b/tests/studio/install/test_selection_logic.py
index b8de0e221f5..6a2e367dc85 100644
--- a/tests/studio/install/test_selection_logic.py
+++ b/tests/studio/install/test_selection_logic.py
@@ -511,6 +511,56 @@ class TestApplyApprovedHashes:
result = apply_approved_hashes([choice], checksums)
assert result[0].expected_sha256 == "a" * 64
+ def test_windows_cuda_legacy_choice_can_match_current_upstream_name(self):
+ choice = AssetChoice(
+ repo = UPSTREAM_REPO,
+ tag = "b9000",
+ name = "llama-b9000-bin-win-cuda-13.1-x64.zip",
+ url = "https://x/llama-b9000-bin-win-cuda-13.1-x64.zip",
+ source_label = "upstream",
+ )
+ checksums = ApprovedReleaseChecksums(
+ repo = "unslothai/llama.cpp",
+ release_tag = "r1",
+ upstream_tag = "b9000",
+ artifacts = {
+ "cudart-llama-bin-win-cuda-13.1-x64.zip": ApprovedArtifactHash(
+ asset_name = "cudart-llama-bin-win-cuda-13.1-x64.zip",
+ sha256 = "b" * 64,
+ repo = UPSTREAM_REPO,
+ kind = "windows-cuda-upstream",
+ )
+ },
+ )
+
+ result = apply_approved_hashes([choice], checksums)
+ assert result[0].expected_sha256 == "b" * 64
+
+ def test_windows_cuda_current_choice_can_match_legacy_compatibility_name(self):
+ choice = AssetChoice(
+ repo = UPSTREAM_REPO,
+ tag = "main",
+ name = "cudart-llama-bin-win-cuda-13.1-x64.zip",
+ url = "https://x/cudart-llama-bin-win-cuda-13.1-x64.zip",
+ source_label = "upstream",
+ )
+ checksums = ApprovedReleaseChecksums(
+ repo = "unslothai/llama.cpp",
+ release_tag = "r1",
+ upstream_tag = "b9000",
+ artifacts = {
+ "llama-b9000-bin-win-cuda-13.1-x64.zip": ApprovedArtifactHash(
+ asset_name = "llama-b9000-bin-win-cuda-13.1-x64.zip",
+ sha256 = "c" * 64,
+ repo = UPSTREAM_REPO,
+ kind = "windows-cuda-upstream",
+ )
+ },
+ )
+
+ result = apply_approved_hashes([choice], checksums)
+ assert result[0].expected_sha256 == "c" * 64
+
def test_none_approved(self):
c1 = self._choice("missing.tar.gz")
checksums = make_checksums(["other.tar.gz"])