invoke-ai/InvokeAI · error · TypeError

Expected PidNet for PiD decoder, got {type(pid_net).__name__

Error message

Expected PidNet for PiD decoder, got {type(pid_net).__name__}.

What it means

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.

Source

Thrown at invokeai/app/invocations/z_image_pid_decode.py:185

        # Gemma is only needed for the one-shot caption encode above. Offload it from VRAM (keeping it in the RAM
        # cache) so its ~5GB is freed before the PiD decoder loads. The cache offloads anything else it needs to
        # fit the decode on its own, so we deliberately do NOT evict every other model here.
        context.models.offload_from_vram(self.gemma2_encoder.text_encoder)
        TorchDevice.empty_cache()

        # 2) Run PiD decode (the loader already returns a live PidNet).
        pid_info = context.models.load(self.pid_decoder.decoder)
        # Read once: the estimate and the decode must agree, or the cache reserves headroom for a
        # peak that will not happen (or too little for one that will).
        pid_memory_optimization = context.config.get().pid_memory_optimization
        estimated_working_memory = estimate_pid_decode_working_memory(
            latents,
            BaseModelType.Flux,
            pid_memory_optimization,
        )
        with pid_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, pid_net):
            if not isinstance(pid_net, PidNet):
                raise TypeError(f"Expected PidNet for PiD decoder, got {type(pid_net).__name__}.")
            device = TorchDevice.choose_torch_device()
            dtype = next(iter(pid_net.parameters())).dtype

            # Z-Image latents come out of the diffusers pipeline normalised
            # by the VAE constants. PiD expects the raw latent.
            denorm_latent = latents.to(device=device, dtype=dtype) / scaling_factor + shift_factor
            context.logger.info(
                f"denorm_latent stats[min={denorm_latent.min().item():.3f} "
                f"max={denorm_latent.max().item():.3f} mean={denorm_latent.mean().item():.3f} "
                f"std={denorm_latent.float().std().item():.3f}]; "
                f"caption_embs shape={tuple(caption_embs.shape)} "
                f"stats[min={caption_embs.min().item():.3f} max={caption_embs.max().item():.3f} "
                f"mean={caption_embs.mean().item():.3f} std={caption_embs.float().std().item():.3f}]"
            )
            caption_embs = caption_embs.to(device=device, dtype=dtype)

            context.util.signal_progress("Running PiD decoder")
            decoder = PiDDecoder(pid_net, backbone=BaseModelType.Flux)

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Select/import the correct PiD decoder model so it is registered with the PidNet model type.
  2. Re-download the PiD decoder weights to rule out corruption.
  3. Update InvokeAI so PidNet loading matches the installed model format.
  4. Verify BaseModelType.Flux PiD submodel configuration in the model manager.
Defensive patterns

Strategy: type-guard

Validate before calling

with pid_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, net):
    if not isinstance(net, PidNet):
        fail_fast(net)

Type guard

def is_pidnet(obj) -> bool:
    return isinstance(obj, PidNet)

Try / catch

try:
    decode(context)
except TypeError as e:
    if "Expected PidNet for PiD decoder" in str(e):
        reimport_pid_decoder_model()
    else:
        raise

Prevention

When it happens

Trigger: Running the PiD decode invocation where the pid submodel, loaded under estimated_working_memory, does not satisfy isinstance(pid_net, PidNet).

Common situations: 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.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/8a5a013fa8b3dcd0. Report an issue: GitHub.