mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
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:
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -216,9 +216,11 @@ def get_weighted_text_embeddings_sd15(
|
||||
, generator = torch.Generator(text2img_pipe.device).manual_seed(2)
|
||||
).images[0]
|
||||
"""
|
||||
original_clip_layers = pipe.text_encoder.text_model.encoder.layers
|
||||
# transformers >=5.6 flattened CLIPTextModel; CLIPTextModelWithProjection still nests it under .text_model
|
||||
clip_text_model = getattr(pipe.text_encoder, 'text_model', pipe.text_encoder)
|
||||
original_clip_layers = clip_text_model.encoder.layers
|
||||
if clip_skip > 0:
|
||||
pipe.text_encoder.text_model.encoder.layers = original_clip_layers[:-clip_skip]
|
||||
clip_text_model.encoder.layers = original_clip_layers[:-clip_skip]
|
||||
|
||||
eos = pipe.tokenizer.eos_token_id
|
||||
prompt_tokens, prompt_weights = get_prompts_tokens_with_weights(
|
||||
@@ -310,7 +312,7 @@ def get_weighted_text_embeddings_sd15(
|
||||
|
||||
# recover clip layers
|
||||
if clip_skip > 0:
|
||||
pipe.text_encoder.text_model.encoder.layers = original_clip_layers
|
||||
clip_text_model.encoder.layers = original_clip_layers
|
||||
|
||||
return prompt_embeds, neg_prompt_embeds
|
||||
|
||||
|
||||
Reference in New Issue
Block a user