okami.mom/strata

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

Niko1221Merge branch 'f-0212-int' into f-0212-splitdf2c65b9f8be

main
4.8 KiB78 linesraw
1"""Two small cards on a layer split (MULTISPILL, round 0212): what the launcher says when a card runs out of memory.
2
3The final line of a failed start is the engine's own reason, not the picture reader's harmless "ggml_cuda_init: ... no CUDA-capable device" that it prints when the
4cards are full and it runs on the processor; the next step does not tell the person to change the context or the number of requests.  Nothing here starts an engine."""
5from __future__ import annotations
6
7import json
8import tempfile
9import unittest
10from pathlib import Path
11
12from strata_cli.launch import runner as R
13from strata_control import vram_fit
14
15# the log of the 2 x 8 GB start that failed (HYBRID, srv118, 2 x RTX PRO 6000 held to 8 GB free by hogs, 128K): the engine's reason, then the picture reader's line
16SERVE_STOP = [
17    "strata serve: layer split, CUDA1 prompt path: prefill: device buffers for a chunk of 512 tokens do not fit (5 of 97247 MiB free at the failure; 555 MiB taken, the failing buffer wanted 2 MiB)",
18    "strata serve: the GPU has too little free VRAM for the prompt path: turn images off (setup: --vision no), close other programs using the GPU, use a shorter context, or read prompts in smaller chunks (--prefill 512)",
19    "ggml_cuda_init: failed to initialize CUDA: no CUDA-capable device is detected",
20]
21CACHE_STOP = [
22    "strata generate: layer split, CUDA1: 0.17 GiB free of 94.97, room for experts 0.00 GiB",
23    "strata generate: layer split, CUDA1 expert cache: no room",
24    "ggml_cuda_init: failed to initialize CUDA: no CUDA-capable device is detected",
25]
26
27
28class TheEnginesReason(unittest.TestCase):
29    def test_the_reason_is_the_engines_not_the_picture_readers(self):
30        self.assertEqual(vram_fit.engine_stop_reason(SERVE_STOP),
31                         "the GPU has too little free VRAM for the prompt path: turn images off (setup: --vision no), close other programs using the GPU, "
32                         "use a shorter context, or read prompts in smaller chunks (--prefill 512)")
33        self.assertEqual(vram_fit.engine_stop_reason(CACHE_STOP), "layer split, CUDA1 expert cache: no room")
34
35    def test_other_stops_and_the_walks_own_lines_are_not_a_memory_stop(self):
36        self.assertIsNone(vram_fit.engine_stop_reason(["strata generate: something else is wrong", "ggml_cuda_init: failed to initialize CUDA"]))
37        self.assertIsNone(vram_fit.engine_stop_reason([]))
38        self.assertIsNone(vram_fit.engine_stop_reason(None))
39        walk = ["strata generate: short of GPU memory: CUDA1 has 2.53 GiB free and a layer split card needs about 9.1 GiB: each later card loads only the dense weights of its own layers",
40                "strata serve: CUDA1: 293 MiB of VRAM free with everything loaded - LOW: its window graphs are captured on first use"]
41        self.assertIsNone(vram_fit.engine_stop_reason(walk), "what the walk did and a LOW warning say nothing about why a start stopped")
42
43    def test_the_last_memory_line_wins(self):
44        lines = ["strata generate: layer split, CUDA1 expert cache: no room", "strata serve: the GPU has too little free VRAM for the prompt path: x"]
45        self.assertTrue(vram_fit.engine_stop_reason(lines).startswith("the GPU has too little free VRAM"))
46
47
48class TheLastLine(unittest.TestCase):
49    def explain(self, lines, **result):
50        with tempfile.TemporaryDirectory() as tmp:
51            log = Path(tmp) / "engine.log"
52            log.write_text("\n".join(lines) + "\n", encoding="utf-8")
53            cfg = Path(tmp) / "run.json"
54            cfg.write_text(json.dumps({"exe": "e", "args": [], "log": str(log)}), encoding="utf-8")
55            return R.explain_engine_exit({"state": "failed", "error": "server_exited", "engine_exit_code": 1, **result}, cfg)
56
57    def test_a_prompt_path_stop_shows_the_engines_line_and_a_next_step_that_keeps_the_context(self):
58        text, nxt = self.explain(SERVE_STOP)
59        self.assertIn("too little free VRAM for the prompt path", text)
60        self.assertNotIn("ggml_cuda_init", text)
61        self.assertNotIn("no CUDA-capable device", text)
62        self.assertIn("were not changed", nxt, "the context and the requests stay what the person chose")
63        self.assertIn("fewer cards", nxt)
64        self.assertNotIn("--context 16k", nxt, "the old advice asked for a smaller context")
65
66    def test_a_stage_cache_stop_shows_the_engines_line(self):
67        text, _ = self.explain(CACHE_STOP)
68        self.assertIn("layer split, CUDA1 expert cache: no room", text)
69        self.assertNotIn("ggml_cuda_init", text)
70
71    def test_a_stop_for_another_reason_is_worded_as_before(self):
72        text, nxt = self.explain(["strata generate: cudaMalloc failed", "unsupported quant type 99"])
73        self.assertIn("unsupported quant type 99", text)
74        self.assertNotIn("were not changed", nxt)
75
76
77if __name__ == "__main__":
78    unittest.main()