@@ -62,7 +62,16 @@ def encode_token_weights(self, token_weight_pairs):
6262 r = (out [- 1 :].to (model_management .intermediate_device ()), first_pooled )
6363 else :
6464 r = (torch .cat (output , dim = - 2 ).to (model_management .intermediate_device ()), first_pooled )
65- r = r + tuple (map (lambda a : a [:sections ].flatten ().unsqueeze (dim = 0 ).to (model_management .intermediate_device ()), o [2 :]))
65+
66+ if len (o ) > 2 :
67+ extra = {}
68+ for k in o [2 ]:
69+ v = o [2 ][k ]
70+ if k == "attention_mask" :
71+ v = v [:sections ].flatten ().unsqueeze (dim = 0 ).to (model_management .intermediate_device ())
72+ extra [k ] = v
73+
74+ r = r + (extra ,)
6675 return r
6776
6877class SDClipModel (torch .nn .Module , ClipTokenWeightEncoder ):
@@ -206,8 +215,12 @@ def forward(self, tokens):
206215 elif outputs [2 ] is not None :
207216 pooled_output = outputs [2 ].float ()
208217
218+ extra = {}
209219 if self .return_attention_masks :
210- return z , pooled_output , attention_mask
220+ extra ["attention_mask" ] = attention_mask
221+
222+ if len (extra ) > 0 :
223+ return z , pooled_output , extra
211224
212225 return z , pooled_output
213226
@@ -547,8 +560,8 @@ def reset_clip_options(self):
547560
548561 def encode_token_weights (self , token_weight_pairs ):
549562 token_weight_pairs = token_weight_pairs [self .clip_name ]
550- out , pooled = getattr (self , self .clip ).encode_token_weights (token_weight_pairs )
551- return out , pooled
563+ out = getattr (self , self .clip ).encode_token_weights (token_weight_pairs )
564+ return out
552565
553566 def load_sd (self , sd ):
554567 return getattr (self , self .clip ).load_sd (sd )
0 commit comments