Make the Intel auto-route guard test able to fail and stop the ps1 harness doubling --force-cpu

test_non_vulkan_backend_suppresses_intel_auto_route ran on Linux x86_64, where
dropping the explicit_backend guard changes only a log line, so the test passed
either way. Move it to Linux ARM64 + Intel GPU, the host where the guard decides
the routed repo, and assert that value.

_run_ps1 composed the --force-cpu snippet twice: it is already inside the
normalized block the helper extracts. The substring assertion hid the duplicate.
Compose it once and compare the whole argv. setup.ps1 appends the flag once and
is unchanged.
This commit is contained in:
Daniel Han 2026-07-29 08:43:07 +00:00
commit d6f374082d
2 changed files with 19 additions and 12 deletions

View file

@ -759,21 +759,26 @@ def test_route_to_vulkan_prebuilt_cpu_fallback_wins():
@pytest.mark.parametrize("backend", ["hip", "rocm", "cpu"])
def test_non_vulkan_backend_suppresses_intel_auto_route(monkeypatch, backend, via):
# The selector suppresses the Intel auto-route the same way whether it arrives
# from the environment or from --llama-backend.
# from the environment or from --llama-backend. Pinned to Linux ARM64, the one
# host where the suppression shows up in a returned VALUE: without it the Intel
# auto-route fires, falls through to the ARM64 fork -> upstream reroute and
# hands back UPSTREAM with the fork pin dropped. On x86_64 the auto-route
# rewrites neither host nor repo, so only a log line differs and the same case
# there cannot fail.
kwargs = {}
if via == "env":
monkeypatch.setenv("UNSLOTH_LLAMA_CPP_BACKEND", backend)
else:
kwargs["llama_backend"] = backend
host = _host(is_linux = True, is_x86_64 = True, has_intel_gpu = True)
host = _linux_arm64_vulkan_host()
routed, repo, tag, persist = ilp._route_to_vulkan_prebuilt(
host, FORK, "b9596-mix-abc", force_cpu = False, **kwargs
)
assert routed is host
assert repo == FORK
assert tag == "b9596-mix-abc"
assert repo == FORK, repo
assert tag == "b9596-mix-abc", tag
assert persist is None

View file

@ -300,15 +300,15 @@ def test_llama_backend_source_choice_in_setup_ps1(backend, force_vulkan, expecte
def _run_ps1(value: str | None) -> str:
# The override is normalized (assign + warn) at the top of the prebuilt block and
# applied to $prebuiltArgs lower down; compose both real snippets.
# One snippet, not two: NORMALIZE already spans the whole if/elseif chain up to
# and including the "Ignoring UNSLOTH_LLAMA_CPP_BACKEND" warn, so the --force-cpu
# append is inside it. Composing the apply snippet on top of it made the harness
# emit the flag twice while setup.ps1 appends it once.
normalize = _ps1_search(
r"\$llamaBackend = \$sourceLlamaBackend.*?Ignoring UNSLOTH_LLAMA_CPP_BACKEND.*?\n\s*\}",
re.DOTALL,
)
apply_flag = _ps1_search(
r'if \(\$llamaBackend -eq "cpu"\) \{\s*\$prebuiltArgs \+= "--force-cpu"\s*\}'
)
assert normalize.count('$prebuiltArgs += "--force-cpu"') == 1, normalize
env = {
k: v
for k, v in os.environ.items()
@ -320,7 +320,7 @@ def _run_ps1(value: str | None) -> str:
"$prebuiltArgs = @()\n"
'$sourceLlamaBackend = "$($env:UNSLOTH_LLAMA_CPP_BACKEND)".Trim().ToLowerInvariant()\n'
'$sourceLegacyForceVulkan = "$($env:UNSLOTH_FORCE_VULKAN)".Trim().ToLowerInvariant()\n'
f'{normalize}\n{apply_flag}\n"ARGS:" + ($prebuiltArgs -join ",")'
f'{normalize}\n"ARGS:" + ($prebuiltArgs -join ",")'
)
out = subprocess.run(
["pwsh", "-NoProfile", "-Command", harness],
@ -336,8 +336,10 @@ def _run_ps1(value: str | None) -> str:
@pytest.mark.parametrize("value", ["cpu", "CPU", "Cpu", " cpu ", "CPU\t"])
def test_ps1_backend_cpu_appends_flag(value):
out = _run_ps1(value)
assert "--force-cpu" in out
assert "Ignoring" not in out
# The whole argv, not a substring: an `in` check passed while the harness was
# emitting --force-cpu twice. setup.ps1 appends it exactly once, and nothing
# else, for a cpu override.
assert out.strip() == "ARGS:--force-cpu"
@_SKIP_NO_PWSH