#4140·omlx

perf(qwen4): investigate PLE mmap decode stalls on 96 GiB Macs — bounded caching, cross-shard reads and telemetry

Author: eazerox2Created Oct 1, 2026Updated Oct 1, 2026

Summary / request

On an M3 Ultra with 96 GiB unified memory, Qwen3.8-Flash-Next-oQ4e-mtp fits only with its PLE n-gram table offloaded. Fresh short requests can decode materially slower than immediate identical replays, and the difference closely tracks process-accounted page-ins. This also makes naive MTP ON/OFF comparisons misleading.

Could we instrument the PLE decode path and test batched cross-shard page reads, then a bounded cache of packed PLE rows/pages if the measured hit rate supports it? The goal is to reduce stalls on machines that cannot hold the whole checkpoint in RAM, without changing model weights, dropping PLE, or weakening the verifier.

This is a performance investigation / enhancement request, not a claim that offload itself is a correctness bug. Hardware replacement is not available for this system.

Environment

Apple M3 Ultra, 60 GPU cores, 96 GiB unified memory. macOS 27.0, build 26A428. oMLX 0.7.0, macOS app build 2987; release tag commit 4d4f5a280b. MLX / mlx-metal 0.32.2; mlx-vlm 0.7.1; mlx-lm 0.31.4.dev132+g94cdcae13. Checkpoint: Jundot/Qwen3.8-Flash-Next-oQ4e-mtp, qwen4_exp / qwen4_exp_text; qwen4_ple_ssd_offload=true. The inspected installed PLE language.py, paged_ssd_cache.py, MTP batch_generator.py, and engine-pool/residency files match their v0.7.0 Git blob hashes. No runtime patch was applied for this experiment. One resident model, concurrency 1. SpecPrefill remained enabled at keep 0.2 / threshold 8192, but all these prompts were below threshold. What was measured

Forty measured requests: OFF (8) -> fixed MTP depth 2 (16) -> OFF (16), with one excluded, recorded warm-up per arm. Prompts had 111–134 input tokens; all 40 produced 512 output tokens and finished length. Temperature 0, top-p 1, top-k 0, min-p 0, seed 37, thinking disabled; penalties neutral.

Each fresh prompt had a leading nonce and zero cached prompt tokens. It was then replayed byte-identically. Cross-arm prompts were run twice in the receiving arm so the second capture could be paired with the warmed capture in the other mode. Settings changes caused model reloads; the server process was not restarted and neither prompt cache nor OS page cache was purged.

Timing: throughput is completion_tokens / generation_duration from streamed usage: server post-first-token generation, not GPU-kernel-only or client end-to-end. proc_pid_rusage (rusage_info_v4.ri_pageins) was sampled before and after each entire request; those counts include prefill and are not yet attributed to PLE files or decode-only intervals.

First OFF arm: fresh requests 62.2–64.6 tok/s, identical replays 80.1–80.4 tok/s. Fresh requests incurred 21.5–26.1 page-ins per output token; replays 0–0.023. Return-OFF arm: fresh requests 67.5–78.3 tok/s, replays 80.5–80.8 tok/s. Fresh requests were less page-in-heavy than the first OFF arm. Aggregate warmed OFF rates: 80.25 / 80.47 / 80.60 tok/s, a 0.43% spread across the run. Eight warmed, identical-prompt OFF/depth-2 comparisons had byte-identical visible output. Mean paired speedups: code 1.293x (four pairs), prose 1.060x (four), all eight 1.177x. These are diagnostic short-greedy results, not production/quality qualification. Depth-2 logged backbone time divided by cycles was 24.8 ms/cycle on warmed replays, versus 28.0–31.4 ms/cycle on fresh requests. The warm OFF server-generation baseline was approximately 12.46 ms/output token; these are different timing scopes, not an exact GPU-to-GPU ratio. Descriptive fit across 24 OFF samples: server_ms/output_token = 12.495 + 0.139 * (whole_request_pageins/output_token), Pearson r 0.998. This mixes cache-hit and cache-miss samples and does not prove that every counted page-in is a decode-time PLE read. A separate read-only header/mincore inspection found approximately 29.8 GiB of PLE n-gram tensor payload. Another per-family snapshot found about 23.84 GiB packed weights + 2.98 GiB scales + 2.98 GiB biases, with roughly 14% / 44% / 44% of their covered pages resident respectively. These are snapshots, not peak-memory figures or a measured hit-rate distribution.

The model configuration has 16 n-gram heads and 128 PLE shards. Representative affine rows occupy 80 bytes of packed weight + 10 bytes scales + 10 bytes biases; the OS page size is 16 KiB. This is a reason to measure page amplification and consider caching packed values—not evidence that a particular cache size is optimal.

Source observations and proposed experiments

  1. Instrument first: attribute stalls and expose the actual small-window path

The source’s seen-page bitmap records previously touched pages, not current residency, and its slow-gather rearm is explicitly heuristic.[1] Please distinguish:

PLE index evaluation/host transfer, gather planning, blocking row reads, upload/dequantization, and total gather wall time. R=1 decode and R=2/3/4 verification windows; requested rows and unique pages per shard and tensor family. Prefetch submission count, hit/wait time, cache hit/miss bytes, and host memory budget. Decode-interior faults and file attribution where feasible. The existing “eviction suspected” warning is useful, but should not be interpreted as a measured eviction counter. Small first patch: opt-in per-request PLE timing/counters, enabled for both MTP ON and OFF. That would tell us whether the next two experiments are worth implementing.

  1. Batch page reads across shards for short decode/verify windows

_SafeTensorMMap._rows_np_owned invokes _prefetch_missing_pages only when that call’s row_indices.size > 8. _assemble then walks touched shards and tensor families, issuing rows_np separately.[1]

A 1–3-token window can request many pages overall while having only a few rows per individual shard/family call. Could we collect the unique (reader, page) requests for the entire PLE lookup, issue a bounded parallel batch, then assemble the rows in original order? Test this against the existing path rather than merely lowering the gate and creating many tiny thread submissions. Bound queue depth and preserve read-error draining/resource ownership.

Expected benefit (hypothesis): overlap independent SSD misses in a small verification window instead of waiting on serial shard gathers. The effective small-window submission counts have not been traced on this machine yet.

  1. Bounded packed-row/page cache, not full-table pinning

The existing path copies the gathered weight/scales/biases and dequantizes afterward.[1] An opt-in byte-budgeted cache could retain packed rows/pages with their required scale/bias data, without caching expanded BF16 embeddings or changing arithmetic.

Start with measured hit rates and small budgets; do not assume hashed n-gram access has a useful hot set. Include copied storage, indexes and outstanding reads in accounting; avoid simply duplicating OS-cached pages without a net benefit. Reserve prompt/KV and OS headroom, reclaim under pressure, and clear on model unload. No unbounded mlock or raised memory limits. Compare caching rows versus pages: rows avoid 16 KiB read amplification, while pages may share storage across nearby lookups. Test whether scales/biases warrant preferential residency; their payload is about 5.96 GiB combined, but retaining all of it might cost too much serving headroom. 4. Investigate prompt-cache I/O interference separately

The persistent KV cache was about 92 GB on disk during the investigation. Its load path uses mx.load.[2] That disk size is not a RAM-use measurement, and we have not demonstrated that its I/O evicts PLE pages.

If direct attribution suggests interference, A/B an isolated test instance with controlled KV-cache traffic and the same model-data warmth. Consider a macOS-specific cache-pollution control only if the underlying file I/O supports it and it improves the result. Do not change mmap advice globally or clear a production prompt cache to approximate this control.

Reproduction and acceptance

Use the environment/settings above and one inference request at a time. Send a new nonce-prefixed request with one of the exact prompts below; record actual prompt/completion counts and cached_tokens. Replay it exactly, verifying output hash equality, and record request-counter deltas plus server generation duration. Repeat OFF -> depth 2 -> OFF with the cross-arm replay design, not just disjoint fresh averages. Keep settings/cache policy fixed outside the MTP fields. For an instrumented candidate, compare fresh/cache-miss and replay cases separately; verify actual PLE read attribution and byte-identical greedy output. Report memory peak, cache-hit rate, prefill/TTFT impact and long-context admission separately. A short-greedy win alone should not promote the feature. Exact task prompts (each receives a fresh leading request identifier) Limitations / evidence

Replays also reuse the prefix KV cache; this is not a factorial isolation of KV reuse versus PLE warmth. Warmth of graph/kernel state may also co-vary. Process page-ins cover the whole request. ri_diskio_bytesread sometimes rose without page-ins or a throughput loss, so it is retained as a separate counter rather than equated to physical PLE SSD traffic. Cross-mode first-replay misses are consistent with speculative-only PLE lookups, but reload/history differences also explain them. Rejected drafts have not been identified as the cause. Warmed means the working set touched by these requests, not the whole table resident. No resident-versus-offloaded same-hardware control was possible. The accompanying evidence ZIP contains benchmark-evidence.json with all 40 measured rows, exact request bodies, output hashes, cache counts, whole-request counter deltas and request-bounded MTP completion summaries; benchmark-summary.json with recomputed paired results and descriptive fits; and a flat CSV for quick inspection. No hostnames, user paths, credentials or production prompts are included. If this is better handled under an existing performance issue, happy to move the data there. The most useful first action would be an instrumented small-window PLE gather so we can validate the cross-shard-read hypothesis before choosing a cache design.

omlx-ple-mtp-evidence.zip

Sources

[1] https://github.com/jundot/omlx/blob/v0.7.0/omlx/patches/mlx_vlm_qwen4_exp_compat/vendor/mlx_vlm/models/qwen4_exp/language.py — PLE row reads, >8-row prefetch gate and heuristic rearm [2] https://github.com/jundot/omlx/blob/v0.7.0/omlx/cache/paged_ssd_cache.py — Persistent prompt-cache load path()