Files
leleka/engine/strata/tools/test_setup_lowram.py
T
Pavlo RatushnyiandClaude Sonnet 5.5 87e2633afe engine/strata: bring the Strata subtree to upstream 41cf05a0 (engine 0.1.50) with the local patches re-applied
Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree
(570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base =
the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main).

Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR
experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details,
conflict table and left-out files are in docs/upstream.md.

Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61),
docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out.

scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run").
Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR
macros on. No GPU run, no quality gate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:49:15 +01:00

103 lines
4.4 KiB
Python

"""Tests for setup.py's low-RAM messages and the paging question (#250): the one-GPU warning says why and shows the
RAM math, and an explicit --low-ram off installs with --yes instead of stopping at "Install it anyway?" (default
n). Mocked input - no GPU, no downloads.
python -m unittest tools.test_setup_lowram
"""
from __future__ import annotations
import contextlib
import io
import sys
import unittest
from pathlib import Path
from unittest import mock
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
import setup # noqa: E402
def run(fn, *args, stdin=None):
"""-> (exit code or None, printed text); `stdin` answers input() (None: never asked)."""
out = io.StringIO()
asked = []
def fake_input(prompt=""):
asked.append(prompt)
if stdin is None:
raise AssertionError(f"asked {prompt!r} with --yes")
return stdin
code = None
with contextlib.redirect_stdout(out), mock.patch("builtins.input", fake_input):
try:
fn(*args)
except SystemExit as e:
code = e.code
return code, out.getvalue(), asked
class OneGpuWhy(unittest.TestCase):
def test_auto_shows_the_ram_math(self):
lines = setup.low_ram_one_gpu_why("IQ3_XXS", 46, "auto") # the #250 report: 46 GB, IQ3_XXS
text = "\n".join(lines)
arena = setup.MODELS["IQ3_XXS"]["arena_gb"]
need = arena + setup.LOW_RAM_HEADROOM_GB
self.assertIn(f"{arena:.0f} + {setup.LOW_RAM_HEADROOM_GB} = {need:.0f} GB", text)
self.assertIn("this PC has 46 GB", text)
self.assertIn("layer split", text) # why one GPU is recommended
self.assertIn("--gpus 0,1", text) # #364 #384: and the way to use them all
self.assertIn("OS file cache", text)
self.assertNotIn("--low-ram off", text) # (that pages the experts: not the way)
def test_an_explicit_choice_says_so(self):
text = "\n".join(setup.low_ram_one_gpu_why("Q2_0", 64, "resident"))
self.assertIn("you chose the low-RAM mode (--low-ram resident)", text)
class PagingQuestion(unittest.TestCase):
MODEL, RAM = "IQ3_XXS", 46 # 60 GB wanted, 46 here
def test_yes_with_low_ram_off_installs(self):
code, out, asked = run(setup.confirm_paging, self.MODEL, self.RAM, "off", True)
self.assertIsNone(code, out)
self.assertEqual(asked, [])
self.assertIn("installing IQ3_XXS with 46 GB of RAM, as you chose (--low-ram off)", out)
def test_yes_with_auto_still_stops(self):
code, out, asked = run(setup.confirm_paging, self.MODEL, self.RAM, "auto", True)
self.assertEqual(code, 1)
self.assertIn("IQ3_XXS needs about 60 GB of RAM; this PC has 46 GB", out)
self.assertIn("--low-ram off --yes", out) # the way to insist
def test_interactive(self):
for choice, answer, want in (("off", "", None), ("auto", "", 1), ("auto", "y", None), ("off", "n", 1)):
with self.subTest(choice=choice, answer=answer):
code, out, asked = run(setup.confirm_paging, self.MODEL, self.RAM, choice, False, stdin=answer)
self.assertEqual(code, want, out)
self.assertEqual(len(asked), 1)
self.assertIn("[y]" if choice == "off" else "[n]", asked[0])
class DraftLayerCountsInTheFit(unittest.TestCase):
"""The draft layer (MTP) takes about 1 GB of graphics memory out of the expert cache: every fit check counts it while it is on."""
def test_the_card_holds_one_gb_less_with_mtp_on(self):
on = setup.low_ram_gpu_gb("IQ3_XXS", 12.0)
off = setup.low_ram_gpu_gb("IQ3_XXS", 12.0, mtp=False)
self.assertAlmostEqual(off - on, setup.MTP_VRAM_GB)
self.assertEqual(setup.MTP_VRAM_GB, 1.0)
self.assertAlmostEqual(setup.low_ram_gpu_share("IQ3_XXS", 12.0, mtp=False) - setup.low_ram_gpu_share("IQ3_XXS", 12.0),
1.0 / setup.MODELS["IQ3_XXS"]["arena_gb"])
def test_the_edge_of_what_fits_moves_by_the_draft_layer(self):
arena = setup.MODELS["IQ1_M"]["arena_gb"]
ram = arena + 6 - 7.0 + 0.5 # a card of 12 GB holds 7 GB beside the dense part; the draft layer needs one of them
self.assertFalse(setup.low_ram_fits("IQ1_M", ram, 12.0))
self.assertTrue(setup.low_ram_fits("IQ1_M", ram, 12.0, mtp=False))
if __name__ == "__main__":
unittest.main()