From 3003fb81934a7246d858a0caa2f9047d1f89a587 Mon Sep 17 00:00:00 2001 From: JasonHoku Date: Sat, 7 Mar 2026 14:06:56 -0800 Subject: [PATCH] fix: add torch.inference_mode to worker thread for Dynamic VRAM compat Worker threads run outside ComfyUI's execution engine which wraps everything in torch.inference_mode(). Without it, Dynamic VRAM's lazy weight loading produces NaN during VAE decode, causing black images. Matches ComfyUI's execution.py:703 pattern. Co-Authored-By: Claude Opus 4.6 --- distribution_worker.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/distribution_worker.py b/distribution_worker.py index 51f3f97..65fa776 100644 --- a/distribution_worker.py +++ b/distribution_worker.py @@ -434,6 +434,7 @@ class WorkerThread(threading.Thread): print(f"[Worker {self.worker_id}] ⚠️ Claim failed: {e}") return None + @torch.inference_mode() def _process_job(self, job): """ Process a single job using local ComfyUI infrastructure. @@ -451,6 +452,11 @@ class WorkerThread(threading.Thread): Returns: tuple: (image_bytes, metadata_dict) + + Note: @torch.inference_mode() is required because worker threads run + outside ComfyUI's execution engine which wraps everything in + inference_mode. Without it, Dynamic VRAM's lazy weight loading can + produce NaN values during VAE decode. """ from .model_loader import ( load_checkpoint, load_loras, load_vae_by_name,