{"record":{"id":"726958ef85c339f0","repo":"invoke-ai/InvokeAI","slug":"expected-pidnet-for-pid-decoder-got-type-pid-net-726958","errorCode":null,"errorMessage":"Expected PidNet for PiD decoder, got {type(pid_net).__name__}.","messagePattern":"Expected PidNet for PiD decoder, got (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/sdxl_pid_decode.py","lineNumber":184,"sourceCode":"        # Gemma is only needed for the one-shot caption encode above. Offload it from VRAM (keeping it in the RAM\n        # cache) so its ~5GB is freed before the PiD decoder loads. The cache offloads anything else it needs to\n        # fit the decode on its own, so we deliberately do NOT evict every other model here.\n        context.models.offload_from_vram(self.gemma2_encoder.text_encoder)\n        TorchDevice.empty_cache()\n\n        # 3) Run PiD decode (the loader already returns a live PidNet).\n        pid_info = context.models.load(self.pid_decoder.decoder)\n        # Read once: the estimate and the decode must agree, or the cache reserves headroom for a\n        # peak that will not happen (or too little for one that will).\n        pid_memory_optimization = context.config.get().pid_memory_optimization\n        estimated_working_memory = estimate_pid_decode_working_memory(\n            latents,\n            BaseModelType.StableDiffusionXL,\n            pid_memory_optimization,\n        )\n        with pid_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, pid_net):\n            if not isinstance(pid_net, PidNet):\n                raise TypeError(f\"Expected PidNet for PiD decoder, got {type(pid_net).__name__}.\")\n            device = TorchDevice.choose_torch_device()\n            dtype = next(iter(pid_net.parameters())).dtype\n\n            # SDXL latents come out of the LDM in the VAE-normalized space; denormalise so PiD sees the raw latent.\n            denorm_latent = latents.to(device=device, dtype=dtype) / scaling_factor + shift_factor\n            caption_embs = caption_embs.to(device=device, dtype=dtype)\n\n            context.util.signal_progress(\"Running PiD decoder\")\n            decoder = PiDDecoder(pid_net, backbone=BaseModelType.StableDiffusionXL)\n            x0 = decoder.decode(\n                latent=denorm_latent,\n                caption_embs=caption_embs,\n                caption_mask=caption_mask,\n                config=PiDDecodeConfig(\n                    num_inference_steps=self.num_inference_steps,\n                    seed=self.seed,\n                    pid_memory_optimization=pid_memory_optimization,\n                ),","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/sdxl_pid_decode.py#L166-L202","documentation":"After loading the PiD (decode) network onto the device with a working-memory budget, the code asserts the loaded object is actually a PidNet instance before decoding SDXL latents. Any other type means the wrong model was wired into the decoder field or the model record is misregistered.","triggerScenarios":"model_on_device(working_mem_bytes=estimated_working_memory) for the PiD model returns a non-PidNet object — wrong model record connected to the PiD decode node, wrong submodel_type on the record, or a loader class mismatch.","commonSituations":"Connecting a VAE or other checkpoint into the PiD decoder input; a model record imported with an incorrect type tag; custom third-party model registered under the wrong loader class.","solutions":["Connect a genuine PiD model record to the PiD decode node and re-run.","Re-register/re-import the PiD model so its record is typed correctly.","Check that the model's loader/class config maps to the PidNet class.","If memory pressure caused a fallback loader path, raise working memory or move the model to CPU."],"exampleFix":"// before\nwith pid_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, pid_net):\n    if not isinstance(pid_net, PidNet):\n        raise TypeError(...)\n// after\nwith pid_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, pid_net):\n    if not isinstance(pid_net, PidNet):\n        raise TypeError(f\"Expected PidNet, got {type(pid_net).__name__}; check the model wired to the decoder.\")","handlingStrategy":"type-guard","validationCode":"if node.pid_model.base_model != BaseModelType.StableDiffusionXL:\n    raise ValueError(\"PiD decoder requires an SDXL PiD model\")","typeGuard":"def is_pid_net(obj) -> bool:\n    return isinstance(obj, PidNet)","tryCatchPattern":"try:\n    result = invoke(context)\nexcept TypeError as e:\n    if \"PidNet\" in str(e):\n        fix_pid_model_binding(graph)\n        retry(context)\n    else:\n        raise","preventionTips":["Wire only PiD-typed model records into the decoder node","Verify model type tags after importing third-party models","Increase working memory budget if loads fall back unexpectedly"],"tags":["type-check","pid-decode","model-loading"],"backgroundTag":"model-type-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}