From 65b2c0361fad2d904dbc25125bdaaf4145eac702 Mon Sep 17 00:00:00 2001 From: izum <61049049+izumkineno@users.noreply.github.com> Date: Wed, 1 Apr 2026 07:42:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96encode=5Ftoken=5Fweights?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E4=BB=A5=E4=BF=9D=E6=8C=81CLIP=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E4=B8=8EComfyUI=E6=A0=B8=E5=BF=83=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E4=B8=80=E8=87=B4=20(#377)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit seems a additional update --- py/bnk_adv_encode.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/py/bnk_adv_encode.py b/py/bnk_adv_encode.py index b3d251f..739180c 100644 --- a/py/bnk_adv_encode.py +++ b/py/bnk_adv_encode.py @@ -221,12 +221,16 @@ def encode_token_weights_l(model, token_weight_pairs): l_out, _ = model.clip_l.encode_token_weights(token_weight_pairs) return l_out, None -def encode_token_weights(model, token_weight_pairs, encode_func): - if model.layer_idx is not None: - model.cond_stage_model.set_clip_options({"layer": model.layer_idx}) - - model_management.load_model_gpu(model.patcher) - return encode_func(model.cond_stage_model, token_weight_pairs) +def encode_token_weights(model, token_weight_pairs, encode_func): + # Keep CLIP options aligned with ComfyUI's core encode path so token + # tensors are created on the same device as the active text encoder pass. + model.cond_stage_model.reset_clip_options() + if model.layer_idx is not None: + model.cond_stage_model.set_clip_options({"layer": model.layer_idx}) + + model_management.load_model_gpu(model.patcher) + model.cond_stage_model.set_clip_options({"execution_device": model.patcher.load_device}) + return encode_func(model.cond_stage_model, token_weight_pairs) def prepareXL(embs_l, embs_g, pooled, clip_balance): l_w = 1 - max(0, clip_balance - .5) * 2