Skip to content

fix: Filter non-transformer keys from Z-Image checkpoint state dicts#8918

Merged
lstein merged 3 commits intoinvoke-ai:mainfrom
Pfannkuchensack:fix/z-image-filter-non-transformer-keys
Feb 28, 2026
Merged

fix: Filter non-transformer keys from Z-Image checkpoint state dicts#8918
lstein merged 3 commits intoinvoke-ai:mainfrom
Pfannkuchensack:fix/z-image-filter-non-transformer-keys

Conversation

@Pfannkuchensack
Copy link
Collaborator

Summary

Merged Z-Image checkpoints (e.g. models with LoRAs baked in) may bundle text encoder weights (text_encoders.*) or other non-transformer keys alongside the transformer weights. These cause load_state_dict() to fail with strict=True. Instead of disabling strict mode, explicitly whitelist valid ZImageTransformer2DModel key prefixes and discard everything else.

Also moves RAM allocation after filtering so it doesn't over-allocate for discarded keys.

Related Issues / Discussions

https://discord.com/channels/1020123559063990373/1149510134058471514/1476724553408319650
https://civitai.com/models/2358008/zimage-turbo-badmilk-1968

QA Instructions

  1. Load a merged Z-Image Turbo checkpoint (e.g. one with LoRAs baked in that contains text_encoders.* keys)
  2. Verify the model loads without errors
  3. Generate an image to confirm the transformer weights loaded correctly

Merge Plan

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • ❗Changes to a redux slice have a corresponding migration
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

Merged Z-Image checkpoints (e.g. models with LoRAs baked in) may bundle
text encoder weights (text_encoders.*) or other non-transformer keys
alongside the transformer weights. These cause load_state_dict() to fail
with strict=True. Instead of disabling strict mode, explicitly whitelist
valid ZImageTransformer2DModel key prefixes and discard everything else.

Also moves RAM allocation after filtering so it doesn't over-allocate
for discarded keys.
@github-actions github-actions bot added python PRs that change python files backend PRs that change backend files labels Feb 27, 2026
@lstein lstein added the v6.12.0 Intended for 6.12.0 release label Feb 27, 2026
@lstein lstein enabled auto-merge (squash) February 28, 2026 16:12
@lstein lstein merged commit 54c1609 into invoke-ai:main Feb 28, 2026
13 checks passed
@Pfannkuchensack Pfannkuchensack deleted the fix/z-image-filter-non-transformer-keys branch February 28, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend PRs that change backend files python PRs that change python files v6.12.0 Intended for 6.12.0 release

Projects

Status: 6.12.x

Development

Successfully merging this pull request may close these issues.

3 participants