From d5fd56541b86ae567f55cbfec7c117490c3544b8 Mon Sep 17 00:00:00 2001 From: Jason Hoku Date: Sat, 14 Mar 2026 02:27:20 -0700 Subject: [PATCH] fix: lazy-import torch/safetensors in network gateway, update stale comments Move torch and safetensors imports inside huggingface_vae_decode() so CivitAI and Distribution functions still work if those packages are missing. Update stale "Uses urllib" comments to reference the gateway. Co-Authored-By: Claude Opus 4.6 (1M context) --- distribution_routes.py | 2 +- distribution_worker.py | 2 +- network_utils.py | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/distribution_routes.py b/distribution_routes.py index 5c2b763..aba0865 100644 --- a/distribution_routes.py +++ b/distribution_routes.py @@ -548,7 +548,7 @@ def notify_workers_to_start(worker_urls, master_url, session_name, sync_models_t Notify remote worker ComfyUI instances to start processing. Sends POST /distribution/start_worker to each worker URL. - Uses urllib.request (no 'requests' library for ComfyUI Registry compliance). + Uses network_utils.py gateway for all outbound requests. Args: worker_urls: List of worker base URLs diff --git a/distribution_worker.py b/distribution_worker.py index 64ec5c8..4834f29 100644 --- a/distribution_worker.py +++ b/distribution_worker.py @@ -656,7 +656,7 @@ class WorkerThread(threading.Thread): def _submit_result(self, job_id, image_bytes, meta, max_retries=3): """ Upload image + metadata to master via multipart POST. - Uses urllib (no 'requests' library for ComfyUI Registry compliance). + Uses network_utils.py gateway for all outbound requests. Retries on transient network errors (connection reset, timeout). """ # JSON-safe meta (ensure no non-serializable types from config round-trip) diff --git a/network_utils.py b/network_utils.py index 23b4a45..44aed02 100644 --- a/network_utils.py +++ b/network_utils.py @@ -16,9 +16,6 @@ import urllib.request import urllib.error import urllib.parse -import torch -from safetensors.torch import _tobytes - # ============================================================================= # 1. CIVITAI API — Model/LoRA metadata lookup @@ -91,6 +88,11 @@ def huggingface_vae_decode(endpoint_url, tensor, height, width): ValueError: If endpoint_url is not in the allowlist RuntimeError: If the remote endpoint returns non-200 """ + # Lazy imports — only needed for HF VAE, avoids breaking CivitAI/Distribution + # if torch or safetensors are not installed + import torch + from safetensors.torch import _tobytes + # Validate endpoint against allowlist if endpoint_url not in HUGGINGFACE_VAE_ENDPOINTS.values(): raise ValueError(