Repository navigation
feat(moe): size each residency option and fit the largest that admission accepts - #3676
beatakouchnir wants to merge 1 commit into
Conversation
0532fc5 to
9c33d0d
Compare
9c33d0d to
81b146f
Compare
|
A few changes since this was opened: UI now follows #3714. The residency control is now the percentage field, so the per-option size labels and the "Fit to memory" dropdown entry in the original description are gone. The fit appears as a clickable hint under the field ( Resident MTP draft head (#3784, #3841). The cached layout scan behind Separate commit, fixes main: |
81b146f to
4acc499
Compare
4acc499 to
525cbde
Compare
8634ad5 to
7755be6
Compare
|
Rebased onto cd6bf3e. Since #4100, the PLE and Engram status calls record and log forced-offload decisions; the fit and per-option sizes call them at hypothetical fractions on every admin poll, so sizing probes now pass |
e23ae21 to
1012212
Compare
|
Rebased onto c0b1056. #4396 removed the |
1012212 to
293e0c0
Compare
293e0c0 to
a065962
Compare
…ion accepts The residency selector offered four fractions with no indication of what each costs or whether it fits; users mapped their memory to a fraction by hand, or found out at load time. DeepSeek V4.1 already had fit_resident_fraction, but only as a library call and only for that adapter. - moe_expert_offload: the header scan behind estimate_offload_admission_bytes is factored into a cached layout (keyed on the shards' stat signature) plus pure arithmetic; the estimate's contract is unchanged. New offload_capacity_fractions (every fraction that maps to a distinct whole-expert capacity, so a chosen value round-trips through the setting) and fit_resident_fraction (largest one whose estimate fits a budget). - deepseek_v41: capacity_fractions for the same purpose. - EnginePool.moe_offload_admission_bytes and fit_moe_offload_fraction run the pool's own _entry_runtime_resident_size on a probe copy of the settings, so every adapter (common, V4.1, Qwen4 with PLE) is sized by the arithmetic admission uses. The budget is threaded through as the ceiling the SSD fallbacks decide against, which keeps the fitting fractions a prefix. - /api/models reports moe_expert_offload_presets (bytes and fits per option), moe_expert_offload_fit_fraction and moe_expert_offload_fit_bytes against the admission ceiling; the dashboard annotates each option with its size, marks the ones over the ceiling, and offers the fit as an option when it is not one of the presets. Tests pin the adapter fit to the estimate over every candidate, the pool to the adapter (common and V4.1, both Engram modes), the route payload with and without a ceiling and on a sizing error, and the dashboard labels. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
a065962 to
f6b4894
Compare
|
@beatakouchnir The fit in this PR picks the largest residency whose estimate fits under the load ceiling, so the suggested value always lands right under that ceiling. I ran it on an M3 Ultra with the ceiling held at 12 GiB (balanced tier). For gemma-4-26b-a4b 4bit and Qwen3.6-35B-A3B 4bit the suggested 74.2% and 57.8% were refused at load, because admission also counts the server process. Where it does load, the weights sit above the prompt line (ceiling x tier headroom), so prompts get a 400. I opened a smaller version in #4858 with you as co-author on the commit. It runs the same admission arithmetic through I'm not merging the PR itself because the fix changed the core of the fit. Once the target moved, the per-option preset sizes, the adapter-level bisect and the cached layout in the admission estimate were no longer needed, and asking you to remove all of that after this sat open so long didn't seem fair. The delay is on me, sorry about that. The sizing work from #2595 and #3628 is what made this small, and keeping this branch rebased through all the churn took real effort. Thanks for that. Closing this in favor of #4858. |
Follow-up to #2595 (expert offload primitive) and #3628 (V4.1
fit_resident_fraction).Problem
The residency field accepts 5–95 percent with no indication of what a value costs in memory or whether admission will accept it. Users map their machine to a fraction by hand, or find out at load time. A fit existed only for the DeepSeek V4.1 adapter, and only as a library call.
Change
moe_expert_offload.py: the header scan behindestimate_offload_admission_bytesis factored into a cached layout (keyed on the config and shards' stat signature) plus pure arithmetic; the estimate's contract is unchanged, andmtp_resident(from feat(moe): Lightning MTP coexists with DeepSeek V4.1 expert offload (resident DSpark draft head) #3784/feat(moe): keep the GLM-5.3 draft head resident so Lightning MTP coexists with glm5_next expert offload #3841) is part of the layout's cache key, so a resident draft head is never counted as offloadable. Newoffload_capacity_fractionslists every fraction that maps to a distinct whole-expert capacity, so a chosen value round-trips through the setting exactly, andfit_resident_fraction(model_path, full_size, budget_bytes, *, mtp_resident=False)bisects it for the largest fraction whose estimate fits (1.0when the resident model fits,Nonewhen even the floor does not, as for V4.1).deepseek_v41:capacity_fractions.EnginePool.moe_offload_admission_bytes(entry, settings, fraction)runs_entry_runtime_resident_sizeon a probe copy of the settings, andfit_moe_offload_fraction(entry, settings, budget_bytes)bisects the adapter's candidates (built with the settings'mtp_enabled) through it, so every adapter (common, V4.1 with either Engram mode, Qwen4-Exp with the PLE table) is sized by the arithmetic admission uses._entry_runtime_resident_sizegains an optionalceiling(defaultNone, the previous behavior) that reaches the PLE and Engram status calls. The fit passes the budget as that ceiling: a resident table that stops fitting is forced to SSD exactly as admission would force it, and the larger fractions are held to its mmap size, which keeps the fitting fractions a prefix. Sizing probes passlog_decision=Falseto the PLE and Engram status calls, so the admin view's per-poll sizing neither logs a forced offload for a fraction nobody chose nor resets the per-model dedup state from fix(engine_pool): log a forced-offload decision only when it changes #4100.GET /api/models:moe_expert_offload_presets(fraction,bytes,fitsper option),moe_expert_offload_fit_fractionandmoe_expert_offload_fit_bytes(null/0when the ceiling is unknown, the model is not in the pool, or nothing fits). A sizing error is logged at debug and leaves the fields empty.Fit to memory: 41.4% resident · ~8.0 GB, that fills the field; when even the routing floor exceeds the ceiling, a one-line notice replaces it. Two i18n keys (English in every locale file, like the existing offload keys). Docs gain a Sizing a residency to your memory section.Verified
Header-only on cached checkpoints (M5 Max 128 GB, nothing loaded). The 107 GiB budget is the documented Metal working-set limit on a 128 GB machine. Every call took at most 0.04 s.
mlx-community/gemma-4-26b-a4b-it-4bit(128 experts)mlx-community/OLMoE-1B-7B-0125-Instruct-4bit(64 experts)mlx-community/Qwen3.8-Flash-Next-4bit(512 experts)Jundot/DeepSeek-V4.1-Flash-oQ3e-mtp(384 experts)The V4.1 row reproduces the 41% the docs quote for
fit_resident_fractionat 107.5 GiB. The Flash-Next row is the non-monotone case: at 75% the PLE table is resident (90.6 GiB), at 100% the resident estimate exceeds the ceiling, the table is forced to SSD and the model fits at 77.8 GiB. For gemma and OLMoE the pool's fit equals the adapter-only fit at every budget.Tests
test_moe_expert_offload.py::TestBudgetFit: candidates are whole experts in some container (a stacked 32-expert and a per-expert 16-expert container in one checkpoint); at every candidate's estimate and one byte below it, the fit is the largest candidate whose estimate fits; dense checkpoint and a missing path fit only at the full size; the layout cache follows a checkpoint edit; withmtp_residentthe draft head's container is neither discounted nor a candidate, even after the cache was populated without the flag; the pool's admission and fit equal the adapter's at every candidate, and the probe never edits the caller's settings.test_deepseek_v41_moe_offload.py:capacity_fractions, and the pool's fit equals the adapter's SSD fit at every capacity's size and one byte below it, in both Engram modes; after the fits, no forced-offload decision has been recorded.test_moe_offload_compat.py: the payload with a ceiling (sizes,fits, fit, the ceiling passed to every call), without one, and on a sizing error.moe_expert_offload_ui.test.cjs: the fit hint's label, apply and no-fit states and its markup.338 passed across the offload, offload-compat, engine-pool and Qwen4-Exp residency suites on the current base; the UI test passes;
ruffis clean on the changed lines; new code is black-formatted, existing files were not reformatted.Not in this PR
An "auto" residency that resolves to the fit at load time. The pieces are here; it needs a settings-schema decision (sentinel fraction or separate flag) and the native app's DTO.
🤖 Generated with Claude Code