Repository navigation
fix: honor Flash Next host offload and explicit MLX memory budgets - #49
Chedrian07 wants to merge 4 commits into
Conversation
The MLX preflight charged the entire checkpoint before the loader could memory-map its n-gram tables, refusing Flash Next on a 128 GiB Mac even in host mode. Let families estimate startup weight bytes. Flash Next uses the loader's shared host-selection rule and subtracts only mapped weight, scale and bias ranges from safetensors headers. Keep the 70% budget and reject oversized resident weights or forced GPU tables. Tests cover automatic and explicit host mode, forced GPU mode, reduced budgets, mixed checkpoint files and both MLX device-info APIs.
Document automatic n-gram placement, the family weight estimate hook and the distinction between resident buffers and reclaimable file pages. Keep context fitting and the existing memory ceiling explicit.
Default parallel startup retains the shared-forward probe's rollback buffers in Flash Next. The following prompt-memory probe then charges those unused rows as resident memory, leaving no prompt room on a 128 GiB Mac even after host n-grams are excluded. Implement the existing release_rounds family hook for backbone and MTP states, cache references and hidden rows. Preserve the prefill schedule and memory limits. Test prompt admission after release and real GPU buffer reclamation with bit-identical subsequent shared forwards.
TENSORFOLD_MEMORY_LIMIT_GB now replaces the 70% default, capped by physical RAM and the GPU recommended working set. Keep the 3 GiB process reserve and honor the resolved budget in concurrent admission without changing lower-budget behavior. Cover raised and lowered limits, hardware caps, both device-info APIs, large finite values, concurrent admission under memory pressure and the CLI's allocator/server handoff. Update the memory guidance and startup help.
|
Thanks @Chedrian07. This lands in 0.3.6.2 with your four commits under your name: 222fe5fd, 923c1f0a, 70a61130, 153f488b. Our 0.3.6 line had moved on since 0.3.5 ( On top of yours: the concurrency admission moved to its own module (we keep |
…h and without giving way (#49)
…e more after the output; the loader sets give_way and tf-h3-dit gives way too (#49)
…arks a clean timing (#49)
…ay to speech too (#49) Card 50 moved binding into Folder.bind and h3.Model.bind; give_way now rides on the folder's io, so tf-h3-image and tf-h3-image-server both yield between blocks and report timing_valid.
…before the free run (#49) buildCase unmapped pic while case.noise still pointed into it; once rebinding remapped those pages, fresh and resident runs read different garbage noise.
…ri rerun and the noise fix (#49)
…es this branch's (#49)
…d of losing its hold (#49)
…asses, tested per stage (#49)
…closing, so late wake-ups cannot outlast the grace (#49)
…s denoising and the decoder (#49)
…batch probe and never losing its hold (#49)
…r, decoder and a denoising step (#49)
On a 128 GiB M4 Max,
tensorfold serve Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTPrefused the 105.4 GiB checkpoint before the loader could map its 29.8 GiB of n-gram tables on the host. Count those tables separately so the remaining 75.6 GiB of weights can enter memory admission, and allow an explicit memory budget to raise or lower the default for larger contexts.The default parallel startup also retained Flash Next's shared-forward probe buffers. After correcting the weight check, those unused rollback states made prompt admission report 88.0 GiB needed against the 86.6 GiB MLX limit. Implement Flash Next's existing
release_rounds()family hook so startup releases the backbone and MTP probe states before profiling prompt memory.weight_bytes(model_dir)family hook, retaining the file-size estimate for other families. Flash Next reads only safetensors headers and subtracts the mapped n-gram weight, scale and bias ranges; unrelated tensors and files stay counted.TF_NGRAM_HOST=1andTF_NGRAM_HOST=0, and report resident/file-backed sizes at startup.TENSORFOLD_MEMORY_LIMIT_GBreplace the default 70% RAM budget, within physical RAM and the GPU's recommended working set. On this Mac,110now means a 110 GiB process budget and 107 GiB for MLX. Concurrent admission honors the larger allowance while retaining the checks for memory held elsewhere and the existing behavior for lower budgets.Validation on Apple M4 Max, 128 GiB, macOS 26.6.2, Python 3.14.0, MLX 0.32.2 and mlx-lm 0.31.3:
python -m pytest -q --tb=no): 1,251 passed, 285 skipped, 4 failed. The same fourtest_bounded_prompt_matches_stock_causal_bitscases (257/273 rows, bf16/fp16) fail on a separate unmodified checkout of basea3274f1with this runtime. CUDA GPU tests are not collected on this Mac.dadefa8066e3be900a0d148d0f5a2f4eb1cf6534: the default-budget check ate7547c1reached serving with parallelism 8, MTP enabled and context automatically fitted to 63,488 tokens.3d9530b,TENSORFOLD_MEMORY_LIMIT_GB=110 tensorfold serve Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTP --context 262144 --max-tokens 131072 --host 127.0.0.1 --port 1313 --no-update-checkreached serving with context 262,144, default parallelism 8 and MTP enabled. The allocator and concurrent admission both reported 107 GiB for MLX;/healthreported a 110 GiB process budget. Startup took 539.3 seconds on this host with paging./health,/v1/modelsand short/v1/chat/completionsrequests returned HTTP 200. With thinking enabled by default, the greedy arithmetic smoke emitted 26 completion tokens and final answer4with drafting enabled and disabled; both token hashes were894ffec4f91c. The requests usedmax_tokens: 512to bound the smoke, so they do not validate a 131,072-token completion.Starting with a 262,144-token context is not a full-window inference qualification; only short requests were run. Host mappings still use reclaimable RAM pages, and a raised budget can increase memory pressure. This change does not promise swap-free execution or qualify SSD throughput. The test host already had swap in use and paging increased during startup.