You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0261dcc
Browse filesBrowse the repository at this point in the historyBrowse files
Flash Next hosts hold their residency set only while it fits the GPU's working set
On a 256 GB M5 Ultra a 195.8 GiB set (four 262K sessions) slowed the GPU-side rounds about threefold, while sets under
the working set held them at speed (BobClawblaw on ashhart#606). Both hosts now hold the set only while its buffers, the
prompt cache's budget and a 2 GiB margin fit recommendedMaxWorkingSetSize, and log which way it went.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
/// macOS unwires GPU memory after 1-2 s idle and the next request re-wires it all (2 s before its first token): the
44
44
/// engine's buffers, every session's and the tower's join one residency set the idle keepalive uses.
45
-
fnholdResident(h: *Host) !void {
45
+
/// Only while the set, the prompt cache's `cache` bytes and a margin fit the GPU's recommended working set: a set past it
46
+
/// slowed the GPU-side rounds about threefold on a 256 GB M5 Ultra (#606: 195.8 GiB held), one under it holds them at speed.
47
+
fnholdResident(h: *Host, cache: u64) !void {
46
48
varlist: std.ArrayList(mtl.Buffer) =.empty;
47
49
deferlist.deinit(h.gpa);
48
50
trylist.appendSlice(h.gpa, h.eng.r.held.items);
49
51
for (h.back.sessions) |s|trylist.appendSlice(h.gpa, s.owned.items);
50
52
trylist.append(h.gpa, h.back.hidden.b);
51
53
if (h.vision) |v|trylist.appendSlice(h.gpa, &v.tower.buffers());
54
+
varbytes: u64=0;
55
+
for (list.items) |b|bytes+=b.length();
56
+
constroom=h.eng.r.device.maxWorkingSet();
57
+
if (bytes+|cache+|fit.MARGIN>room) {
58
+
std.log.warn("flash next: no residency set: its {d:.1} GiB and the prompt cache's {d:.1} GiB pass the GPU's {d:.1} GiB working set; the first request after an idle second waits for the model's memory", .{ fit.gibs(bytes), fit.gibs(cache), fit.gibs(room) });
std.log.info("flash next: {d} buffers ({d:.1} GiB) held resident between requests", .{ list.items.len, fit.gibs(h.resident.?.set.allocatedSize()) });
63
+
std.log.info("flash next: {d} buffers ({d:.1} GiB) held resident between requests, under the GPU's {d:.1} GiB working set", .{ list.items.len, fit.gibs(h.resident.?.set.allocatedSize()), fit.gibs(room) });
55
64
}
56
65
57
66
/// What the sessions may take the server to: 70% of RAM, or FLASHNEXT_LOAD_LIMIT_GB (GB, as GLM_LOAD_LIMIT_GB) up to the
if (std.c.getenv("FLASHNEXT_NO_RESIDENCY") ==null) holdResident(h) catch|err|std.log.warn("flash next: no residency set ({s}): the first request after an idle second re-wires the model", .{@errorName(err)});
187
+
if (std.c.getenv("FLASHNEXT_NO_RESIDENCY") ==null) holdResident(h, plan.budget_bytes) catch|err|std.log.warn("flash next: no residency set ({s}): the first request after an idle second re-wires the model", .{@errorName(err)});
// macOS unwires GPU memory after 1-2 s idle and the next request re-wires it all: one set the idle keepalive uses
488
-
if (std.c.getenv("FLASHNEXT_NO_RESIDENCY") ==null) holdResident(h) catch|err|std.log.warn("flash next: no residency set ({s}): the first request after an idle second re-wires the model", .{@errorName(err)});
488
+
if (std.c.getenv("FLASHNEXT_NO_RESIDENCY") ==null) holdResident(h, budget) catch|err|std.log.warn("flash next: no residency set ({s}): the first request after an idle second re-wires the model", .{@errorName(err)});
/// The engine's buffers and the tower's in one residency set; the idle keepalive's ticks use it.
502
-
fnholdResident(h: *Host) !void {
502
+
/// Only while the set, the prompt cache's `cache` bytes and a margin fit the GPU's recommended working set: a set past it
503
+
/// slowed the GPU-side rounds about threefold on a 256 GB M5 Ultra (#606: 195.8 GiB held), one under it holds them at speed.
504
+
fnholdResident(h: *Host, cache: u64) !void {
503
505
varlist: std.ArrayList(mtl.Buffer) =.empty;
504
506
deferlist.deinit(h.gpa);
505
507
trylist.appendSlice(h.gpa, h.eng.r.held.items);
506
508
if (h.vision) |v|trylist.appendSlice(h.gpa, &v.tower.buffers());
509
+
varbytes: u64=0;
510
+
for (list.items) |b|bytes+=b.length();
511
+
constroom=h.eng.r.device.maxWorkingSet();
512
+
if (bytes+|cache+|cache_fit.MARGIN>room) {
513
+
std.log.warn("flash next: no residency set: its {d:.1} GiB and the prompt cache's {d:.1} GiB pass the GPU's {d:.1} GiB working set; the first request after an idle second waits for the model's memory", .{ cache_fit.gibs(bytes), cache_fit.gibs(cache), cache_fit.gibs(room) });
0 commit comments