@@ -1816,7 +1816,24 @@ def extra_conds_shapes(self, **kwargs):
18161816
18171817 def resize_cond_for_context_window (self , cond_key , cond_value , window , x_in , device , retain_index_list = []):
18181818 if cond_key in ("sam_latents" , "pose_latents" ):
1819- return comfy .context_windows .slice_cond (cond_value , window , x_in , device , temporal_dim = 2 , temporal_offset = 1 )
1819+ # Return sliced view omitting retain_index_list
1820+ return comfy .context_windows .slice_cond (cond_value , window , x_in , device , temporal_dim = 2 , temporal_offset = 0 )
1821+ if cond_key == "ref_mask_latents" and hasattr (cond_value , "cond" ) and isinstance (cond_value .cond , torch .Tensor ):
1822+ # The ref mask is just a single frame padded with frames of zeros, so just grab the first frames for all windows
1823+ full_ref_mask = cond_value .cond
1824+ video_frame_count = x_in .shape [2 ]
1825+ if full_ref_mask .shape [2 ] != video_frame_count + 1 :
1826+ return None
1827+ window_length = len (window .index_list )
1828+
1829+ # Account for the causal anchor frame if it exists
1830+ anchor_index = getattr (window , "causal_anchor_index" , None )
1831+ if anchor_index is not None and anchor_index >= 0 :
1832+ window_length += 1
1833+
1834+ window_ref_mask = full_ref_mask [:, :, :window_length + 1 ].to (device )
1835+ return cond_value ._copy_with (window_ref_mask )
1836+
18201837 return super ().resize_cond_for_context_window (cond_key , cond_value , window , x_in , device , retain_index_list = retain_index_list )
18211838
18221839 def concat_cond (self , ** kwargs ):
0 commit comments