mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
Merge f-ling32-prod 5c0624dd90 (L32-TERM: version-source test fixed, Mac memory floor is a recommendation with a warning instead of a refusal) into the integration staging line
This commit is contained in:
commit
5b4e55c3af
7 files changed
+87
-26
No files matched your search
@@ -41,6 +41,14 @@ void dequant_sk_row(const uint8_t*, SkCode, float*, size_t) noexcept { std::fpri
|
||||
using namespace strata::ling32;
|
||||
|
||||
static double now_s() { return std::chrono::duration<double>(std::chrono::steady_clock::now().time_since_epoch()).count(); }
|
||||
// A Mac with little memory: there is no hard minimum, the advice is 128 GB (the same recommendation as METAL_MIN_RAM_GIB in terminal/strata_control/ling32_family.py). While the model
|
||||
// and the engine buffers are made, a failure of the Metal runtime (it ends the process with exit code 4 and a one-line technical message) is followed by this note in plain words.
|
||||
static std::atomic<bool> g_loading{false};
|
||||
static double g_ws_gib = 0;
|
||||
static void loading_failed_note() {
|
||||
if (!g_loading.load()) return;
|
||||
std::fprintf(stderr, "ling32-metal: this Mac could not hold the model in memory (its GPU allows about %.0f GiB at once). Ling runs best on a Mac with 128 GB or more; with less memory it may not load or be very slow. Close other programs, or use a Mac with more memory.\n", g_ws_gib);
|
||||
}
|
||||
static std::string fmt(const char* f, ...) {
|
||||
char b[4096];
|
||||
va_list ap;
|
||||
@@ -1208,14 +1216,21 @@ int main(int argc, char** argv) {
|
||||
return 0;
|
||||
}
|
||||
Model m;
|
||||
if (!load_model(cx, f, m, o.prefault, err)) { std::fprintf(stderr, "load: %s\n", err.c_str()); return 1; }
|
||||
g_ws_gib = cx.recommended_working_set() / 1073741824.0;
|
||||
std::error_code fsz_ec;
|
||||
const double fsz_gib = double(std::filesystem::file_size(o.model, fsz_ec)) / 1073741824.0; // the model file is what the buffers hold (about 81 GiB); the engine buffers come on top
|
||||
if (!fsz_ec && fsz_gib > g_ws_gib)
|
||||
std::fprintf(stderr, "ling32-metal: warning: the model needs about %.0f GiB and this Mac's GPU allows about %.0f GiB at once; it may not load or be very slow (Ling runs best on a Mac with 128 GB or more)\n", fsz_gib, g_ws_gib);
|
||||
g_loading = true;
|
||||
std::atexit(loading_failed_note);
|
||||
if (!load_model(cx, f, m, o.prefault, err)) { g_loading = false; std::fprintf(stderr, "load: %s\n", err.c_str()); return 1; }
|
||||
Engine E(cx, m);
|
||||
E.mm_min = o.mm_min; E.mm_terms = o.mm_terms; E.moe_mm_min = o.moe_mm_min; E.moe_tm = o.moe_tm; E.moe_g = std::min(4, std::max(1, o.moe_g)); E.mla_kc = o.mla_kc; E.trace_pos = o.trace_pos; E.mm_shared = o.mm_shared; E.mm_tm128 = o.mm_tm128; E.mla_mma = o.mla_mma; E.fast_f32 = o.fast_f32; E.f32_mm = o.f32_mm; E.route_tol = o.route_tol; E.kda_mma = o.kda_mma; E.mla_mmah = o.mla_mmah; E.mla_mpp = o.mla_mpp; E.mla_kch = o.mla_kch; E.mla_thr = o.mla_thr; E.mla_ht4 = o.mla_ht4; E.logits_rows = o.logits_rows;
|
||||
if (o.logits_rows == 0 && o.jobs.empty() && o.dump.empty()) E.logits_rows = 16; // serving and speed runs read the last row(s) only
|
||||
if (!E.init(o.kernels, o.ctx, o.chunk, err)) { std::fprintf(stderr, "init: %s\n", err.c_str()); return 1; }
|
||||
if (!E.init(o.kernels, o.ctx, o.chunk, err)) { g_loading = false; std::fprintf(stderr, "init: %s\n", err.c_str()); return 1; }
|
||||
std::fprintf(stderr, "ling32-metal: engine ready, rss %.1f GiB\n", rss_gib());
|
||||
if (o.spec_mtp) {
|
||||
if (!mtp_init(E, o.mtp, o.spec_k, err)) { std::fprintf(stderr, "mtp: %s\n", err.c_str()); return 1; }
|
||||
if (!mtp_init(E, o.mtp, o.spec_k, err)) { g_loading = false; std::fprintf(stderr, "mtp: %s\n", err.c_str()); return 1; }
|
||||
std::fprintf(stderr, "ling32-metal: rss %.1f GiB with the MTP sidecar\n", rss_gib());
|
||||
}
|
||||
if (o.warm) {
|
||||
@@ -1227,6 +1242,7 @@ int main(int argc, char** argv) {
|
||||
E.reset();
|
||||
std::fprintf(stderr, "ling32-metal: first command buffer (wiring) %.1f s\n", now_s() - tw);
|
||||
}
|
||||
g_loading = false; // the model and the engine buffers are made
|
||||
if (o.serve) { // the protocol goes to a dup of stdout; everything else printed to stdout is moved to stderr
|
||||
l32m_serve::g_out = fdopen(dup(1), "w");
|
||||
dup2(2, 1);
|
||||
|
||||
+13
-11
@@ -10857,20 +10857,22 @@ def install_ling32_air(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adop
|
||||
if not ling32_have(a, pv):
|
||||
left += (ling32_family.FILES[ling32_family.VISION_FILE][0] - (pv.with_name(pv.name + ".part").stat().st_size if pv.with_name(pv.name + ".part").is_file() else 0)) / 1e9
|
||||
args_fit, adv = ling32_engine_args(a, vram_gib, ram_gib, unified, ctx, vision, vision_device, mtp=mtp_on, backend=backend)
|
||||
if backend == "metal" and (adv["tier"] != "A" or float(ram_gib or 0.0) < ling32_family.METAL_MIN_RAM_GIB):
|
||||
fail(f"Ling-3.2-Air on a Mac keeps the whole model in memory (about 84 GiB); this Mac has {float(ram_gib or 0.0):.0f} GB",
|
||||
f"it needs a Mac with {ling32_family.metal_min_ram_words()} of memory (the engine holds about 91 GiB at the default 128K context; a 96 GB Mac cannot)")
|
||||
say()
|
||||
say(f" Memory plan for this PC: tier {adv['tier']} ({ling32_fit.TIER_WORDS[adv['tier']]}), {adv['speed']}" if adv["tier"] else f" Memory plan for this PC: {adv['speed']}")
|
||||
p = adv["plan"]
|
||||
say(f" video memory {p['vram_gb']:.1f} GB (experts + pool), RAM {p['ram_gb']:.1f} GB, SSD {p['ssd_gb']:.1f} GB of experts")
|
||||
if vision:
|
||||
v = p["vision"]
|
||||
say(f" pictures on: the picture reader runs on the {'graphics card (' + str(v['vram_mib']) + ' MiB of its memory, freed when idle)' if v['device'] == 'gpu' else 'processor (about ' + str(v['host_mib']) + ' MiB of RAM; a card of 24 GB or more reads on the card)'}")
|
||||
if backend == "metal": # a Mac keeps the whole model in one memory pool, no tiers: no hard minimum, a clear warning below the recommendation
|
||||
say(f" Memory plan for this Mac: the whole model stays in memory (about 84 GiB, about 91 GiB at the default 128K context), no tiers")
|
||||
if ling32_family.metal_ram_below_advice(ram_gib):
|
||||
warn(f"this Mac has {float(ram_gib):.0f} GB of memory. {ling32_family.metal_ram_advice()}")
|
||||
else:
|
||||
say(" pictures off")
|
||||
for w in adv["warnings"]:
|
||||
warn(w)
|
||||
say(f" Memory plan for this PC: tier {adv['tier']} ({ling32_fit.TIER_WORDS[adv['tier']]}), {adv['speed']}" if adv["tier"] else f" Memory plan for this PC: {adv['speed']}")
|
||||
say(f" video memory {p['vram_gb']:.1f} GB (experts + pool), RAM {p['ram_gb']:.1f} GB, SSD {p['ssd_gb']:.1f} GB of experts")
|
||||
if vision:
|
||||
v = p["vision"]
|
||||
say(f" pictures on: the picture reader runs on the {'graphics card (' + str(v['vram_mib']) + ' MiB of its memory, freed when idle)' if v['device'] == 'gpu' else 'processor (about ' + str(v['host_mib']) + ' MiB of RAM; a card of 24 GB or more reads on the card)'}")
|
||||
else:
|
||||
say(" pictures off")
|
||||
for w in adv["warnings"]:
|
||||
warn(w)
|
||||
if left and free is not None and free < left:
|
||||
fail(f"not enough free disk space in {folder}: need ~{left:.0f} GB, {free:.0f} GB free", ("use --data-dir on a bigger drive (strata launch --data-dir)" if CONTROL else "use --models-dir on a bigger drive"))
|
||||
if left and free is not None and free < left + 1:
|
||||
|
||||
@@ -431,12 +431,14 @@ def check_ling32(s: LaunchSettings, *, vram_gb: float | None, ram_gb: float | No
|
||||
out.append(Notice("warn", "Ling-3.2-Air on AMD: tested on Radeon RX 9070 and Strix Halo class cards (RDNA 4, gfx1201 and gfx1151); other cards run unverified, older ones use slow fallback kernels.",
|
||||
"Windows and Linux; the engine picks its kernels by the card."))
|
||||
elif v == "apple":
|
||||
out.append(Notice("warn", "Ling-3.2-Air on a Mac keeps the whole model in memory (about 84 GiB, no tiers, no pictures yet): it needs a Mac with " + ling32_family.metal_min_ram_words() + " of memory.", "Smaller Macs cannot run it."))
|
||||
low = ling32_family.metal_ram_below_advice(ram_gb)
|
||||
out.append(Notice("warn", "Ling-3.2-Air on a Mac keeps the whole model in memory (about 84 GiB, no tiers, no pictures yet). " + ling32_family.metal_ram_advice(),
|
||||
(f"This Mac has {float(ram_gb):.0f} GB of memory: it is started anyway." if low else "")))
|
||||
elif v and v not in ("nvidia", "cuda"):
|
||||
out.append(Notice("warn", "Ling-3.2-Air runs on NVIDIA, AMD and Apple Silicon computers; this one is none of them.", "It will not start on this computer."))
|
||||
if not adv["plan"]["ok"]:
|
||||
if not adv["plan"]["ok"] and v != "apple":
|
||||
out.append(Notice("warn", adv["plan"]["error"], "The engine would stop at the start with this choice. Take --tier away to let Strata choose."))
|
||||
elif adv["tier"] not in (None, "A"):
|
||||
elif adv["tier"] not in (None, "A") and v != "apple": # a Mac has no tiers (its own notice above)
|
||||
out.append(Notice("warn", f"Memory tier {adv['tier']} ({ling32_fit.TIER_WORDS[adv['tier']]}) on this computer: {adv['speed']}.",
|
||||
"A card with more video memory, or more RAM, moves it up a tier." if adv["tier"] == "B" else "More RAM or video memory shortens the SSD reads; an NVMe drive matters most."))
|
||||
if s.mtp == "on": # asked for by hand: what it is, and the licence (on by default it is part of the plan and says nothing more)
|
||||
|
||||
@@ -77,10 +77,10 @@ ENGINE_FLAGS = {"cuda": ["--tc", "16", "--tc-moe", "128", "--graph", "--mla-kern
|
||||
#: The engine flags that turn the MTP sidecar on, besides `--mtp FILE`: the same on every backend since the Metal program's command line was aligned (L32-METAL f9fbc1d186:
|
||||
#: `--version`, `--info FILE --kv` with mtp=1, `--spec mtp [--spec-adaptive]`; `--mtp FILE` alone only names the sidecar). A Metal engine from before that commit takes `--spec-k K`.
|
||||
MTP_ENGINE_FLAGS = {"cuda": ["--spec", "mtp", "--spec-adaptive"], "hip": ["--spec", "mtp", "--spec-adaptive"], "metal": ["--spec", "mtp", "--spec-adaptive"]}
|
||||
#: AMD cards by gfx name: run in P4 (goldens, speed) / compiled only / anything else. A Mac keeps the whole model in memory (about 84 GiB resident, P6: no tiers), so it needs a 128 GB-class Mac.
|
||||
#: AMD cards by gfx name: run in P4 (goldens, speed) / compiled only / anything else. A Mac keeps the whole model in memory (about 84 GiB resident, P6: no tiers), so it is best on a 128 GB-class Mac (a recommendation, not a minimum).
|
||||
HIP_TESTED = ("gfx1151", "gfx1201")
|
||||
HIP_COMPILED = ("gfx1100", "gfx1101", "gfx1102", "gfx1103", "gfx1150")
|
||||
METAL_MIN_RAM_GIB = 120.0 # owner decision pending (recommended 128 GB, 2026-12-02): the minimum RAM a Mac needs, as the OS reports it (a 128 GB Mac shows 128 GiB). L32-METAL measured 91.4 GiB resident at 128K context and chunk 4096 (m1002, Metal working-set limit 107.5 GiB); the model buffers alone are 81.5 GiB, which a 96 GB Mac cannot hold. One constant: setup.py and the launcher read it
|
||||
METAL_MIN_RAM_GIB = 120.0 # the RAM that Ling is RECOMMENDED to have on a Mac, as the OS reports it (a 128 GB Mac shows 128 GiB): a recommendation only, the owner decided on 2026-12-02 that there is no hard minimum ("anyone can load it, it is just best with at least 128 GB"): below it the installer and the launcher warn and go on. L32-METAL measured 91.4 GiB resident at 128K context and chunk 4096 (m1002, Metal working-set limit 107.5 GiB); the model buffers alone are 81.5 GiB. One constant: setup.py and the launcher read it
|
||||
|
||||
|
||||
def metal_min_ram_words() -> str:
|
||||
@@ -88,6 +88,20 @@ def metal_min_ram_words() -> str:
|
||||
return f"{-(-int(METAL_MIN_RAM_GIB) // 16) * 16} GB"
|
||||
|
||||
|
||||
def metal_ram_below_advice(ram_gib) -> bool:
|
||||
"""True when the Mac's memory is known and below the recommendation (an unknown amount gives no warning)."""
|
||||
try:
|
||||
r = float(ram_gib or 0.0)
|
||||
except (TypeError, ValueError):
|
||||
return False
|
||||
return 0.0 < r < METAL_MIN_RAM_GIB
|
||||
|
||||
|
||||
def metal_ram_advice() -> str:
|
||||
"""The one sentence of the Mac memory warning (installer, launcher and engine say it the same way)."""
|
||||
return f"Ling runs best on a Mac with {metal_min_ram_words()} or more; with less memory it may not load or be very slow."
|
||||
|
||||
|
||||
def backend_of(*, hip: bool = False, darwin: bool = False, sycl: bool = False) -> str:
|
||||
"""The engine backend of this computer: "metal" on a Mac, "hip" with an AMD card, "sycl" for Intel (no engine), else "cuda"."""
|
||||
return "metal" if darwin else "sycl" if sycl else "hip" if hip else "cuda"
|
||||
|
||||
@@ -390,7 +390,7 @@ class Notices(unittest.TestCase):
|
||||
self.assertIn("tested on Radeon RX 9070 and Strix Halo", words("amd")) # AMD has an engine now: tested cards named, the rest "unverified"
|
||||
self.assertNotIn("will not start", words("amd"))
|
||||
self.assertIn("no Intel engine yet", words("intel"))
|
||||
self.assertIn("128 GB of memory", words("apple")) # a Mac keeps the whole model in memory
|
||||
self.assertIn("128 GB or more", words("apple")) # a Mac keeps the whole model in memory: the recommendation, never a refusal
|
||||
self.assertIn("none of them", words("someone-else"))
|
||||
for vendor in ("nvidia", "cuda", None):
|
||||
self.assertNotIn("Ling-3.2-Air on", words(vendor))
|
||||
@@ -515,6 +515,24 @@ class FamilyData(unittest.TestCase):
|
||||
apple = " ".join(n.text for n in S.check_ling32(S.LaunchSettings(family="ling-3.2-air"), vram_gb=None, ram_gb=128, vendor="apple"))
|
||||
self.assertIn("128 GB", apple)
|
||||
|
||||
def test_a_small_mac_gets_a_warning_and_is_started_anyway(self):
|
||||
want = "Ling runs best on a Mac with 128 GB or more; with less memory it may not load or be very slow."
|
||||
self.assertEqual(ling32_family.metal_ram_advice(), want)
|
||||
for ram, low in ((64, True), (96, True), (119.9, True), (120, False), (128, False), (None, False), (0, False)):
|
||||
self.assertEqual(ling32_family.metal_ram_below_advice(ram), low, ram)
|
||||
notes = S.check_ling32(S.LaunchSettings(family="ling-3.2-air"), vram_gb=None, ram_gb=ram, vendor="apple")
|
||||
apple = [n for n in notes if "on a Mac" in n.text]
|
||||
self.assertEqual(len(apple), 1)
|
||||
self.assertIn(want, apple[0].text)
|
||||
self.assertEqual("started anyway" in apple[0].next, low, ram)
|
||||
self.assertEqual([n for n in notes if "Memory tier" in n.text or "cannot" in n.text.lower()], [], ram) # none of the PC tier notices, no refusal
|
||||
|
||||
def test_the_mac_engine_says_it_in_plain_words_and_the_text_follows_the_constant(self):
|
||||
src = (Path(__file__).resolve().parents[3] / "engine" / "src" / "ling32" / "metal" / "ling32_metal_main.cpp").read_text(encoding="utf-8")
|
||||
self.assertIn(f"Ling runs best on a Mac with {ling32_family.metal_min_ram_words()} or more; with less memory it may not load or be very slow", src)
|
||||
self.assertIn("std::atexit(loading_failed_note)", src) # the runtime's exit(4) is followed by the plain note
|
||||
self.assertIn("g_loading = false; // the model and the engine buffers are made", src)
|
||||
|
||||
def test_nothing_is_published_by_default(self):
|
||||
self.assertEqual(ling32_family.sources(env={}), [])
|
||||
got = ling32_family.sources(env={"STRATA_LING32_SOURCE": "https://example.invalid/m/"})
|
||||
|
||||
@@ -144,7 +144,7 @@ class Package(unittest.TestCase):
|
||||
def test_the_version_has_one_source_and_no_program_carries_a_literal(self):
|
||||
repo = PACK.parent.parent
|
||||
cmake = (repo / "engine" / "src" / "ling32" / "CMakeLists.txt").read_text(encoding="utf-8")
|
||||
self.assertIn("project\\(strata VERSION", cmake) # reads the shared engine project line
|
||||
self.assertIn("project\\\\(strata VERSION", cmake) # reads the shared engine project line
|
||||
self.assertIn("LING32_VERSION=", cmake) # and passes it to the program as a define
|
||||
self.assertEqual(engine_version.engine_version(), engine_version.PATTERN.search((repo / "engine" / "CMakeLists.txt").read_text(encoding="utf-8")).group(1))
|
||||
for rel in ("engine/src/ling32/ling32_main.cpp", "engine/src/ling32/metal/ling32_metal_main.cpp"):
|
||||
|
||||
@@ -389,11 +389,20 @@ class Install(unittest.TestCase):
|
||||
self.assertNotIn("--vision", cfg["args"]) # no pictures on a Mac yet
|
||||
self.assertFalse([x for x in cfg["args"] if x in ("--tier", "--vram-budget-gib", "--ram-budget-gib", "--turbo-ssd", "--map-experts")]) # no tiers
|
||||
self.assertIn(ling32_family.MTP_CONFIG_KEY, cfg)
|
||||
with self.assertRaises(SystemExit):
|
||||
self.run_install(backend="metal", ram=64) # a 64 GB Mac cannot hold it
|
||||
with self.assertRaises(SystemExit):
|
||||
self.run_install(backend="metal", ram=96) # nor a 96 GB Mac (L32-METAL: 81.5 GiB of buffers against a working-set limit of about 80 percent of RAM)
|
||||
self.assertEqual(ling32_family.METAL_MIN_RAM_GIB, 120.0)
|
||||
self.assertFalse([s for s in says if "runs best on a Mac" in s]) # 128 GB: no warning
|
||||
self.assertEqual(ling32_family.METAL_MIN_RAM_GIB, 120.0) # the recommendation, kept as one constant
|
||||
|
||||
def test_a_small_mac_is_warned_and_installed_anyway(self):
|
||||
for ram in (64, 96): # no hard minimum (owner, 2026-12-02): "anyone can load it, it is just best with at least 128 GB"
|
||||
_, w, says, _ = self.run_install(backend="metal", ram=ram, mtp_beside=True)
|
||||
cfg = w["cfg"]
|
||||
self.assertEqual(cfg["backend"], "metal") # the install went on and wrote its config
|
||||
self.assertNotIn("--tc", cfg["args"])
|
||||
self.assertFalse([x for x in cfg["args"] if x in ("--tier", "--vram-budget-gib", "--ram-budget-gib", "--turbo-ssd", "--map-experts")]) # a Mac has no tiers
|
||||
warned = [s for s in says if s.startswith("warn") and "runs best on a Mac with 128 GB or more; with less memory it may not load or be very slow" in s]
|
||||
self.assertEqual(len(warned), 1, says)
|
||||
self.assertIn(f"this Mac has {ram} GB", warned[0])
|
||||
self.assertFalse([s for s in says if "SSD" in s and s.startswith("warn")], says) # none of the PC tier warnings
|
||||
|
||||
def test_a_small_card_does_not_download_the_sidecar_by_default(self):
|
||||
with mock.patch.object(setup, "ling32_fetch_mtp", side_effect=AssertionError("fetched")):
|
||||
|
||||
Reference in new issue
Block a user