Skip to content
Python

Update pipeline_z_image.py to support Lora timing

Christopher Herrera7b66f7189639
diff --git a/models/z_image/pipeline_z_image.py b/models/z_image/pipeline_z_image.py
index 1a9c1c5..91e6acc 100644
--- a/models/z_image/pipeline_z_image.py
+++ b/models/z_image/pipeline_z_image.py
@@ -29,6 +29,7 @@ from mmgp import offload
from .z_image_transformer2d import ZImageTransformer2DModel
from .pipeline_output import ZImagePipelineOutput
from shared.utils.utils import get_outpainting_frame_location, resize_lanczos, calculate_new_dimensions, convert_image_to_tensor, fit_image_into_canvas
+from shared.utils.loras_mutipliers import update_loras_slists
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
@@ -335,6 +336,7 @@ class ZImagePipeline(DiffusionPipeline, FromSingleFileMixin):
NAG_scale: float = 1.0,
NAG_tau: float = 3.5,
NAG_alpha: float = 0.5,
+ loras_slists = None,
):
r"""
Function invoked when calling the pipeline for generation.
@@ -446,6 +448,7 @@ class ZImagePipeline(DiffusionPipeline, FromSingleFileMixin):
self._interrupt = False
self._cfg_normalization = cfg_normalization
self._cfg_truncation = cfg_truncation
+ self.transformer.loras_slists = loras_slists
# 2. Define call parameters
if prompt is not None and isinstance(prompt, str):
batch_size = 1
@@ -586,9 +589,15 @@ class ZImagePipeline(DiffusionPipeline, FromSingleFileMixin):
callback(-1, None, True, len(timesteps))
+ # Initialize LoRA scales if multipliers are provided
+ if hasattr(self.transformer, 'loras_slists') and self.transformer.loras_slists is not None:
+ update_loras_slists(self.transformer, self.transformer.loras_slists, len(timesteps))
+
# 6. Denoising loop
with self.progress_bar(total=num_inference_steps) as progress_bar:
for i, t in enumerate(timesteps):
+ # Set LoRA step number for dynamic weight updates
+ offload.set_step_no_for_lora(self.transformer, i)
if self.interrupt:
break