{"record":{"id":"4a1a5aff91c6dfbb","repo":"unslothai/unsloth","slug":"no-diffusion-model-is-loaded-4a1a5a","errorCode":null,"errorMessage":"No diffusion model is loaded.","messagePattern":"No diffusion model is loaded\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/inference/sd_cpp_backend.py","lineNumber":2084,"sourceCode":"                \"Batched prompt/seed lists are not supported on the native sd.cpp engine \"\n                \"(it renders serially); run on a GPU (diffusers) for batched generation, \"\n                \"or use batch_size for a serial native batch.\"\n            )\n        # strength 0/None disables ControlNet (matches diffusers), so no-op it rather than 400.\n        if controlnet is not None and controlnet[3] in (None, 0, 0.0):\n            controlnet = None\n        if controlnet is not None:\n            raise ValueError(\n                \"ControlNet is not yet supported on the native sd.cpp engine; run on a GPU \"\n                \"(diffusers) for ControlNet conditioning.\"\n            )\n\n        cancel = threading.Event()\n        with self._generate_lock:\n            with self._lock:\n                state = self._state\n                if state is None:\n                    raise RuntimeError(DIFFUSION_NOT_LOADED_MSG)\n                # A resident server can exit while idle; drop stale state and report not-loaded so the client gets the reload path, not a 500.\n                if (\n                    state.mode == \"server\"\n                    and state.server is not None\n                    and not state.server.is_alive()\n                ):\n                    self._state = None\n                    raise RuntimeError(DIFFUSION_NOT_LOADED_MSG)\n                self._active_generate_cancel = cancel\n                # Publish an active (step 0) state before the slow pre-generate setup so a reload probe does not read idle while this holds _generate_lock.\n                self._gen = _SdGen(total_steps = int(steps))\n            try:\n                if seed is None:\n                    seed = int.from_bytes(os.urandom(6), \"big\") & ((1 << 53) - 1)\n                else:\n                    seed = int(seed)\n                cfg_scale, flux_guidance = _map_guidance(state.family, guidance)\n                # Resolve selected LoRAs up front (a bad id gives a clear 400). Drop weight-0 rows BEFORE the support gate so an only-disabled request stays a no-op.","sourceCodeStart":2066,"sourceCodeEnd":2102,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/sd_cpp_backend.py#L2066-L2102","documentation":"RuntimeError (DIFFUSION_NOT_LOADED_MSG) raised under the generate lock when self._state is None: generate() was called before any model finished loading, or after unload(). The backend distinguishes this from a 500 so the client gets the reload path.","triggerScenarios":"generate() before begin_load completes; generate() after unload() or after a failed load left no state.","commonSituations":"UI firing generation before the load indicator clears; restarts that drop in-flight loads; calling generate right after a cancel that tore down state.","solutions":["Call begin_load and wait for it to complete (poll status()) before generate().","If a previous load failed, restart it and check its error before generating.","After unload(), load a model again before generating."],"exampleFix":"# before\nbackend.generate(prompt='a cat')  # nothing loaded\n\n# after\nbackend.begin_load(repo_id=..., gguf_filename=...)\nwait_until_loaded(backend)\nbackend.generate(prompt='a cat')","handlingStrategy":"validation","validationCode":"status = backend.status()\nif status.get('state') is None or not status.get('loaded'):\n    wait_until_loaded(backend)  # or issue begin_load first","typeGuard":null,"tryCatchPattern":"try:\n    result = backend.generate(prompt=p)\nexcept RuntimeError as e:\n    if 'No diffusion model is loaded' in str(e):\n        wait_until_loaded(backend)\n        result = backend.generate(prompt=p)\n    else:\n        raise","preventionTips":["Gate generate() on a loaded status in the client state machine.","Treat this message as a reload signal, not an error to log loudly."],"tags":["state-machine","validation","load"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}