{"record":{"id":"cd299eaeb2a2bd5f","repo":"invoke-ai/InvokeAI","slug":"expected-pidnet-for-pid-decoder-got-type-pid-net","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/flux2_pid_decode.py","lineNumber":216,"sourceCode":"        # 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        # 4) Run PiD decode (the loader already returns a live PidNet).\n        pid_info = context.models.load(self.pid_decoder.decoder)\n        # The working-memory estimate scales with the OUTPUT pixel count, so it must see the PACKED latent\n        # (spatial H/16), not the unpacked one - otherwise it over-reserves by 4x.\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            packed,\n            BaseModelType.Flux2,\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            # The packed latent is already BN-denormalized (raw VAE-input space); the scalar transform below is\n            # identity for current FLUX.2 VAEs and only bites if a VAE ever exposes real scalar constants.\n            denorm_latent = packed.to(device=device, dtype=dtype) / scaling_factor + shift_factor\n            context.logger.info(\n                f\"FLUX.2 PiD 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\"using scale={scaling_factor:.4f} shift={shift_factor:.4f}\"\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.Flux2)\n            x0 = decoder.decode(\n                latent=denorm_latent,\n                caption_embs=caption_embs,","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/flux2_pid_decode.py#L198-L234","documentation":"The PiD decoder network loaded for FLUX.2 decode must be an instance of the PidNet class. Any other class means the model record under the PiD model identifier is not a PiD net — corrupted, mislabeled, or an incompatible VAE/diffusion model.","triggerScenarios":"pid_info.model_on_device(working_mem_bytes=...) yields a non-PidNet object in invoke; the node's decoder field references a wrong model key or a corrupted download.","commonSituations":"PiD decoder files incompletely downloaded; a user-selected model key pointing at the FLUX.2 VAE or another backbone; model-manager records stale after upgrade; wrong model type chosen at import.","solutions":["Re-download the PiD decoder model through the model manager","Verify the decoder model identifier points at the FLUX.2 PiD net, not another model","Re-import the model with the correct model type so it loads as PidNet","Update InvokeAI if model-class detection changed between versions"],"exampleFix":"// before: decoder key points at flux2 VAE\ndecoder=ModelIdentifierField(key='flux2-vae-001')\n// after\ndecoder=ModelIdentifierField(key='flux2-pid-decoder-001')","handlingStrategy":"type-guard","validationCode":"pid_info = context.models.load(pid_decoder)\nif type(pid_info.model).__name__ != 'PidNet':\n    raise TypeError(f'{pid_decoder.key} is not a PidNet')","typeGuard":"def is_pid_net(obj) -> bool:\n    return isinstance(obj, PidNet)","tryCatchPattern":"try:\n    result = pid_decode.invoke(context)\nexcept TypeError as e:\n    if 'PidNet' in str(e):\n        redownload_pid_decoder_model()\n    raise","preventionTips":["Verify the decoder model key refers to the FLUX.2 PiD net","Check download completeness/hashes for PiD weights","Re-import with the correct model type after upgrades"],"tags":["model-loading","type-check","pidnet"],"backgroundTag":"model-type-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}