Repository navigation
[Engine] qwen4: add memory-aware PLE Direct reader (F_NOCACHE) 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
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 the OS into heavy swap thrashing, and caps decode throughput on 16 GB hosts.This PR adds a memory-aware Direct I/O PLE reader (
PleReader+DirectFilewithF_NOCACHEon macOS,--ple-direct/--ple-mmap/STRATA_PLE_DIRECT/STRATA_PLE_CACHE_ROWS), asynchronous prompt/draft PLE prefetching with Metalsubmit()ordering so layer 0 executes while SSD reads complete, and macOS 16 KiBMADV_WILLNEEDwarmer support gated cleanly behindorigin/main'sshould_warm_ple_table()inEngine::on_loaded().Related discussion
Tracking issue: #472. Rebased onto
origin/main(7cef952,v0.2.20-poly.11), preservingd72af68'sshould_warm_ple_table()andEngine::on_loaded()deferral.Approach
PleReader(bypassing unified-memory page-cache bloat viaF_NOCACHEon macOS) with a bounded row cache (1,048,576rows /76 MiBdefault) when host RAM is too tight to hold the full PLE table safely alongside routed experts, while keeping explicit--ple-direct/--ple-mmap/STRATA_PLE_DIRECToverrides.gpu::metal::submit()) before waiting onPleReader::collect()so GPU work overlaps SSD reads; drains pending PLE tickets cleanly on~Qwen4(),reset_call(), andon_reset().should_warm_ple_table()onorigin/mainand extendsstart_ple_warmer()to support macOS (getpagesize()stride +MADV_WILLNEED) when mmap mode has sufficient headroom.STRATA_PLE_DIRECTandSTRATA_PLE_CACHE_ROWSinterminal/data/settings-register.jsonand updatesdocs/SETTINGS.md.Validation
cb2ddeconorigin/main7cef952):strata-poly,poly_qwen4_parity,poly_memory_test,poly_memory_growth,poly_runtime_safety,poly_tiny_model_fixture): 0 errors, 0 warnings.ctest --test-dir engine/build-metal -R '^(poly_qwen4_parity|poly_memory_test|poly_memory_growth|poly_metal_defaults|poly_runtime_safety)$' --output-on-failure: 11/11 passed.engine/src/poly/cold_budget_test.cpp: passed (poly_cold_budget_test: ok).python3 tools/check --only docs: passed (6/6).python3 -m unittest tools/test_settings_register.py: passed (8/8).Qwen4-35B-A3B-UD-IQ2_XS, integrated stack onbfd5d1b): PLE direct reader (76.0 MiBcache,F_NOCACHE) kept peak memory footprint at7.4–8.8 GiBacross 8K–32K contexts (13.9–15.5 MiBSSD reads per 192-token decode;612 MiBSSD reads across 32,768-token prompt with58.1%cache hits and100%NIAH recall).backends.yml/check.yml).Limits
>= 32–64 GiB) continue to use mmap +should_warm_ple_table()warmer automatically.