From e999a96d9bdf9e9f1277afb0b1961e00a162f6df Mon Sep 17 00:00:00 2001 From: digital-garbage <133010426+digital-garbage@users.noreply.github.com> Date: Fri, 29 May 2026 04:40:55 +0300 Subject: [PATCH] Fix value function loading: torch.load inside inference_mode(False) Model weights loaded via torch.load inside ComfyUI's inference_mode become inference tensors and can't participate in backward. Wrapping the load in inference_mode(False) ensures parameters are normal autograd tensors. Co-Authored-By: Claude Sonnet 4.6 --- samplers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/samplers.py b/samplers.py index 3d9f4a3d..b00afa0d 100644 --- a/samplers.py +++ b/samplers.py @@ -1296,10 +1296,12 @@ class FunPackLTXAVSceneChainSampler: except ImportError: from value_function import OnlineValueFunction from conditioning import refinement_state_path + import os as _os path = refinement_state_path(refinement_key, "value_fn", prefix="refine_v2", extension="pt") - if not __import__("os").path.exists(path): + if not _os.path.exists(path): return None - vf = OnlineValueFunction.load(path) + with torch.inference_mode(False): + vf = OnlineValueFunction.load(path) return vf if vf.is_ready() else None except Exception: return None