Repository navigation
Studio: warn when a GGUF is tight for Apple unified memory - #14598
Conversation
The picker scored Apple Silicon against total RAM, so on a 64 GiB Mac it badged quants up to ~62 GiB as fitting while llama.cpp and MLX admit min(Metal working set, free) * 0.85. /api/system now reports metal_working_set_gb on the MLX device, and quants past that loader budget but inside the old one show the existing tight tier with a hint that they may load with a shorter context or run slower. Nothing is hidden or marked as not fitting, and other hosts are unchanged.
Codex Review SummaryThis 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. |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
…s resident The loader kills the resident llama-server before it reads available memory, so the free figure the picker polled still counted that model as used. With a 20 GiB model loaded on a 64 GiB Mac, quants the reload would admit in full, the loaded quant included, read as a tight fit. While a chat model is resident the picker now uses the working-set ceiling, working set * 0.85.
…et-review # Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
chatModelLoaded counts a remote API model as loaded, so picking one swapped the measured free-memory budget for the working-set ceiling although switching away frees nothing locally.
|
Codex Review: Didn't find any major issues. Bravo. 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". |
…et-review # Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
…et-review # Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
|
@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: bb5b94a571
ℹ️ 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".
| /** Apple MLX loader budget (`GpuInfo.unifiedLoadBudgetGb`): past it, `fits` becomes `marginal`. */ | ||
| unifiedLoadBudgetGb?: number | null; |
There was a problem hiding this comment.
Pass the unified budget to the Hub GGUF card
The new input is only supplied by the chat picker; the Hub’s GgufDownloadCard and its variant sorting still construct fit inputs from gpuGb, gpuCount, systemRamGb, and budgetFraction alone. Consequently, on an Apple host under memory pressure the picker can label a GGUF as a tight fit while the Hub card continues to badge and sort the same variant as a clean fit. Thread the applicable unified load budget through the Hub inspector/card resources as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Out of scope by design: the PR description lists the Hub download card and variant sort as a separate surface still on the old rule; this PR does not change them, so nothing regresses there.
|
@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: 794d56860e
ℹ️ 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".
| const freeGb = withFree | ||
| ? (finitePositive(device.vram_free_gb) ?? | ||
| finitePositive(data.memory?.available_gb)) |
There was a problem hiding this comment.
Prefer host-available memory for the Apple budget
On the actual /api/system response, the MLX visibility probe does not publish vram_free_gb, and the utilization probe reports only AGX usage, so main.py synthesizes this field as total RAM minus AGX-used memory. Ordinary CPU/app memory pressure is therefore absent from device.vram_free_gb, yet this branch prefers it over memory.available_gb; for example, a 64 GiB Mac with 22 GiB host-available and little AGX usage is scored near the 44 GiB working-set ceiling instead of the loader's roughly 18.7 GiB budget. Use the host-available figure here or make the backend publish the authoritative bounded free value so the new warning works under the memory pressure it targets.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not reproducible from the code: /api/system takes free memory from get_visible_gpu_utilization(), whose MLX branch publishes vram_free_gb = get_gpu_memory_info()['free_gb'] (hardware.py:5177), and that is _apple_unified_free_bytes(psutil available, info) = min(host available, Metal working set) (hardware.py:2649). main.py keeps a producer's free value instead of recomputing total - used, so app memory pressure is already in it.
…d keep a 0 GiB free reading [skip ci]
… through audio.cpp
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cd3cab0678
ℹ️ 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".
| // The AGX in-use figure holds the resident model's Metal buffers, which the loader frees first; | ||
| // other apps' memory stays counted. Unknown usage leaves only the working-set ceiling. | ||
| const usedGb = finiteNonNegative(device.vram_used_gb); | ||
| freeGb = freeGb !== null && usedGb !== null ? freeGb + usedGb : null; |
There was a problem hiding this comment.
Do not credit all AGX usage to the resident model
When another process such as WindowServer is using Metal while a chat model is resident, this adds that process's memory to the post-unload budget even though unloading the model cannot reclaim it. The backend explicitly describes _read_apple_gpu_stats()/vram_used_gb as a system-wide, whole-device AGX counter (hardware.py:2425-2426 and 3127-3149), so freeGb + usedGb can approach the working-set ceiling under external GPU pressure and incorrectly remove the new tight-fit warning. Derive the reclaimable amount from the resident model rather than the device-wide counter, or retain the live free-memory bound when it cannot be attributed.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving as is: the figure is still capped by the working set, so at worst it equals the ceiling this PR started from, and the badge is a soft warning. The picker has no per-model Metal footprint on this branch; the device counter is the closest attribution available.
| let freeGb = | ||
| finiteNonNegative(device.vram_free_gb) ?? | ||
| finiteNonNegative(data.memory?.available_gb); |
There was a problem hiding this comment.
Refresh memory before deriving the unified budget
When the picker is opened after host memory usage has changed, this normally derives the budget from an old /api/system snapshot: useGpuInfoSource() calls fetchSystemInfo() without force or refreshMemory, and use-system.ts returns the module-level cached response indefinitely unless an unrelated live monitor is polling. Thus a snapshot captured before another app allocated memory—or before a resident model loaded—can keep GGUF rows marked as clean fits despite current pressure. Request a refreshed memory snapshot when this picker becomes active, or arrange periodic refreshed snapshots while it is visible.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pre-existing: every fit verdict in this picker (CUDA VRAM included) reads the same shared /api/system snapshot; this PR adds no new caching and changing the refresh policy is out of scope.
| const t = useT(); | ||
| const unifiedLoadBudgetGb = useContext(UnifiedLoadBudget); | ||
| const verdict = | ||
| status === "marginal" && unifiedLoadBudgetGb !== null |
There was a problem hiding this comment.
Preserve the VRAM-budget verdict when it caused marginal
On an Apple host whose saved VRAM Budget is below the unified-memory ceiling, a model between those two thresholds is marginal solely because of the saved setting: the unified check only changes a result inside the required <= budget branch. This condition nevertheless replaces every marginal verdict whenever an Apple budget exists, so the actionable “larger than your VRAM Budget” explanation becomes the unrelated Mac context/slowness hint even though raising the saved budget would resolve it. Carry whether the unified threshold actually caused the verdict instead of inferring that from a non-null context value.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving as is: both explanations are soft warnings for the same tier, and on a Mac a load past a lowered VRAM Budget does run with a shorter context or slower, so the hint is not false.
…through llama.cpp
|
@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: 460383b27d
ℹ️ 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".
| * GGUFs (Orpheus and the like) do load through llama.cpp, so the Audio task alone decides nothing. */ | ||
| function loadsOnAudioCpp(repoId: string): boolean { | ||
| return audioCppModelFor(repoId) !== null || isAudioCppFolderId(repoId); |
There was a problem hiding this comment.
Use audio runtime metadata before applying the Metal budget
On an Apple Audio picker, a cached, local, or community GGUF can be identified as an audio.cpp model by its audio_type (audiocpp_tts, audiocpp_music, or audiocpp_sep) even when its repository/path is absent from the static catalog and is not an umbrella-folder ID. This helper then returns false, so both parent and variant fit calculations apply llama.cpp's unified-memory budget to a model that the existing audio policy routes through audio.cpp, producing a spurious marginal warning. Pass the row's audio type through and use the existing isAudioRuntimeGguf predicate rather than relying only on the ID.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving as is: the curated audio.cpp rows and folders are covered; an uncatalogued cached or community audio.cpp GGUF on a memory-pressured Mac gets a soft tight-fit badge, and it does load into the same unified memory, so the badge is not wrong about memory. Threading audio_type into both fit paths is a larger change than that warrants here.
| devices: readonly GpuDevice[], | ||
| afterUnload = false, | ||
| ): number | null { | ||
| if (data?.device_backend !== "mlx" || devices.length !== 1) return null; |
There was a problem hiding this comment.
Publish the budget for GGUF-only Apple hosts
On a supported Apple Silicon --no-torch installation, or while the MLX stack is unavailable, hardware detection reports device_backend: "cpu" even though the bundled llama.cpp still runs GGUFs through Metal. Its loader continues to apply _apple_metal_memory_budget_bytes() based on the Apple platform, but this guard forces the picker budget to null and the backend only publishes metal_working_set_gb from its DeviceType.MLX branch. Those Mac users therefore retain the incorrect total-RAM fit verdict this change is meant to fix; identify Apple/Metal inference independently of the training backend and expose the same budget for the GGUF-only path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Out of scope: a --no-torch or MLX-less Mac keeps today's verdict exactly (the field is absent, so nothing changes for it); extending the budget to that path needs a backend probe outside the MLX branch and is a follow-up, not a regression here.
|
pre-commit.ci run |
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
What changes for users
On Apple Silicon, the GGUF model picker said "fits" for quants the loader then squeezes. It now shows a soft warning for those instead, and nothing is hidden or blocked.
The gap. The picker budgeted a Mac like a discrete card: 97% of total RAM, which is 62.1 GiB on a 64 GB machine. The loader (
_apple_metal_memory_budget_bytesfor llama.cpp, the same rule in MLX) actually admitsmin(Metal recommended working set, available RAM) * 0.85. On the M3 Max used for testing the working set is 51.84 GiB, so the best case is about 44 GiB, and with ~17-22 GiB free it is about 15-19 GiB. Anything between that and 62 GiB was badged "fits", then loaded with a shorter context or spilled to the CPU.The change.
/api/systemgets an additivemetal_working_set_gbfield.How it was verified
tests/test_mlx_metal_working_set_visibility.py;ruff checkis clean.tests/apple-unified-gguf-fit.test.ts(64 GiB Mac with 51.84 working set and 22 free: 22.2 GiB required is marginal, 15 GiB fits, 63.5 and 200 GiB unchanged; NVIDIA 24 GiB unchanged at every size).memory-cross-surface-matrixpasses.npm run typecheck, the fullnpm testandnpm run buildpass./api/systemreportsmetal_working_set_gb: 51.84. In the picker,unsloth/Qwen3-32B-GGUFquants above the current budget show the amber hint, and smaller ones show none:Not tested here
Before / after
Two isolated Studio installs, BEFORE at the merge base and AFTER at this branch's head, both answering
/api/systemwith the same Apple M3 Max reading (64 GiB unified memory, 51.84 GiB Metal working set, 22 GiB free), since this machine has no Apple GPU. The chat model picker,unsloth/Qwen3-32B-GGUFexpanded: