Repository navigation
Studio: warn when a GPU model silently loaded on CPU - #6339
Conversation
There was a problem hiding this comment.
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.
| # 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", |
There was a problem hiding this comment.
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.
| # 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 "" |
There was a problem hiding this comment.
💡 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".
| if install_kind in _GPU_OFFLOAD_REQUIRED_KINDS: | ||
| log_handle.flush() | ||
| if server_log_shows_gpu_offload(read_full_log(log_path)) is False: |
There was a problem hiding this comment.
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 👍 / 👎.
| # 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") |
There was a problem hiding this comment.
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 👍 / 👎.
| saw_device_row = True | ||
| if match.group(1).lower().startswith(_GPU_DEVICE_PREFIXES): | ||
| return True |
There was a problem hiding this comment.
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 👍 / 👎.
| if attempts: | ||
| cpu_choice = published_asset_choice_for_kind(bundle, "linux-cpu") | ||
| if cpu_choice is not None: | ||
| attempts.append(cpu_choice) |
There was a problem hiding this comment.
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.
e55d528 to
2e7189e
Compare
There was a problem hiding this comment.
💡 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".
| if int(match.group(1)) > 0: | ||
| return True |
There was a problem hiding this comment.
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.
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Summary
llama-servercan 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_offloadkeyed only on the oldmodel buffer sizelines, which recent builds dropped, so it returnedNoneand the warning never showed.What this changes
This is log-only. It does not change install, GPU selection, or model-load behavior.
classify_gpu_offload_linesinstudio/backend/core/inference/llama_cpp.pywith three signals in priority order: the authoritativeoffloaded N/M layers to GPUcount, then GPUmodel buffer sizemarkers across CUDA / ROCm / HIP / Metal / Vulkan / OpenCL / SYCL / MUSA / CANN (host-pinned_Hostbuffers excluded, and authoritative when present), then thedevice_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.offloaded N/M layers to GPUtwice (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_offloadkeeps 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: extendTestClassifyGpuOffloadfor the offloaded-count priority (including0/33then33/33), the_Hostexclusion, every backend marker, thedevice_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.