@@ -414,6 +414,7 @@ def __init__(self, model_patch, vae, control_video, mask, source_video, strength
414414 self .control_latent = None
415415 self .control_latent_shape = None
416416 self .control_stream = None
417+ self .pristine_stream = None
417418 self .active = False
418419
419420 def _fit_frames (self , frames , frame_count , width , height ):
@@ -472,26 +473,28 @@ def diffusion_model_wrapper(self, executor, x, timestep, context, transformer_op
472473 self .active = self .sigma_end <= sigma <= self .sigma_start
473474 self .control_stream = None
474475 if self .active :
475- payload = kwargs .get ("minimax_payload" ) or {}
476- if payload .get ("keyframes" ) or payload .get ("refs" ):
477- raise ValueError ("MiniMax H3 Fun ControlNet does not support keyframe or reference conditioning" )
478476 self .prepare_control_latent (x [0 ].shape )
479477 try :
480478 return executor (x , timestep , context , transformer_options , ** kwargs )
481479 finally :
482480 self .control_stream = None
481+ self .pristine_stream = None
483482
484483 def before_block (self , block_index , args ):
485484 if not self .active or block_index != self .model_patch .model .injection_layers [0 ]:
486485 return
487- self .control_latent = self .control_latent .to (args ["img" ].device )
488- self .control_stream = self .model_patch .model .init_stream (
489- args ["img" ], self .control_latent , args ["layout" ], args ["t_emb" ])
486+ # stash only: control weight loads here would clobber the base block's freshly staged weights
487+ self .pristine_stream = args ["img" ].clone ()
490488
491489 def after_block (self , block_index , args , out ):
492490 if not self .active :
493491 return out
494492 control_index = self .model_patch .model .injection_layers .index (block_index )
493+ if control_index == 0 :
494+ self .control_latent = self .control_latent .to (out ["img" ].device )
495+ self .control_stream = self .model_patch .model .init_stream (
496+ self .pristine_stream , self .control_latent , args ["layout" ], args ["t_emb" ])
497+ self .pristine_stream = None
495498 self .control_stream , skip = self .model_patch .model .step (
496499 control_index , self .control_stream , args ["t_emb" ], args ["mod_segments" ], args ["rope_freqs" ],
497500 transformer_options = args ["transformer_options" ])
@@ -510,6 +513,7 @@ def cleanup(self):
510513 self .control_latent = None
511514 self .control_latent_shape = None
512515 self .control_stream = None
516+ self .pristine_stream = None
513517 self .active = False
514518
515519 def models (self ):
0 commit comments