okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
671f4573d
main
1"""Tests for setup.py's low-RAM messages and the paging question (#250): the one-GPU warning says why and shows the 2RAM math, and an explicit --low-ram off installs with --yes instead of stopping at "Install it anyway?" (default 3n). Mocked input - no GPU, no downloads. 4 5python -m unittest tools.test_setup_lowram 6""" 7from __future__import annotations 8 9import contextlib 10import io 11import sys 12import unittest 13from pathlib import Path 14from unittest import mock 15 16ROOT = Path (__file__ ).resolve ().parents [1 ] 17sys .path .insert (0 ,str (ROOT )) 18import setup # noqa: E402 19 20 21def run (fn ,* args ,stdin = None ): 22"""-> (exit code or None, printed text); `stdin` answers input() (None: never asked).""" 23out = io .StringIO () 24asked = [] 25 26def fake_input (prompt = "" ): 27asked .append (prompt ) 28if stdin is None : 29raise AssertionError (f"asked { prompt !r } with --yes" ) 30return stdin 31 32code = None 33with contextlib .redirect_stdout (out ),mock .patch ("builtins.input" ,fake_input ): 34try : 35fn (* args ) 36except SystemExit as e : 37code = e .code 38return code ,out .getvalue (),asked 39 40 41class OneGpuWhy (unittest .TestCase ): 42def test_auto_shows_the_ram_math (self ): 43lines = setup .low_ram_one_gpu_why ("IQ3_XXS" ,46 ,"auto" )# the #250 report: 46 GB, IQ3_XXS 44text = "\n" .join (lines ) 45arena = setup .MODELS ["IQ3_XXS" ]["arena_gb" ] 46need = arena + setup .LOW_RAM_HEADROOM_GB 47self .assertIn (f" { arena :.0f } + { setup . LOW_RAM_HEADROOM_GB } = { need :.0f } GB" ,text ) 48self .assertIn ("this PC has 46 GB" ,text ) 49self .assertIn ("layer split" ,text )# why one GPU is recommended 50self .assertIn ("--gpus 0,1" ,text )# #364 #384: and the way to use them all 51self .assertIn ("OS file cache" ,text ) 52self .assertNotIn ("--low-ram off" ,text )# (that pages the experts: not the way) 53 54def test_an_explicit_choice_says_so (self ): 55text = "\n" .join (setup .low_ram_one_gpu_why ("Q2_0" ,64 ,"resident" )) 56self .assertIn ("you chose the low-RAM mode (--low-ram resident)" ,text ) 57 58 59class PagingQuestion (unittest .TestCase ): 60MODEL ,RAM = "IQ3_XXS" ,46 # 60 GB wanted, 46 here 61 62def test_yes_with_low_ram_off_installs (self ): 63code ,out ,asked = run (setup .confirm_paging ,self .MODEL ,self .RAM ,"off" ,True ) 64self .assertIsNone (code ,out ) 65self .assertEqual (asked , []) 66self .assertIn ("installing IQ3_XXS with 46 GB of RAM, as you chose (--low-ram off)" ,out ) 67 68def test_yes_with_auto_still_stops (self ): 69code ,out ,asked = run (setup .confirm_paging ,self .MODEL ,self .RAM ,"auto" ,True ) 70self .assertEqual (code ,1 ) 71self .assertIn ("IQ3_XXS needs about 60 GB of RAM; this PC has 46 GB" ,out ) 72self .assertIn ("--low-ram off --yes" ,out )# the way to insist 73 74def test_interactive (self ): 75for choice ,answer ,want in (("off" ,"" ,None ), ("auto" ,"" ,1 ), ("auto" ,"y" ,None ), ("off" ,"n" ,1 )): 76with self .subTest (choice = choice ,answer = answer ): 77code ,out ,asked = run (setup .confirm_paging ,self .MODEL ,self .RAM ,choice ,False ,stdin = answer ) 78self .assertEqual (code ,want ,out ) 79self .assertEqual (len (asked ),1 ) 80self .assertIn ("[y]" if choice == "off" else "[n]" ,asked [0 ]) 81 82 83class DraftLayerCountsInTheFit (unittest .TestCase ): 84"""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.""" 85 86def test_the_card_holds_one_gb_less_with_mtp_on (self ): 87on = setup .low_ram_gpu_gb ("IQ3_XXS" ,12.0 ) 88off = setup .low_ram_gpu_gb ("IQ3_XXS" ,12.0 ,mtp = False ) 89self .assertAlmostEqual (off - on ,setup .MTP_VRAM_GB ) 90self .assertEqual (setup .MTP_VRAM_GB ,1.0 ) 91self .assertAlmostEqual (setup .low_ram_gpu_share ("IQ3_XXS" ,12.0 ,mtp = False )- setup .low_ram_gpu_share ("IQ3_XXS" ,12.0 ), 921.0 / setup .MODELS ["IQ3_XXS" ]["arena_gb" ]) 93 94def test_the_edge_of_what_fits_moves_by_the_draft_layer (self ): 95arena = setup .MODELS ["IQ1_M" ]["arena_gb" ] 96ram = 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 97self .assertFalse (setup .low_ram_fits ("IQ1_M" ,ram ,12.0 )) 98self .assertTrue (setup .low_ram_fits ("IQ1_M" ,ram ,12.0 ,mtp = False )) 99 100 101if __name__ == "__main__" : 102unittest .main ()