Skip to content

Installer Windows: honour UNSLOTH_FORCE_ROCM_TORCH on a mixed NVIDIA + AMD host and say when the AMD card is skipped - #19181

Merged
danielhanchen merged 22 commits into
unslothai:mainfrom
LeoBorcherding:issue-12248-windows-parity
Nov 24, 2026
Merged

danielhanchen merged 22 commits into
unslothai:mainfrom
LeoBorcherding:issue-12248-windows-parity

Conversation

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

Part of #12248

On Windows, install.ps1 and setup.ps1 stop looking for AMD once an NVIDIA GPU is found, so a mixed host always gets CUDA torch, UNSLOTH_FORCE_ROCM_TORCH does nothing, and nothing says the AMD card was skipped. Linux already handles all three.

  • UNSLOTH_FORCE_ROCM_TORCH=1, or CUDA_VISIBLE_DEVICES=-1, installs ROCm torch through the existing AMD-only Windows route, and setup.ps1 keeps it while the flag or mask is set.
  • Without them, CUDA stays and the installer prints install.sh's mixed-host notice (not for an iGPU).
  • A flag with no usable AMD card warns and keeps CUDA; a mask left set warns that it hides the AMD card too.
  • install_python_stack.py no longer ignores the flag on Windows.
[INFO] An AMD GPU (gfx1201) was also found. CUDA PyTorch was installed for the NVIDIA GPU,
[INFO] so training will not use the AMD GPU (one torch install serves one vendor).
[INFO] To train on the AMD GPU instead, re-run this installer with $env:UNSLOTH_FORCE_ROCM_TORCH = "1";
what ran machine result
test_windows_mixed_host_force_rocm_12248.py + 9 Windows AMD routing suites gr33n, Windows 11, pwsh 7.6.9, hardware mocked 503 passed at 78f14c1
test_nvidia_adapter_presence.ps1 gr33n all checks passed at 78f14c1
stack test at base 81803c7 Mac M5 fails, as expected

Not run: a real Windows install on a machine with both an NVIDIA and an AMD GPU.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T17:40:54.304749Z 473cf67 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…iant and the device-pack fast path

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…er and opaque pins; no amd-smi in the notice probe

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…route, weigh amd-smi arches, keep Write-StudioLine in step with setup.ps1
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…DIA; initialise the mute flag for StrictMode callers

[skip ci]
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit that referenced this pull request Nov 24, 2026
## Problem

On runners with 16 GB of RAM, 35 llama.cpp placement tests fail across
`(Python 3.13, g-l)` and `(Python 3.13, m-r)`. The staging runs for
#19113, #19181 and #19244 all show them, for example:

```
test_llama_cpp_placement.py::test_the_moe_cache_stays_off[ram_cannot_pin_experts-]
  assert _load_mode(cmd) == "none"   (None == 'none')
Load mode: keeping mmap; pinning the host-side weights plus the 9.0 GB llama-server grows into
would hold more than 50% of the 15.3 GB of RAM, which the OS cannot page out.
```

They pass on larger runners and locally, so this only shows up on some
runners.

## Cause

#19231 (price llama-server host RAM growth before pinning a spilled
load) is correct. A pinned launch (`--load-mode none`) now also checks
that the pinned host-side weights plus llama-server's growth stay under
a safe share of total RAM. That total comes from
`_host_memory_capacity_mib()`, which reads the real `MemTotal` and the
cgroup limit.

The placement tests fake the GPUs and, where they care, the available
RAM. They never pin the total, so each launch decided against whatever
machine ran it. Reproduced locally by stubbing
`_total_system_memory_mib` to 15667 MiB: 35 failed, 770 passed in the
three files below.

## Fix

- `test_llama_cpp_placement.py` gets an autouse fixture,
`_pinned_host_ram`. It pins `LlamaCppBackend._total_system_memory_mib`
to 256 GiB and `_cgroup_memory_limit_mib` to `None`, so every launch
sees the same host on any runner.
- `test_lookup_table_fit.py` and `test_prompt_cache_sized_to_context.py`
launch through that file's helpers, so they import the fixture.
- Tests that are about host RAM still set their own total in the test
body, which overrides the fixture.

## Verification

- The three files on this branch: 805 passed.
- With the host forced to 15.3 GB (a plugin stubbing
`_total_system_memory_mib`): 805 passed on this branch, and 35 failed on
main.
- All 34 test files that import `test_llama_cpp_placement`: 2365 passed
and 24 skipped.
- One test failed:
`test_cached_gguf_routes.py::test_pipeline_class_guard_passes_every_shipped_family`.
- It fails identically on main, because this host has diffusers
0.41.0.dev0 and the test needs 0.42.0. It is unrelated to this change.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
danielhanchen added a commit that referenced this pull request Nov 24, 2026
…9310)

## Problem


`tests/test_prefetch_snapshot_scope.py::test_st_cache_resolutions_honor_explicit_hf_cache_dir`
fails on main since #19170, and with it the Core legs of every PR based
on main (seen first on the staging run for #19181):

```
AssertionError: an ST cache_dir resolution must read an explicit kwargs.get('cache_dir') first
```

## Cause

#19170 added `_refuse_network_share_raw_adapter_base(...)` before both
`SentenceTransformer(...)` loads. On the `for_inference = True` route it
passes

```python
cache_dir = st_kwargs.get("cache_folder")
or os.environ.get("SENTENCE_TRANSFORMERS_HOME"),
```

The code is right. A few lines earlier the same function maps an
explicit HF `cache_dir` onto `st_kwargs["cache_folder"]`:

```python
_st_cache = kwargs.get("cache_dir") or kwargs.get("cache_folder")
if _st_cache is not None:
    st_kwargs["cache_folder"] = _st_cache
```

so `st_kwargs.get("cache_folder")` already reads `cache_dir` first, and
it is the same value the neighbouring `_check_modules_json_types(...,
cache_dir = st_kwargs.get("cache_folder"))` call and the
`SentenceTransformer(**st_kwargs)` load use. The guard only looked for
the literal `'cache_dir'` inside the expression, so it could not see the
mapping. #19170's own CI ran on an older base and the failure showed up
only after it merged.

## Fix

Test only, no product code changes. The guard now accepts a resolution
that either:

- reads `kwargs.get("cache_dir")` as its first operand, or
- reads `<dict>.get("cache_folder")` first, where the same function,
earlier, assigns `<dict>["cache_folder"]` only from expressions whose
first operand reads `cache_dir` (directly or through one local name).

This is stricter than before in one way: `cache_dir` has to come first,
not just appear somewhere in the expression.

## Verification

- `tests/test_prefetch_snapshot_scope.py`: 43 passed (1 failed on main).
- Sabotage, one at a time on `sentence_transformer.py`, each makes the
guard fail:
- swapping the mapping to `kwargs.get("cache_folder") or
kwargs.get("cache_dir")`;
  - dropping `st_kwargs["cache_folder"] = _st_cache`;
- changing the delegated route's resolution to
`kwargs.get("cache_folder") or
os.environ.get("SENTENCE_TRANSFORMERS_HOME")`.
- With `tests/test_adapter_unc_base_guard.py` (the tests #19170 added):
all pass.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 24, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 473cf67e0a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 9ccccbe into unslothai:main Nov 24, 2026
67 of 72 checks passed
danielhanchen added a commit that referenced this pull request Nov 24, 2026
## Problem

Two install.ps1 source checks fail on main since #19181 (honour
`UNSLOTH_FORCE_ROCM_TORCH` on a mixed NVIDIA + AMD Windows host):

-
`tests/studio/install/test_rdna1_unsupported_message_8529.py::test_the_unsupported_arch_variable_is_declared_outside_the_amd_block`
  ```
AssertionError: install.ps1: the AMD declaration block was restructured;
re-check this test
  ```
-
`tests/studio/install/test_rocm_support.py::TestHipSdkInstalledButDeviceInaccessible::test_install_ps1_sets_flag_when_hipinfo_binary_found`
  ```
  assert (-1 != -1)
  ```

## Cause

#19181 widened two gates on purpose, and both tests anchored on the
exact old text:

- The AMD probe gate went from `if (-not $HasNvidiaSmi) {` to `if (-not
$HasNvidiaSmi -or $ProbeAmdBesideNvidia) {`, so a mixed host is probed
for the flag, mask and notice. `$ROCmUnsupportedGfxArch = $null` is
still declared before that gate, which is the property the first test
protects; its regex just no longer matched the gate line.
- The hipinfo block went from `if ($hipinfoExe) {` to `if ($hipinfoExe
-and -not $script:StudioMuteLines) {`. The silent, notice-only probe on
an NVIDIA host that keeps CUDA does not run hipinfo, so an unbounded HIP
tool cannot hold up that install (comment above the block).
`$HipSdkInstalled = $true` is still the first statement inside it; the
second test searched for the literal `if ($hipinfoExe)` and found
nothing.

The installer is right in both places; the tests needed to follow it.

## Fix

Test only:

- The first test accepts any gate that starts `if (-not $HasNvidiaSmi`
and still requires the declaration between `$ROCmGfxArch = $null` and
that gate.
- The second test finds the `if ($hipinfoExe ...)` block by regex, so
extra conditions are allowed, but it still requires the gate to test
`$hipinfoExe` and now also requires `$HipSdkInstalled = $true` to be the
block's first statement (before it only had to appear somewhere after
the gate).

## Verification

- Both files: 951 passed, 1 skipped (2 failed on main).
- Sabotage on `install.ps1`, one at a time, each makes the matching test
fail:
  - moving `$ROCmUnsupportedGfxArch = $null` inside the probe gate;
  - putting another statement before `$HipSdkInstalled = $true`;
  - dropping `$hipinfoExe` from the hipinfo gate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants