{"record":{"id":"8a5a013fa8b3dcd0","repo":"invoke-ai/InvokeAI","slug":"expected-pidnet-for-pid-decoder-got-type-pid-net-8a5a01","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/z_image_pid_decode.py","lineNumber":185,"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        # 2) 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.Flux,\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            # Z-Image latents come out of the diffusers pipeline normalised\n            # by the VAE constants. PiD expects the raw latent.\n            denorm_latent = latents.to(device=device, dtype=dtype) / scaling_factor + shift_factor\n            context.logger.info(\n                f\"denorm_latent stats[min={denorm_latent.min().item():.3f} \"\n                f\"max={denorm_latent.max().item():.3f} mean={denorm_latent.mean().item():.3f} \"\n                f\"std={denorm_latent.float().std().item():.3f}]; \"\n                f\"caption_embs shape={tuple(caption_embs.shape)} \"\n                f\"stats[min={caption_embs.min().item():.3f} max={caption_embs.max().item():.3f} \"\n                f\"mean={caption_embs.mean().item():.3f} std={caption_embs.float().std().item():.3f}]\"\n            )\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.Flux)","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/z_image_pid_decode.py#L167-L203","documentation":"z_image_pid_decode.py loads the PiD (pixel/image decoder) network with model_on_device(working_mem_bytes=...) and requires the resulting object to be an instance of PidNet before decoding latents. Any other loaded type raises a TypeError naming the actual class, preventing arbitrary modules from being treated as the PiD decoder.","triggerScenarios":"Running the PiD decode invocation where the pid submodel, loaded under estimated_working_memory, does not satisfy isinstance(pid_net, PidNet).","commonSituations":"The PiD decoder model was imported with the wrong model type/format; corrupted weights producing a generic module; a different decoder model selected in the node; InvokeAI version lacking/misclassifying PidNet for Flux models.","solutions":["Select/import the correct PiD decoder model so it is registered with the PidNet model type.","Re-download the PiD decoder weights to rule out corruption.","Update InvokeAI so PidNet loading matches the installed model format.","Verify BaseModelType.Flux PiD submodel configuration in the model manager."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"with pid_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, net):\n    if not isinstance(net, PidNet):\n        fail_fast(net)","typeGuard":"def is_pidnet(obj) -> bool:\n    return isinstance(obj, PidNet)","tryCatchPattern":"try:\n    decode(context)\nexcept TypeError as e:\n    if \"Expected PidNet for PiD decoder\" in str(e):\n        reimport_pid_decoder_model()\n    else:\n        raise","preventionTips":["Register the PiD decoder with the correct model type (PidNet / Flux) in the model manager.","Verify decoder weights integrity after download.","Select the PiD decoder node field explicitly rather than relying on auto-detection."],"tags":["type-check","pidnet","decoder","z-image"],"backgroundTag":"unexpected-model-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}