diff --git a/samplers.py b/samplers.py index 127174f3..3d9f4a3d 100644 --- a/samplers.py +++ b/samplers.py @@ -1348,7 +1348,8 @@ class FunPackLTXAVSceneChainSampler: try: grad = _vf.gradient(cond) d = torch.nn.functional.normalize(grad.float(), dim=-1).to(cond.dtype) - except Exception: + except Exception as _e: + print(f"[FunPackSceneChain] embed_guidance: value function gradient failed ({_e}), using fixed direction") d = _fixed.to(cond.device, cond.dtype).expand_as(cond) else: d = _fixed.to(cond.device, cond.dtype).expand_as(cond) diff --git a/value_function.py b/value_function.py index 606cc60a..f53c92cc 100644 --- a/value_function.py +++ b/value_function.py @@ -73,11 +73,12 @@ class OnlineValueFunction(nn.Module): def gradient(self, conditioning): """∂reward/∂conditioning — same shape as input.""" + mlp_device = next(self.parameters()).device with torch.inference_mode(False), torch.enable_grad(): - c_in = conditioning.detach().clone().float().requires_grad_(True) + c_in = conditioning.detach().clone().float().to(mlp_device).requires_grad_(True) reward = self.forward(self.compress(c_in).unsqueeze(0)) reward.backward() - return c_in.grad.to(conditioning.dtype) + return c_in.grad.to(conditioning.device, conditioning.dtype) def is_ready(self): return len(self.buffer_c) >= self.MIN_SAMPLES