From a37443d8f1644e1c262d556e62b36c882a6526b4 Mon Sep 17 00:00:00 2001 From: CalamitousFelicitousness Date: Mon, 4 May 2026 21:44:07 +0100 Subject: [PATCH] fix(ltx): wrap explicit encode_prompt in inference_context Upstream LTX2 encode_prompt is not @torch.no_grad-decorated; only __call__ is. Calling encode_prompt directly from ltx_process recorded the full Gemma3 forward graph. --- modules/ltx/ltx_process.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/ltx/ltx_process.py b/modules/ltx/ltx_process.py index e29c5fd79..4c5bdc26c 100644 --- a/modules/ltx/ltx_process.py +++ b/modules/ltx/ltx_process.py @@ -326,12 +326,13 @@ def run_ltx(task_id, extra_networks.activate(p, networks) # Encode once and reuse across stages; encode_prompt short-circuits when # embeds are passed to __call__. CPU park keeps them off GPU between stages. - prompt_embeds, prompt_attention_mask, negative_prompt_embeds, negative_prompt_attention_mask = shared.sd_model.encode_prompt( - prompt=prompt_final, - negative_prompt=negative_final, - do_classifier_free_guidance=True, - device=devices.device, - ) + with devices.inference_context(): + prompt_embeds, prompt_attention_mask, negative_prompt_embeds, negative_prompt_attention_mask = shared.sd_model.encode_prompt( + prompt=prompt_final, + negative_prompt=negative_final, + do_classifier_free_guidance=True, + device=devices.device, + ) prompt_embeds = prompt_embeds.cpu() prompt_attention_mask = prompt_attention_mask.cpu() if prompt_attention_mask is not None else None negative_prompt_embeds = negative_prompt_embeds.cpu() if negative_prompt_embeds is not None else None