Skip to content

Commit daa9439

Browse files
comfyanonymouslrivera
authored andcommitted
Fix lowvram issue with ltxv2 text encoder. (Comfy-Org#11675)
1 parent 23a3d66 commit daa9439

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

comfy/ldm/lightricks/embeddings_connector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def forward(
276276
max(1024, hidden_states.shape[1]) / self.num_learnable_registers
277277
)
278278
learnable_registers = torch.tile(
279-
self.learnable_registers, (num_registers_duplications, 1)
279+
self.learnable_registers.to(hidden_states), (num_registers_duplications, 1)
280280
)
281281

282282
hidden_states = torch.cat((hidden_states, learnable_registers[hidden_states.shape[1]:].unsqueeze(0).repeat(hidden_states.shape[0], 1, 1)), dim=1)

comfy/text_encoders/lt.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,19 @@ def __init__(self, dtype_llama=None, device="cpu", dtype=None, model_options={})
8686
)
8787

8888
def set_clip_options(self, options):
89+
self.execution_device = options.get("execution_device", self.execution_device)
8990
self.gemma3_12b.set_clip_options(options)
9091

9192
def reset_clip_options(self):
9293
self.gemma3_12b.reset_clip_options()
94+
self.execution_device = None
9395

9496
def encode_token_weights(self, token_weight_pairs):
9597
token_weight_pairs = token_weight_pairs["gemma3_12b"]
9698

9799
out, pooled, extra = self.gemma3_12b.encode_token_weights(token_weight_pairs)
98100
out_device = out.device
99-
out = out.movedim(1, -1).to(self.text_embedding_projection.weight.device)
101+
out = out.movedim(1, -1).to(self.execution_device)
100102
out = 8.0 * (out - out.mean(dim=(1, 2), keepdim=True)) / (out.amax(dim=(1, 2), keepdim=True) - out.amin(dim=(1, 2), keepdim=True) + 1e-6)
101103
out = out.reshape((out.shape[0], out.shape[1], -1))
102104
out = self.text_embedding_projection(out)

0 commit comments

Comments
 (0)