Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(z-image): filter the quantization side-channel in place

Alexander Eichhorn988f00c788ab
diff --git a/invokeai/backend/model_manager/load/model_loaders/z_image.py b/invokeai/backend/model_manager/load/model_loaders/z_image.py
index 5b8c3ec977..70453f7fe8 100644
--- a/invokeai/backend/model_manager/load/model_loaders/z_image.py
+++ b/invokeai/backend/model_manager/load/model_loaders/z_image.py
@@ -507,7 +507,13 @@ class ZImageCheckpointModel(ModelLoader):
# above, which carries them (and their scales) through the fused-QKV split onto the module
# names the model actually has -- so no re-keying is needed here.
int8_markers = extract_int8_convrot_markers(sd)
- sd = drop_unconsumed_quantization_sidecars(sd)
+ # Filtered in place rather than rebound: the `sd.clear()` below has to reach the same dict
+ # the checkpoint was read into, or the originals stay alive through it and peak RAM
+ # overshoots the `make_room()` reservation (see test_state_dict_is_released_before_the_fp8_cast).
+ kept = drop_unconsumed_quantization_sidecars(sd)
+ sd.clear()
+ sd.update(kept)
+ del kept
orphans = sorted(k for k, v in sd.items() if v.dtype is torch.int8 and k[: -len(".weight")] not in int8_markers)
if orphans:
raise ValueError(