Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Use the end token for the text encoder attention mask.

comfyanonymous56333d48508f
diff --git a/comfy/sd1_clip.py b/comfy/sd1_clip.py
index ff6db0d20..e7ebf046d 100644
--- a/comfy/sd1_clip.py
+++ b/comfy/sd1_clip.py
@@ -168,11 +168,11 @@ class SDClipModel(torch.nn.Module, ClipTokenWeightEncoder):
attention_mask = None
if self.enable_attention_masks:
attention_mask = torch.zeros_like(tokens)
- max_token = self.transformer.get_input_embeddings().weight.shape[0] - 1
+ end_token = self.special_tokens.get("end", -1)
for x in range(attention_mask.shape[0]):
for y in range(attention_mask.shape[1]):
attention_mask[x, y] = 1
- if tokens[x, y] == max_token:
+ if tokens[x, y] == end_token:
break
outputs = self.transformer(tokens, attention_mask, intermediate_output=self.layer_idx, final_layer_norm_intermediate=self.layer_norm_hidden_state)