Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: compare H3 memory floors against total RAM, and stop driving MLX's wired limit (#5420)

[._.]/ Adam Eivye7c8372d62ae
diff --git a/client/src/components/videoGen/ModelDisclosure.jsx b/client/src/components/videoGen/ModelDisclosure.jsx
index f4051e4516..84c2dcc537 100644
--- a/client/src/components/videoGen/ModelDisclosure.jsx
+++ b/client/src/components/videoGen/ModelDisclosure.jsx
@@ -65,11 +65,12 @@ function MemoryFact({ model, systemMemoryGb }) {
}
// Which weight-placement profile this machine will actually get, for a model
-// that declares them (#5420 — MiniMax H3 today). This is the HONEST capacity
-// fact next to the headline `memoryGb`: that number never accounted for the
-// reserve PortOS keeps for the OS, so a machine sitting exactly on it read as a
-// fit while a render would have taken the whole box. Renders nothing at all for
-// a model with no declared profiles, so no other entry gains a row.
+// that declares them (#5420 — MiniMax H3 today). It is the recipe behind the
+// headline `memoryGb` above: which of the model's placements this box qualifies
+// for, and how much of its memory the render is actually allowed to claim once
+// PortOS's reserve is held back. Both facts gate on the SAME total-RAM
+// comparison, so they can never render contradictory verdicts. Renders nothing
+// at all for a model with no declared profiles, so no other entry gains a row.
function MemoryProfileFact({ model, systemMemoryGb }) {
const { profile, usableGb, floorGb } = selectVideoMemoryProfile(model, systemMemoryGb);
if (floorGb === null) return null;
@@ -77,17 +78,16 @@ function MemoryProfileFact({ model, systemMemoryGb }) {
<Fact label="Memory profile">
{usableGb === null ? (
<>
- Needs {floorGb} GB usable · <span className="text-gray-500">this system: {UNKNOWN}</span>
+ Smallest profile needs {floorGb} GB · <span className="text-gray-500">this system: {UNKNOWN}</span>
</>
) : profile ? (
<span className="text-port-success">
- {profile.name || profile.id} · needs {profile.minMemoryGb} GB usable, this system has {Math.round(usableGb)} GB
- {' '}after the {VIDEO_MEMORY_RESERVE_GB} GB reserve
+ {profile.name || profile.id} · needs {profile.minMemoryGb} GB, and the render may claim
+ {' '}{Math.round(usableGb)} GB after the {VIDEO_MEMORY_RESERVE_GB} GB PortOS reserves for the system
</span>
) : (
<span className="text-port-warning">
- None — the smallest profile needs {floorGb} GB usable and this system has {Math.round(usableGb)} GB
- {' '}after the {VIDEO_MEMORY_RESERVE_GB} GB reserve. Renders are refused rather than started.
+ None — the smallest profile needs {floorGb} GB. Renders are refused rather than started.
</span>
)}
</Fact>
diff --git a/client/src/components/videoGen/ModelDisclosure.test.jsx b/client/src/components/videoGen/ModelDisclosure.test.jsx
index 4967bc5a8e..f43bb27ebe 100644
--- a/client/src/components/videoGen/ModelDisclosure.test.jsx
+++ b/client/src/components/videoGen/ModelDisclosure.test.jsx
@@ -108,14 +108,22 @@ describe('ModelDisclosure', () => {
],
};
- it('names the best profile the usable memory can hold', () => {
+ it('names the best profile the machine can hold, and the budget after the reserve', () => {
renderDisclosure({ backend: 'local', model: PROFILED_MODEL, systemMemoryGb: 128 });
expect(screen.getByText(/Rich placement/)).toBeInTheDocument();
- expect(screen.getByText(/this system has 112 GB/)).toBeInTheDocument();
+ expect(screen.getByText(/may claim 112 GB/)).toBeInTheDocument();
});
- it('steps down to a leaner profile once the reserve puts the richer one out of reach', () => {
+ it('agrees with the headline requirement on a box sitting exactly on the floor', () => {
+ // The two facts gate on the same total-RAM comparison, so a 96 GB box on a
+ // 96 GB requirement can never read as a fit above and a refusal below.
renderDisclosure({ backend: 'local', model: PROFILED_MODEL, systemMemoryGb: 96 });
+ expect(screen.queryByText(/below the stated minimum/)).not.toBeInTheDocument();
+ expect(screen.getByText(/Rich placement/)).toBeInTheDocument();
+ });
+
+ it('steps down to a leaner profile when the richer one is out of reach', () => {
+ renderDisclosure({ backend: 'local', model: PROFILED_MODEL, systemMemoryGb: 64 });
expect(screen.getByText(/Lean placement/)).toBeInTheDocument();
});
@@ -126,7 +134,7 @@ describe('ModelDisclosure', () => {
it('says Unknown rather than "too small" when the system memory is unmeasured', () => {
render(<ModelDisclosure backendDisclosures={BACKENDS} backend="local" model={PROFILED_MODEL} />);
- expect(screen.getByText(/Needs 48 GB usable/)).toBeInTheDocument();
+ expect(screen.getByText(/Smallest profile needs 48 GB/)).toBeInTheDocument();
expect(screen.queryByText(/Renders are refused/)).not.toBeInTheDocument();
});
diff --git a/client/src/lib/videoGenParams.js b/client/src/lib/videoGenParams.js
index 817ca8f093..288123db22 100644
--- a/client/src/lib/videoGenParams.js
+++ b/client/src/lib/videoGenParams.js
@@ -233,23 +233,26 @@ export const videoModelMemoryGb = (model) => {
return match ? Number(match[1]) : Number.POSITIVE_INFINITY;
};
-// Host RAM PortOS holds back for the operating system and itself before a
-// MiniMax H3 render may claim the rest. Mirrors MINIMAX_H3_HOST_RESERVE_GB in
-// server/lib/minimaxH3Memory.js — the only number mirrored here, because the
-// per-profile floors ride on the model entry the client already fetches.
+// Host RAM PortOS holds back from a MiniMax H3 render's ALLOCATOR for the OS and
+// itself. Mirrors MINIMAX_H3_HOST_RESERVE_GB in server/lib/minimaxH3Memory.js —
+// the only number mirrored here, because the per-profile floors ride on the
+// model entry the client already fetches — and pinned by
+// server/lib/minimaxH3Memory.test.js. It is reported, never subtracted before
+// comparing against a profile's floor: those floors are total-RAM claims, so
+// netting it off first would put the 128 GB model out of reach of a 128 GB box.
export const VIDEO_MEMORY_RESERVE_GB = 16;
// The weight-placement profile this machine can hold, out of the ones the model
// declares (#5420). Entries carry `memoryProfiles` best-first, each with an
-// honest `minMemoryGb` host floor, so the picker and the disclosure can state
-// the capacity a render will REALLY need instead of the single headline
-// `memoryGb` that never accounted for what the OS keeps.
+// honest `minMemoryGb` total-RAM floor, so the disclosure can name the recipe a
+// render will really get rather than only the headline `memoryGb`.
//
// Returns `{ profile, usableGb, floorGb }`:
// profile the best profile that fits, or `null` when none does
-// usableGb system memory minus the reserve, or `null` when unmeasured — the
-// "not measured" sentinel, deliberately distinct from a small number
-// so an absent /status field never renders as "this box is too small"
+// usableGb system memory minus the reserve — what the allocator is actually
+// capped at — or `null` when unmeasured. That null is the "not
+// measured" sentinel, deliberately distinct from a small number so an
+// absent /status field never renders as "this box is too small".
// floorGb the smallest floor any declared profile has, so a UI that has to
// say what it would take has the number
export const selectVideoMemoryProfile = (model, systemMemoryGb) => {
@@ -261,14 +264,13 @@ export const selectVideoMemoryProfile = (model, systemMemoryGb) => {
.filter((floor) => Number.isFinite(floor) && floor > 0);
const floorGb = floors.length > 0 ? Math.min(...floors) : null;
const system = Number(systemMemoryGb);
- const usableGb = Number.isFinite(system) && system > 0
- ? Math.max(0, system - VIDEO_MEMORY_RESERVE_GB)
- : null;
+ const measured = Number.isFinite(system) && system > 0 ? system : null;
+ const usableGb = measured === null ? null : Math.max(0, measured - VIDEO_MEMORY_RESERVE_GB);
if (profiles.length === 0) return { profile: null, usableGb, floorGb };
- if (usableGb === null) return { profile: profiles[0], usableGb, floorGb };
+ if (measured === null) return { profile: profiles[0], usableGb, floorGb };
const profile = profiles.find((candidate) => {
const floor = Number(candidate.minMemoryGb);
- return !Number.isFinite(floor) || floor <= 0 || usableGb >= floor;
+ return !Number.isFinite(floor) || floor <= 0 || measured >= floor;
}) || null;
return { profile, usableGb, floorGb };
};
diff --git a/scripts/_minimax_h3_common.py b/scripts/_minimax_h3_common.py
index 19a75016e1..35a97f2621 100644
--- a/scripts/_minimax_h3_common.py
+++ b/scripts/_minimax_h3_common.py
@@ -72,9 +72,10 @@ def add_h3_common_args(
parser.add_argument("--memory-profile", default=None,
help="id of the weight-placement profile PortOS selected (reported back, not re-derived)")
parser.add_argument("--min-system-memory-gb", type=float, default=None,
- help="host RAM below which NO declared placement profile can run")
+ help="TOTAL host RAM below which NO declared placement profile can run")
parser.add_argument("--memory-headroom-gb", type=float, default=0.0,
- help="host RAM held back for the operating system and PortOS itself")
+ help="host RAM held back from the model's ALLOCATOR for the OS and PortOS itself; "
+ "never netted off before the --min-system-memory-gb comparison")
return parser
@@ -124,7 +125,7 @@ def total_system_memory_gb() -> float | None:
def enforce_system_memory(args) -> float | None:
- """Refuse a render this machine cannot hold, and return the usable RAM.
+ """Refuse a render this machine cannot hold, and return the measured RAM.
H3's components fit nowhere unassisted, so loading them takes minutes to
hours before an out-of-memory kill would land — long after the job has taken
@@ -132,23 +133,27 @@ def enforce_system_memory(args) -> float | None:
half, which catches a render that reached the helper by any other route
(a persisted-queue replay, a retry, a peer submission, a direct call).
+ Compared against TOTAL memory, deliberately: the floor PortOS passes was
+ hoisted from the registry entry's `memoryGb`, which has always been a claim
+ about the whole machine. `--memory-headroom-gb` caps the ALLOCATOR further
+ down; netting it off here as well would move the 128 GB model onto a 144 GB
+ box and refuse every machine the entry was written for.
+
Fails closed only on a MEASURED shortfall: an unmeasurable host returns None
and the render proceeds, because "the probe returned nothing" is not the
- same fact as "this box has no memory".
+ same fact as "this box has no memory". Returning the measured total means a
+ caller that also needs it does not probe the machine twice.
"""
total_gb = total_system_memory_gb()
if total_gb is None:
return None
- headroom_gb = max(0.0, args.memory_headroom_gb or 0.0)
- usable_gb = max(0.0, total_gb - headroom_gb)
minimum = args.min_system_memory_gb
- if minimum is not None and usable_gb < minimum:
+ if minimum is not None and total_gb < minimum:
raise SystemExit(
f"MiniMax H3 needs at least {minimum:.0f} GB of memory for its smallest weight-placement "
- f"profile. This machine has {total_gb:.0f} GB, of which {usable_gb:.0f} GB is usable after "
- f"the {headroom_gb:.0f} GB reserve PortOS keeps for the operating system."
+ f"profile; this machine has {total_gb:.0f} GB."
)
- return usable_gb
+ return total_gb
def snapshot_root(resolved_file: str | Path, repo_filename: str) -> Path:
diff --git a/scripts/_minimax_h3_common.test.js b/scripts/_minimax_h3_common.test.js
index c71c4c8810..deb00ae64a 100644
--- a/scripts/_minimax_h3_common.test.js
+++ b/scripts/_minimax_h3_common.test.js
@@ -112,14 +112,15 @@ describe.skipIf(!pyBin)('_minimax_h3_common.py — checkpoint facts shared by bo
' print(f"REJECTED:{exc}")',
].join('\n')}`).trim();
- it('refuses a measured box below the floor once the reserve is taken out', () => {
- // 128 GB nameplate against a 128 GB floor used to read as a fit; it is
- // 112 GB usable, which is the number the render actually gets.
- expect(enforce({ total: 128, minimum: 128 })).toMatch(/^REJECTED:.*at least 128 GB.*112 GB is usable/);
+ it('refuses a measured box below the floor', () => {
+ expect(enforce({ total: 96, minimum: 128 })).toMatch(/^REJECTED:.*at least 128 GB.*has 96 GB/);
});
- it('accepts a box with the floor still free after the reserve', () => {
- expect(enforce({ total: 144, minimum: 128 })).toBe('OK:128.0');
+ it('accepts the machine the floor was written for, reserve NOT netted off first', () => {
+ // The floor is a total-RAM claim hoisted from the entry's `memoryGb`.
+ // Subtracting the allocator reserve here as well would move the 128 GB
+ // model onto a 144 GB box and refuse every Mac the entry describes.
+ expect(enforce({ total: 128, minimum: 128 })).toBe('OK:128.0');
});
it('proceeds, rather than refusing, when the host could not be measured', () => {
@@ -127,7 +128,7 @@ describe.skipIf(!pyBin)('_minimax_h3_common.py — checkpoint facts shared by bo
});
it('is a no-op when PortOS passed no floor', () => {
- expect(enforce({ total: 8, minimum: null })).toBe('OK:0.0');
+ expect(enforce({ total: 8, minimum: null })).toBe('OK:8.0');
});
});
diff --git a/scripts/generate_minimax_h3.py b/scripts/generate_minimax_h3.py
index d84c6f6684..141d812c14 100644
--- a/scripts/generate_minimax_h3.py
+++ b/scripts/generate_minimax_h3.py
@@ -14,9 +14,9 @@ Memory: unified memory means this render and the rest of the machine draw on one
pool. PortOS passes the host floor its declared placement profile needs
(`--min-system-memory-gb`) and the reserve it holds back for the operating
system (`--memory-headroom-gb`); `enforce_system_memory` refuses a box below the
-floor before any weight is read, and `apply_memory_limit` caps MLX's allocator
-at the rest so a render that overruns fails as a job instead of wedging the
-machine.
+floor before any weight is read (against TOTAL RAM — the reserve is not netted
+off first), and `apply_memory_limit` caps MLX's allocator at the rest so a
+render that overruns fails as a job instead of wedging the machine.
"""
from __future__ import annotations
@@ -39,7 +39,7 @@ from _runner_common import ( # noqa: E402
)
from _minimax_h3_common import ( # noqa: E402
FPS, add_h3_common_args, emit_result, enforce_system_memory, load_keyframes,
- resolve_cached_snapshot, total_system_memory_gb, validate_h3_output_args,
+ resolve_cached_snapshot, validate_h3_output_args,
)
from _minimax_h3_mlx_pins import ( # noqa: E402
pinned_encoder_hook, verify_pinned_encode_source,
@@ -82,7 +82,7 @@ def parse_args() -> argparse.Namespace:
return parser.parse_args()
-def apply_memory_limit(args: argparse.Namespace, vision_loaded: bool) -> None:
+def apply_memory_limit(args: argparse.Namespace, total_gb: float | None, vision_loaded: bool) -> None:
"""Cap MLX's allocator at the machine's RAM minus PortOS's reserve.
Unified memory means an H3 render and the rest of the machine draw on the
@@ -92,44 +92,45 @@ def apply_memory_limit(args: argparse.Namespace, vision_loaded: bool) -> None:
rather than a failed job. An explicit limit converts that into an
out-of-memory error the runner reports normally.
- Best-effort by design: the limit setters have moved between `mx` and
- `mx.metal` across MLX releases and the wired limit is Metal-only, so each is
- probed rather than assumed. A pin without them still renders — it just keeps
- the old unbounded behaviour, which is what it had before this existed.
+ Only the ALLOCATOR limit is set. The wired limit is a different lever with a
+ much lower safe ceiling — MLX raises when it is set above the recommended
+ max working set, which on a 128 GB Mac is well under RAM-minus-reserve — so
+ driving it from this number would kill the runner outright. It stays at the
+ pin's own default until someone measures a value for it.
+
+ Best-effort by design: the setter has moved between `mx` and `mx.metal`
+ across MLX releases and can reject a limit this build dislikes, so both the
+ lookup and the call are guarded. An MLX without it still renders — it just
+ keeps the unbounded behaviour it had before this existed, which is why a
+ failure here is reported rather than raised.
"""
- total_gb = total_system_memory_gb()
+ profile = args.memory_profile or 'unified'
+ tower = 'loaded' if vision_loaded else 'skipped'
headroom_gb = max(0.0, args.memory_headroom_gb or 0.0)
if total_gb is None:
print(
- f"STATUS:MiniMax H3 placement: {args.memory_profile or 'unified'} "
- f"· host memory unknown, allocator left unbounded "
- f"· vision tower {'loaded' if vision_loaded else 'skipped'}",
+ f"STATUS:MiniMax H3 placement: {profile} "
+ f"· host memory unknown, allocator left unbounded · vision tower {tower}",
file=sys.stderr, flush=True,
)
return
limit_gb = max(1.0, total_gb - headroom_gb)
- limit_bytes = int(limit_gb * 1e9)
import mlx.core as mx
- applied = []
- for module, name in ((mx, "set_memory_limit"), (getattr(mx, "metal", None), "set_memory_limit")):
- setter = getattr(module, name, None)
- if setter is not None:
- setter(limit_bytes)
- applied.append("allocator")
- break
- for module, name in ((mx, "set_wired_limit"), (getattr(mx, "metal", None), "set_wired_limit")):
- setter = getattr(module, name, None)
- if setter is not None:
- setter(limit_bytes)
- applied.append("wired")
- break
- placement = ", ".join(applied) if applied else "no limit lever on this MLX build"
+ setter = getattr(mx, "set_memory_limit", None) or getattr(getattr(mx, "metal", None), "set_memory_limit", None)
+ if setter is None:
+ applied = "no allocator limit on this MLX build"
+ else:
+ try:
+ setter(int(limit_gb * 1e9))
+ applied = f"allocator capped at {limit_gb:.0f} GB"
+ except Exception as exc: # a pin that rejects the limit must not lose the render
+ applied = f"allocator cap rejected by MLX ({type(exc).__name__}: {exc})"
print(
- f"STATUS:MiniMax H3 placement: {args.memory_profile or 'unified'} "
- f"· {limit_gb:.0f} GB of {total_gb:.0f} GB (reserve {headroom_gb:.0f} GB) [{placement}] "
- f"· vision tower {'loaded' if vision_loaded else 'skipped'}",
+ f"STATUS:MiniMax H3 placement: {profile} "
+ f"· {total_gb:.0f} GB RAM, reserve {headroom_gb:.0f} GB [{applied}] "
+ f"· vision tower {tower}",
file=sys.stderr, flush=True,
)
@@ -655,11 +656,11 @@ def main() -> int:
# Capacity before anything is loaded. PortOS gates this at submit time too;
# this is the runner-side half, which also catches a render that reached the
# helper by another route (a persisted-queue replay, a retry, a direct call).
- enforce_system_memory(args)
+ total_memory_gb = enforce_system_memory(args)
# `images` decides whether the Qwen3-VL vision tower loads at all, so the
# placement report can state what is actually resident rather than what the
# entry could hold in the worst case.
- apply_memory_limit(args, vision_loaded=bool(images))
+ apply_memory_limit(args, total_memory_gb, vision_loaded=bool(images))
runtime_dir = Path(args.runtime_dir).resolve()
verify_runtime_checkout(runtime_dir, args.runtime_revision)
diff --git a/scripts/generate_minimax_h3_cuda.py b/scripts/generate_minimax_h3_cuda.py
index 287db866d8..ad5aa02ae2 100644
--- a/scripts/generate_minimax_h3_cuda.py
+++ b/scripts/generate_minimax_h3_cuda.py
@@ -50,8 +50,8 @@ MAX_FRAMES = 345 # last 17n+5 grid point at or below 15 seconds
OFFLOAD_PROFILES = ("auto", "bf16", "int8-stream", "int8-lean")
# Device-VRAM floor per recipe, richest first. This is the same table PortOS
-# declares in server/lib/minimaxH3Memory.js (pinned by runtimes.test.js), and it
-# is now a FLOOR rather than a one-way ladder: a card below the leanest entry
+# declares in server/lib/minimaxH3Memory.js (pinned by its own test suite), and
+# it is now a FLOOR rather than a one-way ladder: a card below the leanest entry
# gets a clean error naming what it would take, instead of the leanest recipe
# and an out-of-memory kill an hour into the load. An explicitly pinned profile
# is checked against it too — the registry entry syncs between peers and can
@@ -273,14 +273,13 @@ def main() -> int:
# Both halves of the capacity gate, before the multi-GB load rather than
# after it: the host floor (which is where the int8 recipes keep ~75 GB of
# weights resident for the whole render) and the device floor.
- usable_host_gb = enforce_system_memory(args)
+ total_host_gb = enforce_system_memory(args)
profile, vram_gb = resolve_offload_profile(args.offload_profile)
- host_report = "host memory unknown" if usable_host_gb is None else f"{usable_host_gb:.0f} GB usable host memory"
+ host_report = "host memory unknown" if total_host_gb is None else f"{total_host_gb:.0f} GB host RAM"
log(
f"STATUS:MiniMax H3 CUDA placement: {profile} "
f"({'pinned' if args.offload_profile != 'auto' else 'auto'}) "
- f"· {vram_gb:.0f} GB VRAM · {host_report} "
- f"(reserve {max(0.0, args.memory_headroom_gb or 0.0):.0f} GB)"
+ f"· {vram_gb:.0f} GB VRAM · {host_report}"
)
log("STAGE:load-pipeline")
diff --git a/server/lib/minimaxH3Memory.js b/server/lib/minimaxH3Memory.js
index 7366b4d533..1bf5f18df9 100644
--- a/server/lib/minimaxH3Memory.js
+++ b/server/lib/minimaxH3Memory.js
@@ -50,13 +50,20 @@
*/
/**
- * Host RAM held back from the model, in GB.
+ * Host RAM held back from the model's allocator, in GB.
*
* A render is not the only thing on the machine: PortOS itself, Postgres, the
* client build and the OS all need to stay resident, and an H3 render that
* consumes the last gigabyte takes the install down with it rather than
* failing. This is a deliberate policy reserve — the only number in this module
* that is not lifted from an existing runner-proven constant.
+ *
+ * It caps the ALLOCATOR (`apply_memory_limit` in scripts/generate_minimax_h3.py)
+ * and is reported beside the requirement; it is deliberately NOT subtracted
+ * before comparing against `minMemoryGb`. Those floors were hoisted from the
+ * entries' `memoryGb`, which has always been a claim about TOTAL system memory,
+ * so netting the reserve off first would silently move the 128 GB model onto a
+ * 144 GB machine — refusing every box the entry was written for.
*/
export const MINIMAX_H3_HOST_RESERVE_GB = 16;
@@ -74,10 +81,11 @@ export const MINIMAX_H3_AUTO_PROFILE_ID = 'auto';
*
* id stable key. On the CUDA lane this IS the `--offload-profile`
* value the runner takes, so the two cannot name a recipe
- * differently (pinned by runtimes.test.js).
+ * differently (pinned by minimaxH3Memory.test.js).
* name label for the UI
* description one line stating what the recipe actually does
- * minMemoryGb host-RAM floor, EXCLUSIVE of MINIMAX_H3_HOST_RESERVE_GB
+ * minMemoryGb TOTAL host-RAM floor — the same quantity the entry's
+ * `memoryGb` has always stated, not a post-reserve figure
* minVramGb device-VRAM floor, or null when the device memory IS the host
* memory (Apple unified memory)
* unified true when host and device memory are the same pool
@@ -186,7 +194,9 @@ export const miniMaxH3MemoryProfiles = (model) => (
);
/**
- * Usable host RAM after the reserve, or `null` when capacity wasn't measured.
+ * Host RAM left for the model's allocator after the reserve, or `null` when
+ * capacity wasn't measured. Reported and used to cap the allocator — NOT the
+ * quantity profile floors are compared against (see the reserve's docblock).
*
* `null` is the sentinel for "not measured" and is deliberately distinct from
* a measured small number — a capacity probe that returned nothing must not
@@ -198,13 +208,13 @@ export const miniMaxH3UsableMemoryGb = (totalMemoryGb) => {
};
/**
- * The best profile this box's HOST memory can hold, plus what it was measured
- * against. VRAM is deliberately not considered here: the server has no
+ * The best profile this box's total host memory can hold, plus what it was
+ * measured against. VRAM is deliberately not considered here: the server has no
* synchronous view of the device, and the runner — which does — re-selects on
* the same table before it loads anything.
*
* @returns {{ profile, usableMemoryGb, totalMemoryGb }} with `profile: null`
- * when the model declares none or nothing fits. `usableMemoryGb: null` means
+ * when the model declares none or nothing fits. `totalMemoryGb: null` means
* the host was not measured, in which case the best declared profile is
* returned unjudged for the runner to confirm.
*/
@@ -213,10 +223,10 @@ export const selectMiniMaxH3MemoryProfile = ({ model, totalMemoryGb } = {}) => {
const usableMemoryGb = miniMaxH3UsableMemoryGb(totalMemoryGb);
const total = positiveNumber(totalMemoryGb);
if (profiles.length === 0) return { profile: null, usableMemoryGb, totalMemoryGb: total };
- if (usableMemoryGb === null) return { profile: profiles[0], usableMemoryGb, totalMemoryGb: total };
+ if (total === null) return { profile: profiles[0], usableMemoryGb, totalMemoryGb: total };
const profile = profiles.find((candidate) => {
const floor = positiveNumber(candidate.minMemoryGb);
- return floor === null || usableMemoryGb >= floor;
+ return floor === null || total >= floor;
}) || null;
return { profile, usableMemoryGb, totalMemoryGb: total };
};
@@ -241,15 +251,14 @@ const smallestHostFloorGb = (profiles) => profiles.reduce((smallest, profile) =>
export const miniMaxH3MemoryDeclineReason = ({ model, modelId, totalMemoryGb } = {}) => {
const profiles = miniMaxH3MemoryProfiles(model);
if (profiles.length === 0) return null;
- const { profile, usableMemoryGb } = selectMiniMaxH3MemoryProfile({ model, totalMemoryGb });
- if (usableMemoryGb === null || profile) return null;
+ const { profile, totalMemoryGb: measured } = selectMiniMaxH3MemoryProfile({ model, totalMemoryGb });
+ if (measured === null || profile) return null;
const floor = smallestHostFloorGb(profiles);
const name = model?.name || modelId || model?.id || 'This model';
return {
code: 'MINIMAX_H3_MEMORY_INSUFFICIENT',
message: `${name} needs at least ${floor} GB of memory for its smallest weight-placement profile. `
- + `This machine has ${Math.round(Number(totalMemoryGb))} GB, of which ${Math.round(usableMemoryGb)} GB is usable `
- + `after the ${MINIMAX_H3_HOST_RESERVE_GB} GB reserve PortOS keeps for the operating system. `
+ + `This machine has ${Math.round(measured)} GB. `
+ `Render on a peer with more memory, or pick a smaller model.`,
};
};
diff --git a/server/lib/minimaxH3Memory.test.js b/server/lib/minimaxH3Memory.test.js
index 3ea9f9def9..6ed58f141d 100644
--- a/server/lib/minimaxH3Memory.test.js
+++ b/server/lib/minimaxH3Memory.test.js
@@ -58,24 +58,20 @@ describe('applyMiniMaxH3MemoryProfiles', () => {
});
describe('selectMiniMaxH3MemoryProfile', () => {
- it('picks the richest CUDA profile the usable host memory can hold', () => {
+ it('picks the richest CUDA profile this host can hold, and reports the allocator budget', () => {
const model = decorated(cudaEntry());
- const { profile, usableMemoryGb } = selectMiniMaxH3MemoryProfile({
- model,
- totalMemoryGb: 96 + MINIMAX_H3_HOST_RESERVE_GB,
- });
+ const { profile, usableMemoryGb } = selectMiniMaxH3MemoryProfile({ model, totalMemoryGb: 96 });
expect(profile.id).toBe('bf16');
- expect(usableMemoryGb).toBe(96);
+ expect(usableMemoryGb).toBe(96 - MINIMAX_H3_HOST_RESERVE_GB);
});
- it('subtracts the reserve, so a box sitting exactly on the headline floor does NOT fit', () => {
- // The whole point of the reserve: 128 GB nameplate against a 128 GB floor
- // used to read as a fit while a render would have claimed the whole machine.
+ it('gates on TOTAL memory, so the machine the entry was written for still qualifies', () => {
+ // The floors were hoisted from `memoryGb`, which has always been a total-RAM
+ // claim. Netting the reserve off before the comparison would silently move
+ // the 128 GB model onto a 144 GB box and 400 every render on a 128 GB Mac.
const model = decorated(mlxEntry());
- expect(selectMiniMaxH3MemoryProfile({ model, totalMemoryGb: 128 }).profile).toBeNull();
- expect(
- selectMiniMaxH3MemoryProfile({ model, totalMemoryGb: 128 + MINIMAX_H3_HOST_RESERVE_GB }).profile.id,
- ).toBe('unified-8bit');
+ expect(selectMiniMaxH3MemoryProfile({ model, totalMemoryGb: 128 }).profile.id).toBe('unified-8bit');
+ expect(selectMiniMaxH3MemoryProfile({ model, totalMemoryGb: 127 }).profile).toBeNull();
});
it('defers to the runner when the host was not measured', () => {
@@ -97,7 +93,6 @@ describe('miniMaxH3MemoryDeclineReason', () => {
expect(reason.code).toBe('MINIMAX_H3_MEMORY_INSUFFICIENT');
expect(reason.message).toContain('128 GB');
expect(reason.message).toContain('64 GB');
- expect(reason.message).toContain(`${MINIMAX_H3_HOST_RESERVE_GB} GB reserve`);
});
it('stays null for a box that fits, an unmeasured host, and a model with no table', () => {
@@ -141,20 +136,35 @@ describe('validateMiniMaxH3MemoryProfileTable / sanitize', () => {
});
});
-// The CUDA runner re-selects a recipe from the device's VRAM, which the server
-// cannot see. That only stays honest while its floors agree with the ones this
-// module declares and the UI renders — hand-synced across a language boundary,
-// the same shape MINIMAX_H3_CUDA_OFFLOAD_PROFILES already has.
-describe('CUDA VRAM floors', () => {
- it('match PROFILE_MIN_VRAM_GB in the Python runner', () => {
- const runner = readFileSync(
- join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'scripts', 'generate_minimax_h3_cuda.py'),
- 'utf8',
- );
- const declared = runner.match(/^PROFILE_MIN_VRAM_GB = \((.*)\)$/m);
+const repoFile = (...parts) => readFileSync(
+ join(dirname(fileURLToPath(import.meta.url)), '..', '..', ...parts),
+ 'utf8',
+);
+
+// Two constants are hand-synced out of this module — one across a language
+// boundary, one across the client boundary. Both are read as TEXT rather than
+// imported: the Python one cannot be imported at all, and importing the client
+// module into a server suite drags client-only deps into CI (they are separate
+// workspaces). This is the same shape MINIMAX_H3_CUDA_OFFLOAD_PROFILES already
+// has in runtimes.test.js.
+describe('hand-synced mirrors', () => {
+ it('CUDA VRAM floors match PROFILE_MIN_VRAM_GB in the Python runner', () => {
+ // The runner re-selects a recipe from the device's VRAM, which the server
+ // cannot see; that only stays honest while the two tables agree.
+ const declared = repoFile('scripts', 'generate_minimax_h3_cuda.py')
+ .match(/^PROFILE_MIN_VRAM_GB = \((.*)\)$/m);
expect(declared).not.toBeNull();
const fromPython = [...declared[1].matchAll(/\("([^"]+)",\s*(\d+)\)/g)]
.map(([, id, floor]) => ({ id, minVramGb: Number(floor) }));
expect(fromPython).toEqual(CUDA_SPEC.profiles.map(({ id, minVramGb }) => ({ id, minVramGb })));
});
+
+ it('the host reserve matches VIDEO_MEMORY_RESERVE_GB in the client', () => {
+ // The client states how much of the box a render may claim. A drift here
+ // would have the disclosure promise a budget the runner never applies.
+ const declared = repoFile('client', 'src', 'lib', 'videoGenParams.js')
+ .match(/^export const VIDEO_MEMORY_RESERVE_GB = (\d+);$/m);
+ expect(declared).not.toBeNull();
+ expect(Number(declared[1])).toBe(MINIMAX_H3_HOST_RESERVE_GB);
+ });
});