ADFA-1798 | Add proactive memory warning for custom model loading - #63
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
8501e64 to
17a4173
Compare
Code reviewFound 1 issue:
🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
17a4173 to
3d873f6
Compare
Code reviewThe overflow finding from the previous review is fully addressed by the ceilings and the saturating Found 2 issues:
🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Selecting a .gguf now runs a pre-flight check before the path is persisted, which is what makes ai-core load it. The model's size and its declared shape are weighed against free RAM; if it looks too large the user is asked whether to go ahead, with Cancel as the default and the figures behind the judgement on screen. Declining leaves the previously selected model untouched. The check fails open throughout: an unreadable size, header or memory reading means no warning rather than a wrong one. - ModelMemoryEstimator splits mmap'd weights from the KV cache and compute buffers, sized from the model's own shape when the header provides it. - ModelMemoryGate decides Safe / Risky(TIGHT|INSUFFICIENT) / Unknown. - GgufHeaderReader reads only the metadata block, bounded by a byte budget, an entry cap and an array cap, and attributes shape keys to their own architecture so a multimodal file's clip.* values stay out. - UserConfirmation lets the load coroutine await the user's answer, so the flow stays one readable sequence across a rotation. ADFA-1798
3505241 to
3c1b4de
Compare
Description
This PR introduces a "pre-flight" memory check to prevent application crashes caused by loading oversized custom
.ggufmodels into memory. Before attempting to load a selected model, the application now reads the file's GGUF header to estimate its required footprint (weights plus KV cache and compute buffers) and compares it against the device's currently available RAM.If the model is deemed too large and poses a crash risk, a non-blocking warning dialog alerts the user. The dialog provides a clear explanation of the memory shortfall and offers two choices: "Cancel" (aborting the load safely, which is the default) or "Proceed anyway" (empowering power users to attempt the load if they plan to free up RAM). This proactively enhances app stability and builds user trust.
Details
GgufHeaderReaderto parse metadata blocks andModelMemoryEstimatorto calculate load and runtime byte requirements.DeviceMemoryinterface andSystemDeviceMemoryimplementation to read real-time available RAM fromActivityManager.ModelMemoryGateto evaluate estimates against available RAM, assigning a risk severity ofTIGHTorINSUFFICIENT.MemoryWarningDialogFragmentto present the warning, utilizing a newUserConfirmationcoroutine primitive to gracefully handle async user decisions and process death.index.htmland tooltips to explain the memory requirements and warning behaviors to users.document_5161635105843709586.mp4
Ticket
ADFA-1798
Observation
ContentResolverqueries during the pre-flight check are dispatched to the IO thread to avoid blocking the main UI thread.