diff --git a/strata_cli/launch/runner.py b/strata_cli/launch/runner.py index abe7e575..c309ea0f 100644 --- a/strata_cli/launch/runner.py +++ b/strata_cli/launch/runner.py @@ -1969,7 +1969,7 @@ CAUSE_LINE = re.compile(r"error|exception|failed|cannot|can't|could not|no devic r"no kernel|illegal|denied|refus", re.I) # The GPU runtime (ROCm) failed while the card was being set up, often right after another engine exited: the runtime's own text # ("terminate called after throwing an instance of 'rocr::AMD::hsa_exception'") stays in the log, not in the sentence shown. -HSA_START = re.compile(r"hsa_exception|HSA_STATUS_ERROR|hsaKmt", re.I) +HSA_START = re.compile(r"hsa_exception|HSA_STATUS_ERROR", re.I) HSA_START_NEXT = ("The graphics card was not ready yet; wait a few seconds and run it again. If it keeps happening, restart the PC " "and report the log.") KNOWN_CAUSES = ( @@ -2052,7 +2052,13 @@ def explain_engine_exit(result: dict, config: Path | None, marks: dict | None = stage = f"The server did not become ready ({state}: {why or 'see the engine log'})" hsa = HSA_START.search(" ".join(lines + [str(why or "")])) # the runtime's own text is kept out of the sentence (it is in the log) if hsa: - cause = "" + # a real cause in the same log (out of memory, no permission on the card ...) wins: its line is the cause shown + real = next((x for x in reversed(lines) if any(p.search(x) for p, _ in KNOWN_CAUSES)), None) + if real: + hsa = None + cause = re.sub(r"^(\[strata\]\s*)?(\d{4}-\d\d-\d\d[ T][\d:.]+\s*)?", "", real.strip())[:240] + else: + cause = "" text = stage + (f": {cause}" if cause else ".") if not text.endswith((".", "!")): text += "." diff --git a/tests/terminal/test_round8_fixes.py b/tests/terminal/test_round8_fixes.py index 47ef0276..d3e9db47 100644 --- a/tests/terminal/test_round8_fixes.py +++ b/tests/terminal/test_round8_fixes.py @@ -60,6 +60,18 @@ class EngineExitIsExplained(unittest.TestCase): self.assertNotIn("hsa_exception", text) self.assertIn("graphics card was not ready yet", nxt) + def test_a_real_cause_in_the_same_log_wins_over_the_gpu_runtime_start_failure(self): + cfg, log = self.config_with_log(["strata generate: CUDA error: out of memory", + "terminate called after throwing an instance of 'rocr::AMD::hsa_exception'", " what(): "]) + text, nxt = R.explain_engine_exit({"state": "failed", "error": "server_exited", "engine_exit_code": 134}, cfg) + self.assertIn("out of memory", text) + self.assertIn("--context 16k", nxt) + self.assertNotIn("graphics card was not ready", nxt) + cfg, _ = self.config_with_log(["Permission denied: /dev/dri/renderD128", "terminate called after throwing an instance of 'rocr::AMD::hsa_exception'"]) + self.assertIn("render group", R.explain_engine_exit({"error": "server_exited", "engine_exit_code": 134}, cfg)[1]) + cfg, _ = self.config_with_log(["hsaKmtOpenKFD ok", "strata generate: CUDA error: out of memory"]) + self.assertNotIn("graphics card was not ready", R.explain_engine_exit({"error": "server_exited"}, cfg)[1]) + def test_out_of_memory_and_old_engine_get_their_own_next_step(self): cfg, _ = self.config_with_log(["strata generate: CUDA error: out of memory"]) self.assertIn("--context 16k", R.explain_engine_exit({"error": "server_exited"}, cfg)[1])