Skip to content

Studio: keep waiting on a llama-server load that is still reading its model - #11055

Merged
danielhanchen merged 2 commits into
unslothai:mainfrom
oobabooga:worktree-llama-health-timeout
Sep 16, 2026
Merged

danielhanchen merged 2 commits into
unslothai:mainfrom
oobabooga:worktree-llama-health-timeout

Conversation

@oobabooga

Copy link
Copy Markdown
Member

Large GGUF models can fail to load in Studio on slow hardware, even though nothing is wrong. Studio gives llama-server 10 minutes to become ready and then kills it, so any load that needs longer always fails. This was reported on Reddit: GLM-5.3 UD-Q4_K_XL (467 GB) needs about 25 minutes to load on the reporter's machine.

With this PR, Studio keeps waiting as long as llama-server is visibly still working on the load. It gives up only after 10 minutes with no sign of activity.

What changes for users

Situation Before After
Load takes longer than 10 minutes but is progressing Fails at 10 minutes Keeps waiting while activity remains above the thresholds
Load stops making progress (for example, storage hangs) Fails at 10 minutes Fails 10 minutes after activity stops
Load crashes, or the user cancels Stops immediately Unchanged

The error for a stalled load now says llama-server "stopped making progress" instead of "never became healthy".

How Studio tells that a load is still working

llama-server prints nothing while it reads model weights. In one test it was silent for 102 seconds. Studio therefore checks the llama-server process itself every 5 seconds and counts the load as active if any of these grow past a small threshold:

  • Memory use, at least 1 MiB above its previous peak.
  • Bytes reported by the process I/O counters, at least 1 MiB.
  • Page faults, at least 64. These count the OS loading pieces of a memory-mapped file on demand. They can reveal memory-mapped loading on a machine short on RAM, where memory use stops growing and no ordinary reads happen.
  • CPU use, above 5% of one core.

The thresholds are set above the background activity of an idle llama-server answering Studio's status checks. That was 0 to 1 page faults per 5 seconds, and at most 33 right after a load finished. Child processes are included, because the diffusion model runner does its loading in a child process. If the counters cannot be read, Studio falls back to the old fixed 10-minute limit.

Results

In Studio. Loading a 5 GB model from storage throttled to 6.5 MB/s, which takes about 13 minutes:

Run Result
main Failed at 10 minutes
this PR Loaded after 13 minutes, and chat worked
this PR, storage frozen 3 minutes in Failed 10 minutes after the freeze

This run used an earlier version of the change that did not yet count page faults or child processes.

Low RAM. The same model loaded on CPU from 20 MB/s storage with memory capped at 3 GB, below the model's size. The timeout was shortened to 60 seconds to keep the test quick.

Run Result
Without page faults counted Timed out 60 seconds after memory hit the cap, while the model was still loading
this PR Kept waiting while the model loaded, until the OS killed llama-server for exceeding the 3 GB cap
this PR, storage frozen mid-load Timed out 60 seconds after the freeze

Verification

  • 9 new tests in test_llama_cpp_wait_for_health.py, most using real child processes. They cover slow loads, stalled and idle processes, work done by a child process, a memory-mapped load visible only through page faults, unreadable counters, and status-check noise. All 9 fail on main and pass on Linux, macOS 14.5 (M1 Mac mini), and Windows 11.
  • Linux: 4,263 passed and 5 skipped across the llama, GGUF, GPU and related suites.
  • ruff check and scripts/run_ruff_format.py pass.

Limitations

  • Activity is not the same as progress. A load that keeps working without ever finishing, for example one swapping to disk continuously, now waits until the user cancels. Cancel, shutdown and crash detection still work as before.
  • A load whose activity stays below the thresholds, or whose counters cannot be read, still times out after 10 minutes.
  • The slow-load tests used throttled storage and a 5 GB model, not a 400 GB model. On macOS and Windows I measured the counters and ran the tests, but did not run a slow Studio load. No DiffusionGemma load was tested.
  • For reviewers: the 10-minute limit is now _HEALTH_STALL_TIMEOUT_S in llama_cpp.py, shared by all three call sites. Studio: add per-model custom llama.cpp INI configuration #10783 adds a new _wait_for_health(timeout = 600.0, ...) call. If it merges after this PR, that call should use the constant.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed this hits the fixed 600s wait in studio/backend/core/inference/llama_cpp.py, where a load still reading weights gets killed at ten minutes, and the fallback to the fixed deadline when counters are unreadable looks right. Will get this reviewed.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 16, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 16, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Went through this one carefully, including a full before/after simulation. The change is correct and I could not find a defect in it. Summary of what I ran and the two things worth acting on.

The differential

One thing to flag first: the 9 new tests are a void differential as written. They do all fail on main, but every one of them fails with AttributeError out of monkeypatch.setattr against _STARTUP_PROGRESS_SAMPLE_S, _STARTUP_PROGRESS_MIN_CPU_FRACTION, _startup_work_sample or _made_startup_progress, none of which exist before this PR. They never reach a behavioural assertion on the base arm, so they do not demonstrate the defect. They are good regression tests, they just do not prove the thing the description claims they prove.

So I wrote one that runs unmodified on both arms, touching only _wait_for_health and leaving the sample interval at its default 5.0s:

Simulation main this PR
Load still visibly working at the deadline fails, abandoned at 7.1s passes, healthy at 9.1s
Load that stops working fails at 7.1s fails at 12.1s, one timeout after the last work

That reproduces the reported defect and shows the fix, and it confirms the stall guardrail still terminates. If you want it, it is two functions and no new symbols, and it would survive a future refactor of the internals that the current 9 would not.

Cross-platform, both arms

Ran the suite on staging across Linux, Apple Silicon macOS and Windows, with a base arm on each (production diff reverse applied, your test files kept):

OS main this PR the 9 stall tests
ubuntu-latest 9 failed 0 failed, 311 passed fail to pass
macos-15 10 failed 1 failed, 310 passed fail to pass
windows-latest 14 failed 5 failed, 306 passed fail to pass

Every remaining head failure is red on the base arm too, so the head failure set is a strict subset of main. The macOS one is test_a_started_shutdown_refuses_to_spawn, pre-existing. The 5 Windows ones are FileNotFoundError [WinError 2] from spawning a real llama-server binary hosted runners do not ship, and they fail before _wait_for_health is reached. This does give real hardware coverage of the macOS pfaults and Windows num_page_faults branches.

Locally, studio/backend/tests/test_llama*.py (56 files) gives 70 failed / 3026 passed / 9 skipped on both main and this branch, with byte-identical failure sets. Zero regressions.

Checks that came back clean

  • /proc/<pid>/stat [7] and [9] really are minflt and majflt, verified against resource.getrusage, and rsplit(b")", 1) correctly survives a comm containing parentheses and spaces.
  • The "health check timed out" substring contract at llama_cpp.py:19080 still matches the reworded marker, and no other _stdout_lines matcher collides with the new wording. embed_llama_server.py:935 has its own separate message and is unaffected.
  • ast diff of _wait_for_health: 14 predicates on main, 13 unchanged, 5 added, 1 removed, where the removal is just time.monotonic() < deadline rewritten as the walrus form. Every predicate governing shutdown, cancel, process is None, poll() and the 200 response is untouched.
  • Enumerated _made_startup_progress over its full input space, 720 cells: 720 match the documented rule, 0 violations. The new block shortens the deadline in 0 of 720 cells, so a load that goes healthy before the deadline takes the same path it always did.
  • With psutil absent entirely it returns None and falls back to the fixed deadline, which is what the Windows runner actually exercised. pid of None, a Mock, 0 or -1 all return None.
  • Symbol audit: all 8 new names are private to llama_cpp.py and the tests, with zero readers in studio/frontend, desktop, docs, unsloth or unsloth_zoo.

Two things worth acting on

1. The frontend still hardcodes the old 600s. CLI_LOAD_POLL_MAX_MS in studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts:244 and CLI_LOAD_ADOPT_MAX_MS in studio/frontend/src/features/chat/api/chat-adapter.ts:2753 are both 600_000, and they were tuned to the bound this PR removes. Neither cancels the backend load, so the 25 minute case still completes: waitForServerModel just returns, and adoptInFlightServerLoad shows "A model is still loading". So not a blocker, but on the exact scenario this PR is fixing, a CLI started load stops being adopted at ten minutes while it is still loading. Worth a follow up.

2. Sampling cost is higher than it looks. Measured on a host with 3887 processes, 5 reps of 200 calls:

Call Median
_startup_work_sample 38.9 ms
of which children(recursive=True) 35.3 ms
of which the actual counter reads 35 us

Almost all of it is children(recursive=True) walking the entire process table, so it scales with the host's process count rather than with the model or the llama tree. At the 5s interval that is 0.78% of one core during a load, and a quieter desktop would see roughly a tenth of it, so it is not a blocker. But llama-server has no children and the diffusion shim spawns exactly one, before uvicorn starts, so a non-recursive walk would cover both call sites at a fraction of the cost. Also worth noting every load now pays one sample before its first probe, including one that is healthy immediately.

On the acknowledged no-absolute-cap behaviour: I agree it is the right trade, and it is genuinely bounded in practice because unload_model() sets _cancel_event before it takes _lock and the wait polls cancellation every interval, so the user can always cancel. No HTTP route takes this backend's _lock, so status stays responsive.

What I could not prove

No 400 GB model and no real 25 minute load, so the GLM-5.3 report is verified at mechanism level at 7 second scale, not end to end. No DiffusionGemma load, which is the one path that spawns a child during the wait, so child accounting rests on synthetic descendants. macOS 14.5 and Windows 11 specifically were not tested, macos-15 and windows-latest were. And the 5 Windows failures are pre-existing but stay untested on that OS because the runner has no llama-server binary.

Happy with this once you have had a look at the two items above. The #10783 note about the new _wait_for_health(timeout = 600.0) call site is right, and whichever lands second should pick up the constant.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-16T08:06:48.652960Z 7d7d0e7 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.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 16, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 7d7d0e7ca3

ℹ️ 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 98f15da into unslothai:main Sep 16, 2026
58 of 68 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 3, 2026
…nslothai#16476)

The mmap startup-progress test depends on a child process generating enough real page faults inside a 1.5-second stall window before health becomes ready at 2.5 seconds. It failed in the Python 3.13 CPU job even though the same test passed locally on both base and the auth branch. The exact remote scheduling or page-cache cause is unproven; a wall-clock resource dependency makes this an unreliable test of the progress policy.

The reviewed unslothai#16471 spacing dependency is already merged. The remaining changes are confined to tests.

Drive the production startup sampler and health wait with a controlled clock and process counters. CPU time, resident memory and read-byte counters stay flat. Advancing faults keep the wait alive beyond its original deadline; fixed faults reach the original stall timeout. A separate parser check covers the platform counter fields and Linux stat parsing, including a process name containing a closing parenthesis.

The health-test fix changes no production startup code, stall budget or polling interval. The test does not sleep, skip the failing case or relax its negative assertion. Fake process IDs are outside the valid host PID range and all process access is controlled.

The final validation pass also corrects the installer progress fixture to model successful uv bootstrap. Forcing bootstrap failure could instead hit the valid torch-freeze guard before reaching the progress assertion on newer torch installations. All 16 progress checks now pass without changing installer behavior or weakening assertions. Current-main integration with this health change passes 896 checks, with two existing platform skips. That integration also verifies the upstream CI fixture fixes from unslothai#16530 through unslothai#16533.

The rewrite also removes the now-unused `os` import. The existing import-safety check correctly rejected the preceding head; the same command passes after this one-line cleanup. All 101 local health/font checks pass. Refreshed Linux, macOS and Windows staging explicitly includes that required import-safety gate. The raw logs confirm that the gate runs and passes on all three platforms.

The health-wait behavior and original test came from unslothai#11055, with later timing adjustments in unslothai#11284 and unslothai#12065. The complete health-wait test file passes 89 tests. This hardens the test contract without claiming a production mmap failure was reproduced or that every earlier CI timeout has the same cause.

Disabling production fault accounting makes the new positive case fail while the stalled case still passes. Three panel reviews and three independent focused reviews found no actionable defect. Platform counter formats are simulated on Linux; removing the worker means this case no longer covers actual native mmap page-ins. Other real-process startup tests remain.

The paired Studio switchboard completes auth, Settings and route crawling with functional `NO_REGRESSION`: 38 matching steps and one Hub visual difference. All 39 functional captures succeed on both arms. The Hub benchmark-popover comparison retains a visual/mask difference on confirmation, so exact visual parity for that capture is not claimed. The health-test change itself has no production UI effect. The included unslothai#16471 dependency changes Settings spacing and uses its existing before/after evidence below.

Current-head staging passes 117 Python checks (89 health, 12 font-contract and 16 installer progress checks), 42 Node spacing/control checks and the required import-safety gate on each of [Linux](https://github.com/Imagineer99/unsloth/actions/runs/41645022400), [Apple Silicon macOS](https://github.com/Imagineer99/unsloth/actions/runs/41645022445) and [Windows](https://github.com/Imagineer99/unsloth/actions/runs/41645022404), with zero failures or skips. Raw logs and exact source-head ancestry were checked. The current-head switchboard reports functional `NO_REGRESSION` across auth, all 19 Settings steps, model picker and route crawling. The retained Hub/data-recipes comparisons include DOM/mask differences with zero changed pixels; exact visual parity is not claimed for those captures.

The current head also carries unslothai#16471's rich-paste badge correction for the font-contract CI regression introduced by unslothai#16298. Both Settings components are byte-identical to the parent. Local validation passes 101 Python checks and 42 Node checks. Refreshed platform checks include the font contract as well as the unchanged health-policy checks.

The shared spacing dependency below is the exact unslothai#16471 change; this comparison validates that dependency.

![Shared Settings spacing dependency before and after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16471/pr16471_before_after-a78db41ffd5e.png)

The inherited rich-paste badge correction is also byte-identical to unslothai#16471. At the enlarged font setting it scales from the previous fixed 10 px to 15 px, with the feature and switch retained:

![Shared rich-paste font-scaling dependency before and after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16471/pr16471_before_after-3e473cadeed6.png)
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