fix(prompt): restore textual inversion on clip-skip>=2

transformers 5.6 flattened CLIPTextModel, removing the .text_model wrapper that
compel_hijack and the xhinker parser dereference on the normalized clip-skip path.
On SD1.5 at clip-skip >= 2 this raised AttributeError, which processing_prompt
caught and silently fell back to fixed-attention encoding, dropping textual
inversion and prompt weighting.

Resolve the submodule via getattr(te, 'text_model', te), correct for flattened
CLIPTextModel, CLIPTextModelWithProjection (still nested), and transformers < 5.6.
This commit is contained in:
CalamitousFelicitousness
2026-06-25 02:06:05 +01:00
parent 7ed3cd71e0
commit aeef359bd7
2 changed files with 8 additions and 4 deletions
+3 -1
View File
@@ -327,7 +327,9 @@ def compel_hijack(self, token_ids: torch.Tensor, attention_mask: torch.Tensor |
else:
hidden_state = text_encoder_output.hidden_states[-clip_skip]
if normalized:
hidden_state = self.text_encoder.text_model.final_layer_norm(hidden_state)
# transformers >=5.6 flattened CLIPTextModel; CLIPTextModelWithProjection still nests it under .text_model
text_model = getattr(self.text_encoder, 'text_model', self.text_encoder)
hidden_state = text_model.final_layer_norm(hidden_state)
return hidden_state