okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-container-mem-core: memory checks that read a container's limit correctly6b63729a9

main
1.9 KiB49 linesraw
1"""Setup's low-RAM choice compares the RAM (ram_gb(): GiB) with the expert arena (MODELS arena_gb: GB of 10^9 bytes)
2plus the headroom in ONE unit, GiB.  IQ3_S: arena 50.3 GB = 46.85 GiB, so the line moves at 56.85 GiB.
3
4    python -m unittest tools.test_setup_low_ram_units
5"""
6from __future__ import annotations
7
8import sys
9import unittest
10from pathlib import Path
11
12ROOT = Path(__file__).resolve().parents[1]
13sys.path.insert(0, str(ROOT))
14import setup  # noqa: E402
15
16POD_GIB = 61_998_571_520 / 2**30      # the rented RTX 4090 container's memory.max: 57.74 GiB
17PC_64GB_GIB = 62.6                    # what a 64 GB PC's MemTotal shows
18
19
20class LowRamUnits(unittest.TestCase):
21    def test_the_iq3s_arena_in_gib(self):
22        self.assertAlmostEqual(setup.MODELS["IQ3_S"]["arena_gb"] * 1e9 / 2**30, 46.85, places=2)
23
24    def test_the_57_7_gib_container_keeps_the_ram_copy_line(self):
25        # measured there: line B peaks at 50.72 GiB anon + shmem with no OOM in six starts, and is the faster line
26        self.assertFalse(setup.low_ram_needed("IQ3_S", POD_GIB))
27
28    def test_a_48_gib_container_gets_the_low_ram_line(self):
29        self.assertTrue(setup.low_ram_needed("IQ3_S", 48.0))
30
31    def test_a_64_gb_pc_keeps_the_ram_copy_line_as_before(self):
32        self.assertFalse(setup.low_ram_needed("IQ3_S", PC_64GB_GIB))
33
34    def test_56_gib_gets_the_low_ram_line(self):
35        self.assertTrue(setup.low_ram_needed("IQ3_S", 56.0))
36
37    def test_the_line_moves_at_arena_gib_plus_headroom(self):
38        edge = 50.3e9 / 2**30 + setup.LOW_RAM_HEADROOM_GB
39        self.assertTrue(setup.ram_short_of_arena(edge - 0.01, 50.3))
40        self.assertFalse(setup.ram_short_of_arena(edge, 50.3))
41
42    def test_the_old_mixed_unit_band_moves(self):
43        # 56.85-60.3 GiB took the low-RAM line only because GiB was compared with GB
44        for ram in (57.0, 58.5, 60.29):
45            self.assertFalse(setup.low_ram_needed("IQ3_S", ram), ram)
46
47
48if __name__ == "__main__":
49    unittest.main()