Repository navigation
Studio: retry on the GPU with --fit off when llama.cpp's fit step crashes - #16421
debojyoti-dev wants to merge 15 commits into
Conversation
…shes On an RX 5700 XT with the auto-selected Vulkan build, llama-server dies with 0xC0000005 while llama.cpp's fit step is still querying device memory, before any weights load. The existing --fit off retry only runs when Unsloth placed the model itself, so a launch that handed placement to --fit on went straight to the CPU fallback. When a fitter Unsloth turned on is the last thing the child logged before crashing, retry once with --fit off, pinning -c to the --fit-ctx floor when the argv names no context so the retry does not jump to the model's native window. A user's own -fit/--fit or LLAMA_ARG_FIT is left alone, and a retry that also crashes still reaches the CPU fallback. Fixes unslothai#16395
|
This PR adds a longer log message and new conditions ahead of that retry, so the guard now sits outside the window. The fix is either to keep the capability-crash skip next to the retry, or to update the test to find the retry's actual The other reds here (Source lint and workflow-trigger lint risky loader, |
… their copy (#16431) ## Summary `Chat UI Tests (extra)` fails on PRs based on current main (#16418, #16421, #16413) in the chat width driver: ``` [chat-width] FAIL in step "measure the 'Standard' preset across 7 viewports" after 30.7s: TimeoutError: Locator.click: Timeout 30000ms exceeded. - waiting for get_by_role("option", name="Standard", exact=True) ``` #16408 (`8da4ba2f1c`, customizable new-chat greeting) renamed the chat width option label from "Standard" to "Default" (`settings.appearance.custom.chatWidth.standard`) in every locale. The product change is intended. `tests/studio/playwright_chat_width.py` clicked the option by its English text, so it waited for an option that no longer exists. ## Change - **`playwright_chat_width.py`:** the driver picks each preset by its position in the open listbox, not by its copy. The component lists the values as `["standard", "wide", "full"]`. The driver's own names for the presets (`CHAT_WIDTH_PRESETS`) are unchanged, so the measurements and messages read the same. I did not switch it to the `_en_catalog` reader, because `test_en_catalog.py` pins every catalog-reading driver to the composer workflow, and this one runs in `studio-ui-smoke.yml`. - **New `tests/studio/test_chat_width_driver_presets.py`:** checks that `appearance-custom-controls.tsx` still maps over `["standard", "wide", "full"]` in that order, and that the driver has one preset per option. A reorder or a new option then fails here instead of measuring the wrong preset. ## Testing - The new test, `test_en_catalog.py` and `test_playwright_suites_run_in_ci.py`: 54 passed. - Sabotage: with the component's order swapped to `["wide", "standard", "full"]`, the new test fails. - The driver itself needs a live Studio. It runs in this PR's own `Chat UI Tests (extra)` job, and I will only merge once that is green. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
|
Review record for #16421, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#691. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
DriverVersion Name llama-1793676444-cpu-port-50058-try0.log llama-1793676441-noflash-port-50058-try1.log llama-1793676437-noflash-port-50058-try0.log llama-1793676433-port-50058-try1.log llama-1793676429-port-50058-try0.log |
…retry reaches --fit off [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 60806997c5
ℹ️ 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".
| run_cmd = [ | ||
| *(self._without_flags(run_cmd, {"-fit", "--fit"}) or run_cmd), | ||
| "--fit", | ||
| "off", |
There was a problem hiding this comment.
Remove retry-added locks before the new fit-off relaunch
When keep_resident=True, no_ram_reserve=False, and the initial launch is fully GPU-offloaded, _mem_managed is empty, but the existing fit-on recovery can subsequently append _retry_lock. In the supported fit-off → fit-on → no-flash fit-on → no-flash fit-off recovery sequence, this new rung then marks mlock inapplicable while the cleanup below only strips _mem_managed, leaving the retry-added lock on the final child. That pins a complete host copy of an otherwise GPU-resident model and can defeat recovery on RAM-constrained hosts. Track and remove the managed lock actually present on run_cmd, including locks added by earlier recovery rungs.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 61953c9: page-locks added by earlier recovery rungs are tracked and stripped by the fit-off rung.
| and not _hip_rocr_mismatch | ||
| and self._fit_step_retry_eligible(run_cmd, extra_args, env) | ||
| ) | ||
| if _fit_step_crashed or ( |
There was a problem hiding this comment.
Restore residency when the no-flash retry re-enables fitting
For a managed fit-on load with keep_resident=True and no_ram_reserve=False, this newly reachable branch strips the page lock and sets _mem_host_resident and _memory_mlock_applicable false. If the fit-off attempt also crashes, _enable_managed_fit_for_no_flash() re-enables fitting on that stripped argv without reinstating the lock or bookkeeping. A successful no-flash fit-on launch can therefore place weights in host RAM without the requested residency guarantee, and later settings checks incorrectly consider the missing lock satisfied. Reapply the host-memory policy whenever a subsequent recovery switches the fitter back on.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 61953c9: the no-flash fit-on relaunch re-arms the page-lock and its bookkeeping when the fitter is turned back on.
…m when no-flash re-enables the fitter [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 61953c922a
ℹ️ 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".
| rearmed = _rearm_resident_lock( | ||
| flipped, "--flash-attn off retry; it runs the fitter again" | ||
| ) |
There was a problem hiding this comment.
Drop managed DirectIO when no-flash recovery re-enables fitting
On Windows with no_ram_reserve=True, a managed fit-on crash can now reach the fit-off rung and append --load-mode dio. If that child also crashes, this no-flash path re-enables fitting but leaves managed DIO and its applicability flag intact. The upstream help reproduced in studio/backend/tests/test_load_mode_caps_unknown.py:199 describes dio as “use DirectIO if available”; _drop_managed_dio() documents that it buffers CPU layers and requires confirmed full offload. A fitter that places weights in host RAM can therefore exhaust RAM where file-backed paging would allow recovery. Strip managed DIO and refresh the memory bookkeeping when re-enabling fitting, matching the ordinary fit-on recovery.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5614c88: the no-flash fit-on relaunch now drops Unsloth's managed DirectIO (record kept for the CPU replay), with a regression test.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5614c8859b
ℹ️ 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".
| flipped = self._drop_managed_dio( | ||
| flipped, | ||
| "the --flash-attn off retry runs the fitter again", | ||
| clear_record = False, |
There was a problem hiding this comment.
Restore managed DirectIO on subsequent fit-off retries
On Windows with no_ram_reserve=True and confirmed discrete-GPU offload, the fit-on → fit-off → no-flash fit-on → no-flash fit-off recovery sequence loses managed DirectIO on the final child. This call correctly strips --load-mode dio for the no-flash fit-on attempt, but the preceding fit-off retry already set _mem_host_resident=False, and _rearm_resident_lock() leaves it false under No RAM Reserve. The subsequent fit-off retry therefore skips its DIO policy block; the retained _memory_dio_flags would also suppress reinsertion. The captured upstream help describes dio as “use DirectIO if available” (studio/backend/tests/test_load_mode_caps_unknown.py:199); without it, Windows retains the full host mapping despite the no-reserve setting. Re-evaluate managed DIO against the actual retry argv whenever fitting is disabled, independently of the host-residency transition.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing: the final child still loads and runs; without DirectIO it keeps a reclaimable mmap page cache, which costs no correctness and needs four consecutive startup crashes under No RAM Reserve to reach.
…al extra (#17687) ## Summary `Core (HF=latest + TRL=latest)` fails on every PR since TRL 1.18.0 was released today (for example on the staging runs for #17521, #17534 and #16421): ``` FAILED tests/_trl_trainer_discovery_shim.py::test_unsloth_patches_experimental_trainers_via_thin_wrappers AssertionError: experimental *Trainer classes declared in source but not importable: [('async_grpo', 'HarnessAsyncGRPOTrainer')] ``` TRL 1.18 added `trl/experimental/async_grpo/openenv_harness.py`, which defines `HarnessAsyncGRPOTrainer` and imports the optional `openenv` package at module level. The CI job does not install `openenv`, so that one submodule cannot be imported. The inline test (in `consolidated-tests-ci.yml`) finds every `class *Trainer` in `trl.experimental.*` by regex, walks the package's submodules to locate each one, and swallows submodule import errors. So the class is reported as "declared in source but not importable", as if TRL's public surface had drifted. TRL is right, and Unsloth does not patch this trainer. The test already skips a whole experimental package whose `__init__` needs an optional dependency (`IMPORT-SKIP`), but it had no equivalent for a single submodule. Reproduced with TRL 1.18.0 and transformers 5.23.0: 1 failed, 4 passed. ## Change In the submodule walk, a `ModuleNotFoundError` for a non-`trl` module counts as an optional-extra skip, but only when the submodule that failed is the file declaring the class. It is logged as an `IMPORT-SKIP` line naming the module and the missing package. Every other case still lands in `missing`: - a class that is not defined anywhere; - a submodule failing for another reason; - a missing `trl.*` module. ## Testing Running the inline test extracted from the workflow: - TRL 1.18.0: 5 passed, with `IMPORT-SKIP trl.experimental.async_grpo.openenv_harness.HarnessAsyncGRPOTrainer: needs the optional openenv`. - TRL 1.17.1: 5 passed, unchanged. - Sabotage: a `trl/experimental/async_grpo/zz_ghost.py` that raises `RuntimeError` before declaring `GhostTrainer` still fails with `[('async_grpo', 'GhostTrainer')]`. - The workflow YAML parses, and the workflow-content tests (`test_cache_budget_discipline.py`, `test_pip_cache_naming.py`, `test_zoo_suite_parallel_isolation.py`, `test_trl_cap_sites.py`): 295 passed, 3 skipped.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5614c8859b
ℹ️ 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 not _mem_should_mlock or _mem_host_resident: | ||
| return run |
There was a problem hiding this comment.
Refresh residency applicability even when locking is disabled
On a discrete GPU, with both memory toggles initially off, a managed fit-on → fit-off → no-flash fit-on recovery leaves _memory_mlock_applicable=False: the fit-off rung clears it, and this guard skips restoring it because no lock was requested at launch. If the successful no-flash fitter leaves weights in host RAM, turning Keep Resident on afterward is incorrectly treated as already satisfied by memory_state_satisfies_settings(). Consequently, both the settings reload hint and duplicate-load comparator skip the reload needed to apply residency. Update the host-residency/applicability bookkeeping whenever fitting is re-enabled, independently of whether the current settings require adding a lock.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing: with Keep Resident off nothing is emitted or owed, and the existing --fit on rung uses the same gate; the only effect is a reload prompt after toggling the setting post three startup crashes.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 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". |
Studio can fall back to CPU when llama.cpp crashes during its own memory-fitting step, even though loading without fitting may succeed. This adds one GPU retry with fitting disabled before the existing recovery continues.
The retry requires a startup failure whose last child log comes from the fitting step. It preserves explicit user fit and context settings, excludes capability and ROCm-library failures, and retains CPU fallback if the retry fails. Managed Auto context, including Studio's internally emitted
-c 0, is bounded to the fit-context floor or 8192 instead of the model's native window. Separate KV caches retain that floor per serving slot, and retry commands normalize the managed fit flag so later flash-attention recovery can re-enable fitting.Fixes #16395
Validation:
-c 0on retry. The corrected Auto-context integration test fails on that version and passes with the fix. Two further recovery interactions were corrected after review: per-slot context sizing and conflicting managed fit flags.The reporter's Windows 10 RX 5700 XT and driver have not been tested. The crash/recovery simulations establish the launcher sequence; they do not establish that the driver can allocate and decode after fitting is disabled. The new tests also reproduce the previously broken flash-attention recovery and per-slot context allocation; they fail before the corrections and pass afterward.