replicas: the memfd arena warns when the RAM will not hold all the engines
This commit is contained in:
1 parent
9f1d0ad041
commit
9d8337844e
2 files changed
+28
-1
No files matched your search
+12
-1
@@ -194,8 +194,19 @@ def shared_arena_plan(cfg: dict, n_replicas: int, *, shm: str = "/dev/shm", plat
|
||||
if fd >= 0:
|
||||
path = f"/proc/{os.getpid()}/fd/{fd}"
|
||||
_MEMFDS[path] = fd
|
||||
warn = ""
|
||||
try: # the arena once plus about 7 GB of private RAM per engine (measured); a warning, never a refusal
|
||||
from strata_control import replica_profile as _rp
|
||||
q = _rp.quant_of(cfg)
|
||||
if q:
|
||||
need = _rp.ARENA_GB[q] + n_replicas * _rp.PER_REPLICA_GB
|
||||
if avail / 2**30 < need + 4:
|
||||
warn = (f" WARNING: about {need:.0f} GB are needed for {n_replicas} engines and {avail / 2**30:.0f} GB "
|
||||
"are free: the last engine may not fit (fewer replicas, or the layer split, is safer)")
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
return path, (f"one shared expert arena for {n_replicas} replicas (memory object of the server, not limited by "
|
||||
"the size of /dev/shm): the experts are in RAM once")
|
||||
f"the size of /dev/shm): the experts are in RAM once.{warn}")
|
||||
if not (os.path.isdir(shm) and os.access(shm, os.W_OK)):
|
||||
return None, f"shared expert arena: {shm} is not usable; each replica keeps its own copy of the experts in RAM"
|
||||
free = free_bytes if free_bytes is not None else _free(shm)
|
||||
|
||||
@@ -384,6 +384,22 @@ class SharedArena(unittest.TestCase):
|
||||
os.fstat(fd)
|
||||
remove_arena(path) # (twice: harmless)
|
||||
|
||||
@unittest.skipUnless(hasattr(__import__("os"), "memfd_create") and sys.platform.startswith("linux"), "Linux memfd")
|
||||
def test_a_memfd_arena_warns_when_the_engines_will_not_all_fit(self):
|
||||
cfg = {**self.CFG, "model_name": "qwen3.8-flash-next-iq3_s"}
|
||||
path, note = shared_arena_plan(cfg, 2, platform="linux", environ={}, free_bytes=57 << 30, use_memfd=True)
|
||||
try:
|
||||
self.assertTrue(path)
|
||||
self.assertIn("WARNING", note)
|
||||
self.assertIn("may not fit", note)
|
||||
finally:
|
||||
remove_arena(path)
|
||||
path, note = shared_arena_plan(cfg, 2, platform="linux", environ={}, free_bytes=120 << 30, use_memfd=True)
|
||||
try:
|
||||
self.assertNotIn("WARNING", note)
|
||||
finally:
|
||||
remove_arena(path)
|
||||
|
||||
def test_a_memfd_needs_free_ram(self):
|
||||
path, note = shared_arena_plan(self.CFG, 2, platform="linux", environ={}, free_bytes=2 << 30, use_memfd=True)
|
||||
self.assertIsNone(path)
|
||||
|
||||
Reference in new issue
Block a user