diff --git a/docs/MAC.md b/docs/MAC.md index 75b9460d..23851a95 100644 --- a/docs/MAC.md +++ b/docs/MAC.md @@ -26,7 +26,7 @@ with 32 GB, where the experts stream from the SSD. Other chips and memory sizes - **The n-gram table:** each pack also has a 28.8 GB n-gram table (the model's second file). It is read from the SSD a few rows at a time and does not count against the memory above. - **Disk:** the download is 66-84 GB, plus about 7 GB for the pack and the draft layer. A Mac that streams also needs room for the experts' copy (below): 34-40 GB. - **A Mac whose memory cannot hold the pack (32-48 GB):** the engine streams the experts from the SSD instead. It decides this by itself when the experts are more than 60% of Metal's share. - - It keeps the most-used experts in an arena: Metal's share, or the memory macOS reports as available less what it keeps for macOS, whichever is smaller. It keeps 5 GB, or 15% of the RAM when that is more, and it also keeps the n-gram table's share. It checks the free memory again just before it takes the arena, and takes less if less is free. + - It keeps the most-used experts in an arena: Metal's share, or the memory macOS reports as available less what it keeps for macOS, whichever is smaller. It keeps 7 GB, or 15% of the RAM when that is more, and it also keeps the n-gram table's share. It checks the free memory again just before it takes the arena, and takes less if less is free. - It reads the rest as each token needs them, and reads ahead the experts the next layer will probably use. - Setup writes a second copy of the experts for such a Mac (`.experts`, 40 GB for IQ3_XXS). In it each expert's three matrices sit together, so the SSD reads an expert with one request instead of three. On the 32 GB M4 that is about 17% faster decoding and 30% faster prompts, with the same tokens. Setup writes it only when the disk has room for it plus 10 GB; otherwise it warns, and the engine reads the model file as before. - Setup configures such a Mac without the MTP draft layer: one token per step is faster there. diff --git a/metal/src/engine/arena_budget.h b/metal/src/engine/arena_budget.h index 05303e4b..261f7757 100644 --- a/metal/src/engine/arena_budget.h +++ b/metal/src/engine/arena_budget.h @@ -3,11 +3,12 @@ // // The arena is anonymous memory the GPU keeps resident: macOS cannot page it out or drop it like file cache. It must // leave room for macOS and the desktop, and for the other big memory the engine itself uses while it runs: -// keep macOS and the desktop: max(5 GB, 15% of the RAM) - STRATA_METAL_KEEP_FREE_GB sets it. The M5 Max +// keep macOS and the desktop: max(7 GB, 15% of the RAM) - STRATA_METAL_KEEP_FREE_GB sets it. The M5 Max // (128 GB) froze with an 89 GB arena and 7 GB kept beside a 50 GB n-gram table; with 15% it keeps 20.6 GB. // The 32 GB M4 (IQ3_XXS after a 6K prompt, 5 interleaved runs, memory_pressure every 3 s, vm_stat // swapouts): 7 GB kept + 2 GB reserve 5.93 tok/s (arena ~8.5 GB, least free 50%), 7 + 0.5 6.59 (~10 GB, -// 49%), 5 + 0.5 7.47 (~12 GB, 43%); no swap-out in any run. +// 49%), 5 + 0.5 7.47 (~12 GB, 43%); no swap-out in any run. But a 34-minute server soak with 5 GB kept +// swapped out 93 MB while its 11.7 GB arena filled (none after): 7 GB again. // ple the n-gram table: mapped whole in RAM (--ple-io ram) it is all of it; read row by row (the default, // F_NOCACHE: no file cache) only its bounded row cache, 1M rows of at most 192 bytes: 0.5 GB reserved. // GPU the Metal working set less what is already allocated, less 1 GB. @@ -32,7 +33,7 @@ struct ArenaMem { constexpr double kGB = 1e9; inline double arena_keep(const ArenaMem& m) { - return m.keep_gb >= 0 ? m.keep_gb * kGB : std::max(5.0 * kGB, 0.15 * m.phys); + return m.keep_gb >= 0 ? m.keep_gb * kGB : std::max(7.0 * kGB, 0.15 * m.phys); } inline double arena_ple_reserve(const ArenaMem& m) { return m.ple_mapped > 0 ? m.ple_mapped : 0.5 * kGB; } diff --git a/metal/src/engine/window.cpp b/metal/src/engine/window.cpp index 08456a3b..aed846c8 100644 --- a/metal/src/engine/window.cpp +++ b/metal/src/engine/window.cpp @@ -1062,7 +1062,7 @@ void stream_atexit() { } // namespace // The arena, once the rest is allocated (the MTP layer loads after init): what the GPU working set and the RAM leave -// with STRATA_METAL_KEEP_FREE_GB kept for macOS (default: 5 GB, or 15% of the RAM when that is more - the M5 Max +// with STRATA_METAL_KEEP_FREE_GB kept for macOS (default: 7 GB, or 15% of the RAM when that is more - the M5 Max // froze with an 89 GB arena and 7 GB left beside a 50 GB n-gram table read through the file cache; arena_budget.h); // STRATA_METAL_ARENA_GB sets it. bool Window::stream_arena(std::string& err) { diff --git a/metal/tests/arena_budget_test.cpp b/metal/tests/arena_budget_test.cpp index 6314ef27..71f7d847 100644 --- a/metal/tests/arena_budget_test.cpp +++ b/metal/tests/arena_budget_test.cpp @@ -24,12 +24,12 @@ int main() { ArenaMem m5r = m5; m5r.ple_mapped = 50.7 * kGB; check(arena_budget(m5r) <= b5 - 48.0 * kGB, "M5 Max, table in RAM: the arena gives up the table's 50.7 GB", arena_budget(m5r)); - // the M4 Mac mini, 32 GB: 15% = 5.16 GB kept + // the M4 Mac mini, 32 GB: the 7 GB floor (15% would be 5.16 GB) ArenaMem m4{34.4 * kGB, 26.8 * kGB, 3.3 * kGB, 17.8 * kGB}; - check(std::fabs(arena_keep(m4) - 5.16 * kGB) < 1e6, "M4 32 GB: macOS keeps 15% (5.16 GB)", arena_keep(m4)); - check(std::fabs(arena_budget(m4) - (17.8 - 5.16 - 0.5) * kGB) < 1e6, "M4 32 GB: available - 5.16 - 0.5", arena_budget(m4)); + check(std::fabs(arena_keep(m4) - 7.0 * kGB) < 1e6, "M4 32 GB: macOS keeps the 7 GB floor", arena_keep(m4)); + check(std::fabs(arena_budget(m4) - (17.8 - 7.0 - 0.5) * kGB) < 1e6, "M4 32 GB: available - 7 - 0.5", arena_budget(m4)); ArenaMem m16{17.2 * kGB, 11 * kGB, 3 * kGB, 9 * kGB}; - check(std::fabs(arena_keep(m16) - 5.0 * kGB) < 1e6, "a 16 GB Mac: the 5 GB floor", arena_keep(m16)); + check(std::fabs(arena_keep(m16) - 7.0 * kGB) < 1e6, "a 16 GB Mac: the 7 GB floor", arena_keep(m16)); // the overrides ArenaMem o = m4; o.keep_gb = 12.0;