{"record":{"id":"387e8760f82d4d8e","repo":"invoke-ai/InvokeAI","slug":"expected-pidnet-for-pid-decoder-got-type-pid-net-387e87","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/flux_pid_decode.py","lineNumber":142,"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            # FLUX latent is stored in normalised form (matching FluxAutoEncoder\n            # state); denormalise so PiD sees the same representation it\n            # consumed during training.\n            ae = get_flux_ae_params()\n            denorm_latent = latents.to(device=device, dtype=dtype) / ae.scale_factor + ae.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.Flux)\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,","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/flux_pid_decode.py#L124-L160","documentation":"The PiD decode invocation loads the PiD decoder network via model_on_device() and asserts the returned object is an instance of PidNet. Any other type (wrong model registered under the key, wrapper, or corrupted load) raises TypeError. This guarantees the decoder exposes the PidNet API (parameters, forward) used downstream.","triggerScenarios":"invoke() enters pid_info.model_on_device(working_mem_bytes=estimated_working_memory) and the yielded pid_net is not a PidNet instance — e.g., the selected VAE/decoder key resolves to a standard AutoencoderKL instead of the PiD network.","commonSituations":"Selecting a standard FLUX VAE where a PiD decoder model is expected; a model manager record with wrong model class; partial install of the PiD decoder model.","solutions":["Select the correct PiD decoder model record for the node's pid field","Reinstall/redownload the PiD decoder model if its record resolves to the wrong class","Verify the model's configured model type in the Model Manager matches PidNet","Print/inspect type(pid_net) to identify what object is actually being returned"],"exampleFix":"// before: standard VAE selected as decoder\npid_model=<flux_vae_autoencoderkl_key>\n// after\npid_model=<pidnet_decoder_model_key>","handlingStrategy":"type-guard","validationCode":"pid_info = context.models.load(pid_model)\n# confirm the record's model type is the PiD decoder, not a standard VAE","typeGuard":"def is_pid_net(obj) -> bool:\n    return isinstance(obj, PidNet)","tryCatchPattern":"try:\n    output = pid_decode.invoke(context)\nexcept TypeError as e:\n    if 'Expected PidNet' in str(e):\n        # select the actual PiD decoder model record\n        pass\n    else:\n        raise","preventionTips":["Select the dedicated PiD decoder model, not the standard FLUX VAE","Verify model class/type in the Model Manager before use","Reinstall the PiD decoder if its record resolves to the wrong class"],"tags":["type-error","pidnet","decoder","flux","invokeai"],"backgroundTag":"unexpected-model-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}