Skip to content

Studio: warn when a GPU model silently loaded on CPU - #6339

Merged
danielhanchen merged 2 commits into
mainfrom
fix/studio-detect-silent-cpu-offload
Jun 16, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix/studio-detect-silent-cpu-offload

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Summary

llama-server can serve HTTP 200 while running a model entirely on CPU when its GPU backend fails to initialize (a missing CUDA runtime DLL, a broken HIP load, etc). Studio then runs a "GPU" GGUF on CPU without telling anyone, which is the silent slowdown behind #5807, #5106, and #5830.

Studio already logs a warning for this (the #5106 path), but it stopped firing on current llama.cpp: _classify_gpu_offload keyed only on the old model buffer size lines, which recent builds dropped, so it returned None and the warning never showed.

What this changes

This is log-only. It does not change install, GPU selection, or model-load behavior.

  • New classify_gpu_offload_lines in studio/backend/core/inference/llama_cpp.py with three signals in priority order: the authoritative offloaded N/M layers to GPU count, then GPU model buffer size markers across CUDA / ROCm / HIP / Metal / Vulkan / OpenCL / SYCL / MUSA / CANN (host-pinned _Host buffers excluded, and authoritative when present), then the device_info: table. The device table is disconfirm-only: it lists available devices, not where the model loaded, so a visible GPU device never overrides a definite CPU-only buffer result.
  • The count is keyed on the model with the most layers. With MTP/speculative decoding llama-server logs offloaded N/M layers to GPU twice (main model and draft model), so deciding on the largest model stops a small drafter that fits on GPU from masking a main model running on CPU (the Qwen3.6-27B-MTP case).
  • _classify_gpu_offload keeps its intent guards and delegates to the shared classifier. The existing warning block is unchanged; it simply fires again on current llama.cpp.

Cost

The classifier runs once after model load, over the already-captured startup log lines (no new subprocess, no extra probe). It only logs. No measurable overhead and no behavior change.

Tests

studio/backend/tests/test_llama_cpp_context_fit.py: extend TestClassifyGpuOffload for the offloaded-count priority (including 0/33 then 33/33), the _Host exclusion, every backend marker, the device_info: disconfirm-only behavior (a GPU row alone is inconclusive; CPU-only buffers win over a GPU device row), and the tri-state guards.

Relates to #5807, #5106, #5830.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces robust GPU-offload detection logic during model initialization and installation validation. It adds log classification helpers to parse llama-server startup logs for GPU offload markers, offloaded layer counts, and device info. If an intended GPU bundle fails to offload and runs entirely on CPU, a GpuOffloadFailure is raised, prompting the resolver to fall back to a prebuilt CPU binary as a last resort. Comprehensive unit tests are added to verify the log parsing, validation gates, and fallback mechanisms. The reviewer suggested optimizing the log reading utility to read only up to the character limit directly from the file stream instead of loading the entire file into memory, preventing potential OOM issues with extremely large log files.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread studio/install_llama_prebuilt.py Outdated
Comment on lines +5617 to +5623
# Install kinds that ship GPU code (so validation launches with --n-gpu-layers).
_GPU_INSTALL_KINDS = {
"linux-cuda",
"linux-arm64-cuda",
"linux-rocm",
"windows-cuda",
"windows-hip",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Reading the entire log file into memory using read_text() and then slicing it with [:max_chars] can be highly inefficient and potentially lead to Out Of Memory (OOM) issues if the log file grows extremely large.

Instead, consider opening the file and reading only up to max_chars directly from the stream.

Suggested change
# Install kinds that ship GPU code (so validation launches with --n-gpu-layers).
_GPU_INSTALL_KINDS = {
"linux-cuda",
"linux-arm64-cuda",
"linux-rocm",
"windows-cuda",
"windows-hip",
def read_full_log(log_path: Path, *, max_chars: int = 1_000_000) -> str:
"""Full startup log (capped); offload markers appear during model load, so
the 60-line read_log_excerpt tail can miss them."""
try:
with log_path.open("r", encoding="utf-8", errors="replace") as f:
return f.read(max_chars)
except OSError:
return ""

@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: d4a826d4da

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

Comment thread studio/install_llama_prebuilt.py Outdated
Comment on lines +5823 to +5825
if install_kind in _GPU_OFFLOAD_REQUIRED_KINDS:
log_handle.flush()
if server_log_shows_gpu_offload(read_full_log(log_path)) is False:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Run the GPU-offload gate for approved GPU bundles

This rejection only happens inside validate_server, but normal published CUDA/ROCm bundles have expected_sha256 set by apply_approved_hashes, and validate_prebuilt_choice skips validate_server unless choice.expected_sha256 is None or _RUN_STAGED_PREBUILT_VALIDATION (currently false). In the common approved-bundle install path, a GPU bundle that serves 200 while loading fully on CPU will still be accepted and will never advance to the CPU fallback this change adds; the offload probe needs to run for intended-GPU kinds even when the archive hash is approved.

Useful? React with 👍 / 👎.

Comment thread studio/install_llama_prebuilt.py Outdated
# build. Only when a CUDA attempt exists, so a partial release (no CUDA)
# still walks back to an older release rather than shipping CPU here.
if attempts:
cpu_choice = published_asset_choice_for_kind(bundle, "linux-cpu")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Choose the arm64 CPU fallback on arm64 CUDA hosts

On Linux arm64 NVIDIA hosts, linux_cuda_choice_from_release selects linux-arm64-cuda attempts, but this new fallback always appends the linux-cpu asset. If the arm64 CUDA bundle fails the offload check and the release also contains the x64 CPU bundle, the attempt loop can advance to and record that wrong-architecture CPU prebuilt, leaving unusable binaries on DGX Spark/Grace Hopper instead of using linux-arm64 or source-building.

Useful? React with 👍 / 👎.

Comment on lines +153 to +155
saw_device_row = True
if match.group(1).lower().startswith(_GPU_DEVICE_PREFIXES):
return True

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Don't let device_info override CPU-only buffers

When a startup log contains only CPU model buffer size lines plus a GPU row in device_info (llama.cpp prints that device inventory before model tensor allocation whenever a GPU backend is visible), this branch returns True even though the model-buffer signal already showed no GPU allocation. That means the exact silent-CPU case this classifier is trying to catch can be treated as healthy on both the runtime warning path and the installer copy; the device table should not override a definite CPU-only buffer result.

Useful? React with 👍 / 👎.

Comment thread studio/install_llama_prebuilt.py Outdated
Comment on lines +6089 to +6092
if attempts:
cpu_choice = published_asset_choice_for_kind(bundle, "linux-cpu")
if cpu_choice is not None:
attempts.append(cpu_choice)

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 Only use the CPU fallback for offload failures

Because this CPU asset is appended to the normal attempt list, validate_prebuilt_attempts will advance to it after any PrebuiltFallback from the CUDA candidate, not just GpuOffloadFailure. On a NVIDIA Linux install where the newest CUDA archive fails for an ordinary validation/extraction/runtime-library issue, this now installs a CPU binary from that release instead of letting the release loop try an older CUDA release that could still provide GPU acceleration.

Useful? React with 👍 / 👎.

llama-server can serve HTTP 200 while running a model entirely on CPU when its GPU backend fails to init, so Studio could run a GGUF on CPU without saying so (#5807 / #5106 / #5830). The silent-CPU warning already exists but stopped firing on current llama.cpp because _classify_gpu_offload keyed only on the dropped 'model buffer size' lines. Add a shared classify_gpu_offload_lines (offloaded N/M counts, GPU model-buffer markers excluding _Host, device_info disconfirm-only) and delegate to it so the warning fires again. Log-only: no install or load behavior changes.

Pure classification of already-captured startup log lines, run once after load; no new subprocess, no slowdown.
@danielhanchen
danielhanchen force-pushed the fix/studio-detect-silent-cpu-offload branch from e55d528 to 2e7189e Compare June 16, 2026 05:26
@danielhanchen danielhanchen changed the title Studio: detect silent CPU offload (runtime warning + install-time reject) Studio: warn when a GPU model silently loaded on CPU Jun 16, 2026

@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: 2e7189ec7f

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

Comment on lines +124 to +125
if int(match.group(1)) > 0:
return True

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 treat draft offload as proof the main model used GPU

When MTP uses a separate draft model, llama-server can emit offload counts for both models; this code comment/test already assumes a draft count may appear before the main model's count. On a GPU with enough VRAM for the small drafter but not the primary GGUF, a non-zero draft offloaded N/M line will return True here before a later offloaded 0/... for the main model is examined, so _gpu_offload_active suppresses the CPU-load warning even though the primary model is running on CPU.

Useful? React with 👍 / 👎.

With MTP/speculative decoding llama-server logs 'offloaded N/M layers to GPU' twice: once for the main model and once for the small draft model. The old scan returned True on any non-zero count, so a drafter that fits on GPU while the main GGUF runs on CPU suppressed the warning (the Qwen3.6-27B-MTP case). Decide on the line with the most layers (the main model) instead, so a drafter cannot mask a main model on CPU.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 0541277f87

ℹ️ 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 e73a89f into main Jun 16, 2026
28 of 32 checks passed
@danielhanchen
danielhanchen deleted the fix/studio-detect-silent-cpu-offload branch June 16, 2026 06:06
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.

1 participant