Repository navigation
[Engine] qwen4: extend --ple-direct to Metal (F_NOCACHE), async overlap, and macOS warmer - #473
Draft
NightRain233 wants to merge 1 commit into
Draft
NightRain233 wants to merge 1 commit into
NightRain233 wants to merge 1 commit into
Conversation
NightRain233
force-pushed
the
feat/qwen4-metal-ple-direct
branch
from
December 6, 2026 05:38
3cee661 to
cb2ddec
Compare
…p, and macOS warmer
NightRain233
force-pushed
the
feat/qwen4-metal-ple-direct
branch
from
December 6, 2026 16:45
cb2ddec to
40478fe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and result
On 16 GB Apple Silicon Macs running Qwen4-35B-A3B (
UD-IQ2_XS), the 10.73 GiB per-layer embedding (PLE) table (per_layer_token_embd.weight) cannot stay resident in RAM alongside VRAM-cached weights and routed experts. Reading PLE rows viammappollutes the unified-memory page cache, pushes macOS into heavy swap thrashing, and caps decode throughput on 16 GB hosts.Upstream #464 added an opt-in
--ple-direct(DirectFile/PleReader) path for CUDA/HIP while explicitly keeping Metal excluded (!gpu::is_metal()). This PR builds directly on top of #464 (0794bc5) to extend Direct I/O PLE support to Apple Silicon Metal:PleReaderwithF_NOCACHEon macOS (--ple-direct/--ple-mmap/STRATA_PLE_DIRECT/STRATA_PLE_CACHE_ROWS), keeping CUDA/HIP opt-in default (0) unchanged and auto-selecting Direct I/O on tight-RAM Metal hosts (ple_direct = -1auto mode).PleReaderinload_geometry()beforefill_expert_cache()so the PLE budget is accounted for during expert cache sizing, and submits Metal layer 0 (gpu::metal::submit()) before waiting onPleReader::collect()to overlap SSD reads with GPU work.start_ple_warmer()to support macOS (getpagesize()stride +MADV_WILLNEED) when mmap mode has sufficient headroom, gated behindorigin/main'sshould_warm_ple_table().Related discussion
Tracking issue: #472. Rebased cleanly onto
origin/main(0794bc5, including merged #464).Approach
ple_direct = 0default on CUDA/HIP/SYCL; addsple_direct = -1auto selection for tight-RAM Metal hosts (with explicit--ple-direct,--ple-mmap, andSTRATA_PLE_DIRECToverrides).F_NOCACHEinDirectFile(pread) with the bounded row cache (1,048,576rows /76 MiBdefault, tunable viaSTRATA_PLE_CACHE_ROWS) to prevent unified-memory page-cache bloat.gpu::metal::submit()overlap beforePleReader::collect()so layer 0 GPU execution hides SSD read latency; drains pending PLE tickets cleanly on~Qwen4(),reset_call(), andon_reset().start_ple_warmer()for macOS (MADV_WILLNEED) behindshould_warm_ple_table()on roomy Macs (>= 32–64 GiB).STRATA_PLE_DIRECTandSTRATA_PLE_CACHE_ROWSinterminal/data/settings-register.jsonand updatesdocs/SETTINGS.mdanddocs/models/qwen4.md.Validation
40478feonorigin/main0794bc5):strata-poly+ all poly test targets): 0 errors.ctest --test-dir build-pr473 -L poly --output-on-failure: 51/51 (100%) passed (includingpoly_qwen4_parity,poly_memory_test,poly_memory_growth,poly_metal_defaults,poly_runtime_safety).python3 tools/test_dropped_paths.py,python3 tools/settings_register.py --check,python3 tools/check --only docs: all passed (docs 6/6).Qwen4-35B-A3B-UD-IQ2_XS, integrated stack):--metal-memory balanced --ple-direct --max-context 131072 --basinkv --basinkv-index sphere --basinkv-kv-quant wht_int4): PLE Direct achieved 93.0% cache hit, only246.30 MiBSSD reads (699.8 mscollect wait), peak memory footprint9.56 GiB,0.00 GiBexitgpu_inuse, 100% exact needle recall (COBALT-7319).1,870,192 / 1,966,464rows), only338.86 MiBSSD reads (1,061.0 mscollect wait), peak memory footprint9.57 GiB(0 swaps),0.00 GiBexitgpu_inuse, 100% exact needle recall (QUARTZ-6042).7.4–8.8 GiB(13.9–15.5 MiBSSD reads per 192-token decode;612 MiBSSD reads across 32,768-token prompt with58.1%cache hits).CONTRIBUTING.mdpending maintainer review andrun-backendscross-backend CI.Limits
should_warm_ple_table()warmer automatically.run-backendsCI before merging.