Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
fix(tools): check temp free space before the eviction write in datapoint.py
Unknown-Findouta1dfd787bc27
diff --git a/c/tests/test_datapoint.py b/c/tests/test_datapoint.pyindex f5f069b4..cf526642 100644--- a/c/tests/test_datapoint.py+++ b/c/tests/test_datapoint.py@@ -274,5 +274,43 @@ class PersistentDatapointTest(unittest.TestCase):self.assertTrue(all(family.has_gateway_adapter for family in FAMILIES))+class EvictCacheSpaceTest(unittest.TestCase):+ """The portable fallback must not fill the temp volume.++ It is the only eviction route on Windows, and since #1042 it sizes the write+ from the machine's real RAM rather than a hardcoded 8 GB. A 128 GB box whose+ temp dir is on a drive with 124 GB free would write until that volume hit+ zero and only then raise OSError.+ """++ def _run(self, ram_gb, free_gb, tmp="/tmp"):+ usage = SimpleNamespace(free=int(free_gb * GB))+ with mock.patch.object(sys, "platform", "win32"), \+ mock.patch.object(datapoint.tempfile, "gettempdir", return_value=tmp), \+ mock.patch.object(datapoint.shutil, "disk_usage", return_value=usage), \+ mock.patch.object(datapoint.tempfile, "NamedTemporaryFile") as ntf:+ return datapoint.evict_cache(ram_gb), ntf++ def test_refuses_when_the_temp_volume_is_too_small(self):+ result, ntf = self._run(ram_gb=128, free_gb=124)+ self.assertFalse(result)+ ntf.assert_not_called() # nothing written, not even partially++ def test_writes_when_there_is_room(self):+ result, ntf = self._run(ram_gb=8, free_gb=500)+ self.assertTrue(ntf.called)+ self.assertTrue(result)++ def test_unreadable_temp_volume_does_not_block_the_write(self):+ """A failed disk_usage must not become a refusal. The pre-existing+ OSError handler around the write is still the backstop."""+ with mock.patch.object(sys, "platform", "win32"), \+ mock.patch.object(datapoint.shutil, "disk_usage",+ side_effect=OSError("no stat")), \+ mock.patch.object(datapoint.tempfile, "NamedTemporaryFile") as ntf:+ self.assertTrue(datapoint.evict_cache(1))+ self.assertTrue(ntf.called)++if __name__ == "__main__":unittest.main()diff --git a/c/tools/datapoint.py b/c/tools/datapoint.pyindex ec155ca9..7e8be996 100644--- a/c/tools/datapoint.py+++ b/c/tools/datapoint.py@@ -32,6 +32,7 @@ import argparseimport osimport platformimport re+import shutilimport statisticsimport subprocessimport sys@@ -171,6 +172,24 @@ def evict_cache(ram_gb, snap_dir=None):# Fallback: Write temp file larger than RAMsize_mb = int(ram_gb) * 1024 + 1024+ # Confirm the temp volume can hold it before writing a byte. This is the only+ # eviction route on Windows (macOS has purge, Linux has fadvise), and since+ # #1042 it writes the machine's real RAM rather than a hardcoded 8 GB, so the+ # write is now as large as the box. tempfile.gettempdir() is usually the+ # system drive while the model lives elsewhere, so on a 128 GB machine with+ # 124 GB free on C: this fills the system volume to zero and only then raises.+ tmp_dir = tempfile.gettempdir()+ need = size_mb * (1 << 20)+ try:+ free = shutil.disk_usage(tmp_dir).free+ except OSError:+ free = None+ if free is not None and free < need:+ print(f"[datapoint] cache eviction skipped: need {need / (1 << 30):.0f} GB "+ f"free in {tmp_dir} but only {free / (1 << 30):.0f} GB available. "+ f"Point TMPDIR (TEMP on Windows) at a larger volume, or pass "+ f"--no-evict and label the run warm.", file=sys.stderr)+ return Falseprint(f"[datapoint] evicting page cache by writing {size_mb / 1024:.0f} GB "f"to a temp file (no direct eviction on this platform; --no-evict skips)",file=sys.stderr)