okami.mom/strata

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

Niko1221merge f-split into f-split-s6326e39118

main
2.2 KiB52 linesraw
1"""#1445: a vision encoder that cannot start because the GPU is busy/unavailable (compute mode Exclusive_Process) says
2so, with the nvidia-smi check, instead of only the first line of the encoder's output.
3
4    python -m serve.test_vision_busy
5"""
6import io
7import tempfile
8import unittest
9from pathlib import Path
10from types import SimpleNamespace
11from unittest import mock
12
13import serve.server as server
14
15
16class Busy(unittest.TestCase):
17    def test_message_names_the_cause_from_the_line(self):
18        m = server.vision_start_error("ggml_backend_cuda_device_get_memory: cudaMemGetInfo failed "
19                                      "(CUDA-capable device(s) is/are busy or unavailable), returning 0/0")
20        self.assertIn("Exclusive_Process", m)
21        self.assertIn("nvidia-smi", m)
22        self.assertIn("did not start", m)
23
24    def test_message_names_the_cause_from_the_log_tail(self):
25        with tempfile.NamedTemporaryFile("w+", suffix=".log", delete=False) as f:
26            f.write("x" * 40000 + "\ncudaMalloc failed: CUDA-capable device(s) is/are busy or unavailable\n")
27            name = f.name
28        try:
29            with open(name, "a") as log:
30                m = server.vision_start_error("load_hparams: something", log)
31            self.assertIn("Exclusive_Process", m)
32        finally:
33            Path(name).unlink()
34
35    def test_other_failures_are_unchanged(self):
36        self.assertEqual(server.vision_start_error("ERR no mmproj\n"), "the vision encoder did not start: ERR no mmproj")
37
38    def test_start_raises_it(self):
39        line = "cudaMalloc failed: CUDA-capable device(s) is/are busy or unavailable\n"
40        proc = SimpleNamespace(stdin=io.StringIO(), stdout=io.StringIO(line), kill=lambda: None, wait=lambda timeout=None: 0,
41                               poll=lambda: None)
42        v = server.Vision.__new__(server.Vision)
43        v.spawn = (["strata-vision"], None, None)
44        v.dir = Path(tempfile.gettempdir())
45        with mock.patch.object(server, "popen", lambda *a, **k: proc):
46            with self.assertRaises(RuntimeError) as cm:
47                v._start()
48        self.assertIn("Exclusive_Process", str(cm.exception))
49
50
51if __name__ == "__main__":
52    unittest.main()