Skip to content

fix(studio): reject Vulkan diffusion gpu_ids before Phase 1 teardown - #7415

Merged
danielhanchen merged 9 commits into
unslothai:mainfrom
Souravrajvi0:feat/fix-diffusion-gpu-reject-early-661b
Jul 27, 2026
Merged

danielhanchen merged 9 commits into
unslothai:mainfrom
Souravrajvi0:feat/fix-diffusion-gpu-reject-early-661b

Conversation

@Souravrajvi0

Copy link
Copy Markdown
Contributor

Summary

Fixes #7205.

When loading a DiffusionGemma GGUF with explicit gpu_ids on a Vulkan llama.cpp build, LlamaCppBackend.load_model used to run Phase 1 (_kill_process()) before it could read the GGUF header and reject the unsupported combination. That tore down the active model and then returned 400.

This PR classifies diffusion GGUFs before Phase 1 teardown:

  • Local gguf_path: read the header via _gguf_path_is_diffusion before killing the server
  • HF remote: try a cached local GGUF via resolve_local_gguf_path first; download only when uncached (existing behavior)
  • Shared rejection message via _VULKAN_DIFFUSION_GPU_IDS_ERROR and _reject_vulkan_diffusion_gpu_ids_before_teardown()

Test plan

  • test_local_vulkan_diffusion_preflight_runs_before_teardown
  • test_local_vulkan_diffusion_rejection_keeps_active_server
  • Existing remote diffusion preflight tests still pass

Classify local GGUF paths (and cached HF downloads when available) for
diffusion before _kill_process() so unsupported gpu_ids requests return
400 without tearing down the active model. Fixes unslothai#7205.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c1b2427773

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 6441 to 6445
if _cached_gguf and Path(_cached_gguf).is_file():
self._reject_vulkan_diffusion_gpu_ids_before_teardown(
_cached_gguf,
model_identifier,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don't skip pre-teardown download for partial GGUF caches

When a Vulkan load with gpu_ids finds only a cached main/shard-1 GGUF, this branch just classifies that file and leaves _preflight_model_path as None; Phase 2 then calls _download_gguf only after _kill_process(). resolve_local_gguf_path() does not prove the variant is complete, so with a partial split cache, missing shard, disk-space error, or offline hub failure the existing server is torn down before the load fails. The preflight should either verify/reuse a complete cached load target or still run _download_gguf before Phase 1 for incomplete caches.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, and reproduced on the commit this was posted against (c1b2427). With resolve_local_gguf_path() returning a cached shard-1 file and _download_gguf raising (missing shard / ENOSPC / offline hub), the observed order was KILL -> DOWNLOAD, so the healthy server was gone before the load failed.

That cached-path shortcut was reverted in 5e06a84, so the hf_repo preflight now always runs _download_gguf before Phase 1. Re-running the same three failure modes on head gives DOWNLOAD only, with _kill_process never called. _download_gguf resolves the full split set (gguf_extra_shards / _cached_complete_candidate / split_needs_refetch), so completeness really is proven pre-teardown, and Phase 2 reuses _preflight_model_path.

Locked in with a behavioral regression test in c9867a4: it patches resolve_local_gguf_path to return an on-disk shard-1 and asserts the call order is exactly ['download']. It fails on c1b2427 with ['kill', 'download'] and passes on head.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: c9867a4653

ℹ️ 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

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: b0acba68bb

ℹ️ 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

Copy link
Copy Markdown
Member

The one red check here, connection (opencode), is not from this branch.

The job's own classifier says so: it failed with [guide drift] agent=opencode: invoke timed out after 1200s (headless-TTY hang -- the recipe likely needs a non-interactive/print flag), which the workflow raises only after preflight and install have both passed. On the same run connection (claude), (pi) and (hermes) all succeeded against the same served gemma-4-E4B, so the server and the API contract are fine. The hang is the third-party opencode CLI waiting on a TTY.

This branch touches two files, studio/backend/core/inference/llama_cpp.py and its test, and nothing in unsloth_cli/commands/start.py or the agent-connection path.

Separately, this PR was replicated onto a staging repo and run there across Ubuntu, macOS 14 and Windows: all three green, plus the full check set at 45 passed with 2 skipped.

@danielhanchen

Copy link
Copy Markdown
Member

Checked the platform matrix on this one, since a new hardware path must not disturb the old ones.

Every new branch is gated on is_vulkan_backend and gpu_ids, which makes the blast radius structural rather than something you have to trust the tests for:

NVIDIA AMD CPU only
Windows reachable reachable inert (no gpu_ids)
Linux reachable reachable inert
WSL reachable reachable inert
macOS inert (Metal, never a Vulkan build) inert inert

So CUDA, ROCm, Metal and CPU-only callers reach none of it, and the only behaviour change lands on the exact configuration the issue describes.

The one genuinely new statement is the local-path preflight. It is a character-for-character duplicate of the check that already sat further down (if not Path(gguf_path).is_file(): raise FileNotFoundError(f"GGUF file not found: {gguf_path}")), same exception, same message. Anything it rejects would have been rejected anyway; the difference is that it now happens before the healthy server is killed instead of after, which is the whole point. The cost is re-reading one GGUF header on the Vulkan-plus-gpu_ids local path, which is rare and cheap.

The red connection (opencode) check is not this PR. The job log says invoke timed out after 1200s (headless-TTY hang) and the workflow flags it as guide drift in a CLI recipe this PR does not touch; the same job passes on #7463 and #7386. 104 tests green locally.

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Jul 27, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Cross-platform staging run on this PR came back clean: 16 of 16 green across Ubuntu, macOS and Windows.

One job (Windows Unsloth UI CI) failed on the first attempt with exit 143 in its Stop second Unsloth teardown step, and passed on a straight re-run with no code change. I checked rather than assuming, because that job had passed its previous 14 runs on other branches including main, so "flaky" was not a supported claim at the time. Exit 143 is SIGTERM during a kill of the second Studio instance, the step is teardown-only, and this PR touches neither that workflow nor the shutdown path it exercises. Recording it here so the first-attempt red is not mistaken for a signal from this change.

@danielhanchen
danielhanchen merged commit 9eaf5c2 into unslothai:main Jul 27, 2026
44 checks passed
danielhanchen added a commit to InfoSage05/unsloth that referenced this pull request Jul 27, 2026
Resolves the overlap with two Vulkan changes that landed on main after this
branch last synced: unslothai#7415 (reject Vulkan diffusion gpu_ids before Phase 1
teardown) and unslothai#7476 (report Vulkan GPUs in system UI).

llama_cpp.py: take main's shared _VULKAN_DIFFUSION_GPU_IDS_ERROR constant and
its local-GGUF pre-teardown branch, which this branch did not have, and keep
this branch's gpu_ids_are_vulkan_ordinals qualification plus its CPU-only-build
pin rejection. The missing-file check stays under main's original gate so a bad
local path is still reported before the running server is torn down, while only
the diffusion rejection carries the ordinal qualification.

use-system.ts: fold this branch's gguf_devices field and its gpu_ids doc
comment into main's SystemGpuInfo interface, keeping main's inference_gpu.

test_gguf_load_cache_reuse.py: the _no_gguf_gpu_ids stub now returns the
(ids, are_vulkan_ordinals) tuple this branch's resolver returns.
danielhanchen added a commit that referenced this pull request Jul 27, 2026
… onto #7476) (#7498)

* Vulkan GPUs: real device names and selectable ordinals

Rebases the durable half of #7356 onto the inference_gpu transport #7476
landed on main. Those two PRs solve an overlapping problem and disagree on
the data model, so merging #7356 as-is would ship two parallel Vulkan
device concepts with different index semantics. This keeps main's transport
and adds what #7356 had that #7476 does not.

- _vulkan_probe.py emits a 5th column, ggml's device description, sanitized
  for the tab protocol and UTF-8 safe. Reader tolerates 4- or 5-column
  output so an older probe still parses.
- llama_cpp gains _run_vulkan_probe (shared parse) and
  vulkan_device_inventory (names + is_igpu + real totals).
- get_vulkan_inference_gpu_info reports the real name and an explicit
  is_igpu instead of "Vulkan<i>" and a total == 0 guess.
- index_kind becomes "vulkan", not "relative", and gpu_ids picks are
  supported on Vulkan builds once the probe enumerated ordinals. The XPU ban
  no longer applies to them: a Vulkan pick is a ggml ordinal, not a torch-xpu
  index, so it works on an Intel host too.
- Frontend picker reads the Vulkan inventory as the pickable set.

Memory deliberately still comes from _get_gpu_memory, not the inventory.
That path applies _apply_igpu_host_reserve_mib and zeroes a shared total;
budgeting an APU off its raw shared total would hand out the whole machine's
RAM with no OS headroom. Identity is joined onto it by ordinal, so a probe
failure degrades to Vulkan<i> names with the memory readings intact.

Dropped from #7356 as superseded: validate_vulkan_gpu_ids (main's
resolve_requested_gpu_ids already rejects duplicates and
_resolve_gguf_gpu_ids_for_request already probes for existence), the
gguf_devices transport, and the iGPU budget fallback in 7161989, which
main's aggregateGpuMemoryTotalGb handles better by counting a shared pool
once.

Also keeps #7356's removal of the late diffusion raise, so the graceful
gpu_ids drop stays reachable for a GGUF only classified as diffusion after
download. #7415's real guard, _reject_vulkan_diffusion_gpu_ids_before_
teardown, is untouched.

Verified on Windows + Strix Halo: backend Vulkan/GPU-selection suites at the
same 4 pre-existing failures as main, tests/studio 1671 passed with no new
failures, frontend typecheck clean. Hardware confirmation of the underlying
behavior is on #7356 from @Bebiv24 (RX 9070 XT + RX 480).

Co-authored-by: LeoBorcherding <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: LeoBorcherding <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Studio: diffusion GGUF + unsupported gpu_ids/memory_mode is rejected only after Phase 1 teardown

2 participants