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
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.
Source
Thrown at invokeai/app/invocations/flux2_pid_decode.py:216
# 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()
# 4) Run PiD decode (the loader already returns a live PidNet).
pid_info = context.models.load(self.pid_decoder.decoder)
# The working-memory estimate scales with the OUTPUT pixel count, so it must see the PACKED latent
# (spatial H/16), not the unpacked one - otherwise it over-reserves by 4x.
# 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(
packed,
BaseModelType.Flux2,
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
# The packed latent is already BN-denormalized (raw VAE-input space); the scalar transform below is
# identity for current FLUX.2 VAEs and only bites if a VAE ever exposes real scalar constants.
denorm_latent = packed.to(device=device, dtype=dtype) / scaling_factor + shift_factor
context.logger.info(
f"FLUX.2 PiD denorm_latent stats[min={denorm_latent.min().item():.3f} "
f"max={denorm_latent.max().item():.3f} mean={denorm_latent.mean().item():.3f}] "
f"using scale={scaling_factor:.4f} shift={shift_factor:.4f}"
)
caption_embs = caption_embs.to(device=device, dtype=dtype)
context.util.signal_progress("Running PiD decoder")
decoder = PiDDecoder(pid_net, backbone=BaseModelType.Flux2)
x0 = decoder.decode(
latent=denorm_latent,
caption_embs=caption_embs,View on GitHub (pinned to 0b6a024f2f)
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
Example fix
// before: decoder key points at flux2 VAE decoder=ModelIdentifierField(key='flux2-vae-001') // after decoder=ModelIdentifierField(key='flux2-pid-decoder-001')
Defensive patterns
Strategy: type-guard
Validate before calling
pid_info = context.models.load(pid_decoder)
if type(pid_info.model).__name__ != 'PidNet':
raise TypeError(f'{pid_decoder.key} is not a PidNet') Type guard
def is_pid_net(obj) -> bool:
return isinstance(obj, PidNet) Try / catch
try:
result = pid_decode.invoke(context)
except TypeError as e:
if 'PidNet' in str(e):
redownload_pid_decoder_model()
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Expected PreTrainedModel for text encoder, got {type(text_en
- Expected PreTrainedTokenizerBase for tokenizer, got {type(to
- Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type
- Expected PreTrainedModel for Gemma encoder, got {type(gemma_
- Expected PreTrainedTokenizerBase for Gemma tokenizer, got {t
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/cd299eaeb2a2bd5f.
Report an issue: GitHub.