{"record":{"id":"a6b3bc1bc14c0147","repo":"unslothai/unsloth","slug":"sd-server-returned-len-blobs-of-count-request","errorCode":null,"errorMessage":"sd-server returned {len(blobs)} of {count} requested images in the batch.","messagePattern":"sd-server returned (.+?) of (.+?) requested images in the batch\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/inference/sd_cpp_backend.py","lineNumber":2300,"sourceCode":"                    )\n                except RuntimeError as exc:\n                    # A ggml unsupported-op abort killed the server: this graph cannot run on the GPU backend at all, so restart the model on the CPU backend once and retry this chunk. Any other death propagates.\n                    server = self._restart_server_on_cpu_backend(state, str(exc), cancel)\n                    if server is None:\n                        raise\n                    state = replace(state, server = server)\n                    with self._lock:\n                        if self._state is not None and self._state.server is not None:\n                            self._state = state\n                    blobs = server.img_gen(\n                        payload,\n                        on_step = self._on_log,\n                        cancel_event = cancel,\n                        total_timeout = max(deadline - time.monotonic(), 1.0),\n                    )\n                # All-or-nothing per chunk: fail rather than silently drop images from the batch.\n                if not cancel.is_set() and len(blobs) != count:\n                    raise RuntimeError(\n                        f\"sd-server returned {len(blobs)} of {count} requested images in the batch.\"\n                    )\n                images.extend(Image.open(io.BytesIO(b)).convert(\"RGB\") for b in blobs)\n                # sd.cpp advances the seed per image within a job, so report chunk_seed+i.\n                seeds.extend((chunk_seed + i) & ((1 << 63) - 1) for i in range(len(blobs)))\n        finally:\n            if lora_stage is not None:\n                shutil.rmtree(lora_stage, ignore_errors = True)\n        return images, seeds\n\n    def _restart_server_on_cpu_backend(\n        self, state: _SdState, error_text: str, cancel: threading.Event\n    ) -> Optional[SdCppServer]:\n        \"\"\"Relaunch this checkpoint's sd-server with ``--backend cpu``; None if that does not apply.\n\n        ggml's Metal backend checks every node against ``ggml_metal_device_supports_op`` and calls\n        ``GGML_ABORT`` when one is not implemented for that device, because a single-backend graph\n        has nowhere else to put the node -- there is no per-op CPU fallback. The whole sd-server","sourceCodeStart":2282,"sourceCodeEnd":2318,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/sd_cpp_backend.py#L2282-L2318","documentation":"The sd-server img_gen call returned fewer image blobs than the requested batch count for a chunk. The backend enforces all-or-nothing per chunk: a partial batch is failed loudly rather than silently returning fewer images, because seeds and image positions in the batch would desync. It is skipped only when the cancel event is set (cancellation path takes over).","triggerScenarios":"Requesting batch_size > 1 (or a chunked batch) and the server returns len(blobs) != count while not cancelled — e.g. server-side crash mid-batch, truncated response, or a server bug dropping images.","commonSituations":"Large batches on memory-constrained GPUs where the server dies partway; mismatches between client and server batch semantics after a version change.","solutions":["Retry the generation; transient server drops usually resolve on a fresh job.","Reduce batch_size (or chunk size) to lower per-job memory pressure.","If it reproduces deterministically, capture the sd-server log tail and check for OOM/crash lines; restart or reload the server.","Verify the installed sd-server version matches what the backend expects (reinstall via the studio updater)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"assert count >= 1 and batch_size >= 1, \"batch count must be positive\"","typeGuard":null,"tryCatchPattern":"try:\n    images, seeds = backend.generate(...)\nexcept RuntimeError as e:\n    if \"requested images in the batch\" in str(e):\n        retry_with_smaller_batch()\n    raise","preventionTips":["Keep batch_size modest relative to available VRAM.","Watch server memory trends across batches; restart the server when fragmentation builds up.","Treat partial-batch failures as retryable, and surface which chunk failed."],"tags":["diffusion","sd-cpp","batch","partial-result"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}