{"record":{"id":"f1601ebde6fb1abb","repo":"unslothai/unsloth","slug":"sd-cli-exited-ret-last-output-n-join-tail","errorCode":null,"errorMessage":"sd-cli exited {ret}. Last output:\n{\"\\n\".join(tail[-12:])}","messagePattern":"sd-cli exited (.+?)\\. Last output:\n(.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/inference/sd_cpp_engine.py","lineNumber":822,"sourceCode":"                    if proc.poll() is not None:\n                        break\n                    continue\n                tail.append(line)\n                if len(tail) > 40:\n                    tail.pop(0)\n                if on_log is not None:\n                    on_log(line)\n            ret = proc.wait(timeout = 5.0)\n        finally:\n            if proc.poll() is None:\n                _terminate(proc)\n            # Only once it has actually exited: a pid still running has to stay\n            # recorded, or the next startup has no handle on it.\n            if proc.poll() is not None:\n                forget_pid(proc.pid)\n\n        if ret != 0:\n            raise RuntimeError(f\"sd-cli exited {ret}. Last output:\\n\" + \"\\n\".join(tail[-12:]))\n        if not out.is_file():\n            raise RuntimeError(\n                f\"sd-cli reported success but no image at {out}. Last output:\\n\"\n                + \"\\n\".join(tail[-12:])\n            )\n        logger.info(\"sd-cli run ok in %.1fs -> %s\", time.time() - t0, out)\n        return out\n\n\n# ── engine routing ──────────────────────────────────────────────────────────\n\nENGINE_DIFFUSERS = \"diffusers\"\nENGINE_SD_CPP = \"sd_cpp\"\n\n# Backends diffusers serves well with GPU acceleration; everything else is native-engine territory.\n_GPU_BACKENDS = frozenset({\"cuda\", \"rocm\", \"xpu\"})\n\n","sourceCodeStart":804,"sourceCodeEnd":840,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/sd_cpp_engine.py#L804-L840","documentation":"The sd-cli subprocess exited with a non-zero return code. The message embeds the exit status and the last 12 stdout/stderr lines captured by the reader thread, which is the primary diagnostic: it usually shows the real cause (model load failure, OOM, unsupported GGUF feature, bad argument). The process is terminated and its pid untracked in the finally block, so no zombie remains.","triggerScenarios":"Any sd-cli run that fails internally: corrupt or unsupported model files, out-of-memory during load or sampling, invalid prompt/param encodings, or missing accelerator drivers.","commonSituations":"Model quantization not supported by the installed CLI version; GPU OOM on large models; truncated GGUF download; CLI built without the backend the model needs (e.g. FlashAttention, CUDA).","solutions":["Read the embedded last-12-lines tail — it names the actual failure; act on that, not on the exit code.","Exit code 139/134 (segv/abort) with memory lines: reduce resolution/steps, enable offload, or use a smaller quant.","Model-load errors: verify the GGUF checksum / re-download, and confirm the CLI build supports the model architecture.","Keep the sd-cli build in sync with the backend version (rebuild or `unsloth studio update`)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    engine.generate(...)\nexcept RuntimeError as e:\n    msg = str(e)\n    if \"exited\" in msg:\n        tail = msg.split(\"Last output:\", 1)[-1]\n        log_for_triage(tail)  # act on the real cause in the tail\n    raise","preventionTips":["Always log the embedded tail — it contains the actual CLI error.","Validate model files (size/checksum) before handing them to the CLI.","Match CLI build features (CUDA/FA) to the model's requirements before running."],"tags":["diffusion","sd-cpp","cli","process-exit"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}