Files
strata/tools/test_setup_lowram.py
T
Niko1221 5a7190de4a setup: the low-RAM mode's one-GPU warning says why, with the RAM math; --low-ram off --yes installs (#250)
Low-RAM mode on a multi-GPU pick dropped to one GPU with only "the low-RAM mode runs on one GPU".  It now says
why: the experts plus ~10 GB for the rest (e.g. 43 + 10 = 53 GB) against this PC's RAM, or that --low-ram was
chosen; that the engine does not split layers in that mode (it refuses --resident-experts with a layer split);
and what keeps all the GPUs (more RAM, a smaller size, --low-ram off).

--low-ram off on a PC short of RAM asked "Install it anyway?" with the default n, so an unattended --yes
install always stopped although the user had turned the mode off explicitly.  With --low-ram off the default is
y (--yes installs, with a warning); with auto the question and its n default are as before (#125), and the stop
message names --low-ram off --yes.  The two blocks are functions now (low_ram_one_gpu_why, confirm_paging);
tests in tools/test_setup_lowram.py with mocked input.
2026-09-30 20:40:02 +02:00

83 lines
3.2 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
self.assertIn("--low-ram off", text) # and the way to keep them all
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])
if __name__ == "__main__":
unittest.main()