* feat(collector): compressed worker -> master result transfer Workers sent every frame as an uncompressed PNG (compress_level=0), base64-encoded inside a JSON request, one request per frame. For cloud workers this makes result download (egress) the dominant transfer cost: a 121-frame 720p batch is ~446 MB per worker. Add `transfer_format` / `transfer_quality` optional widgets to Distributed Collector: - legacy_png (default): unchanged behaviour - png, ffv1: lossless, bit-identical master tensors to legacy_png - jpeg, webp: lossy stills - h264, h265, av1: lossy video of the whole batch Compressed results are posted as multipart/form-data chunks (binary, no base64, ~32 MB soft cap per request, configurable with COMFYUI_DISTRIBUTED_TRANSFER_CHUNK_BYTES). The master decodes each chunk off the event loop and enqueues one item per frame, so collection, ordering and audio handling are unchanged. Encoding also runs in an executor on the worker. Compatibility: - /distributed/job_complete still accepts the legacy JSON envelope. - A worker talking to an older master gets a 400 on the first chunk and resends everything as legacy_png. - Missing video encoders fall back to h264 (lossy) or png (ffv1). Measured on 121 frames at 1280x720: png 163 MB (2.7x), ffv1 128 MB (3.5x), h264 q90 2.4 MB (186x, 40.2 dB), av1 q90 0.4 MB. Also clips IMAGE values before 8-bit quantization on the new path so out-of-range values no longer wrap around. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0166t8T3CVaxZkJbP2RtSpo6 * fix(collector): wire transfer options through V3 node; bound finalized payload size Addresses review on #97. V3 integration - Add optional `transfer_format` / `transfer_quality` inputs to the registered nodes/v3.py DistributedCollector schema (legacy defaults) and accept/forward them in execute() to the runtime helper. - tests/test_v3_collector_transfer.py checks the registered node's public schema and argument forwarding without a ComfyUI checkout; the opt-in real-runtime acceptance (tests/helpers/v3_runtime_check.py) now allows exactly these appended optional inputs, verifies their contract, and checks forwarding through the real executor. Payload size bound - encode_chunks() enforces limits on finalized bytes (after encoder flush and muxer finalization). Encoder lookahead kept the pre-flush buffer near zero, so a chunk could hold the whole batch and finalize far above the limit. Oversized video chunks are re-encoded with proportionally fewer frames; the next chunk is sized from observed bytes/frame. - Multi-frame chunks stay within TRANSFER_MAX_CHUNK_BYTES (32 MiB); a single frame may use up to TRANSFER_MAX_REQUEST_BYTES (96 MiB, new, COMFYUI_DISTRIBUTED_TRANSFER_MAX_REQUEST_BYTES) minus envelope reserve. A frame that cannot fit raises FrameTooLargeError. - The worker encodes all chunks before sending, so an unfittable frame fails before anything is delivered (no partial batch on the master). - Audio rides on the last chunk only when the request stays in bounds; otherwise it is sent as a final audio-only completion. - Legacy fallback triggers only on an older master's rejection ("Invalid JSON payload"); other errors, e.g. size limits, raise with a pointer to the limit settings instead of resending as legacy_png. - The master returns 413 when a request exceeds --max-upload-size. Tests: codec flush-overshoot and single-frame cases, worker fallback / nothing-sent / audio placement, and real aiohttp server tests with client_max_size covering bounded high-entropy video, 413 reporting, and unfittable frames. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0166t8T3CVaxZkJbP2RtSpo6 --------- Co-authored-by: ymiyad <ymiyad@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
126 lines
4.4 KiB
Python
126 lines
4.4 KiB
Python
"""Registered V3 DistributedCollector: transfer options in the public schema and forwarded to the runtime.
|
|
|
|
Runs without a ComfyUI checkout by loading nodes/v3.py against a recording
|
|
stand-in for comfy_api's io module. tests/test_v3_migration.py covers the same
|
|
boundary against the real framework when COMFYUI_SOURCE_ROOT is set.
|
|
"""
|
|
import importlib.util
|
|
import sys
|
|
import types
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
PKG = "dist_v3_transfer_testpkg"
|
|
|
|
|
|
class _Field:
|
|
def __init__(self, kind, id=None, **kwargs):
|
|
self.kind = kind
|
|
self.id = id
|
|
self.kwargs = kwargs
|
|
|
|
|
|
def _io_type(kind):
|
|
return types.SimpleNamespace(
|
|
Input=lambda id, **kw: _Field(kind, id, **kw),
|
|
Output=lambda id=None, **kw: _Field(kind, id, **kw),
|
|
)
|
|
|
|
|
|
def _fake_io():
|
|
io = types.ModuleType("io")
|
|
|
|
class ComfyNode:
|
|
pass
|
|
|
|
io.ComfyNode = ComfyNode
|
|
io.Schema = lambda **kw: types.SimpleNamespace(**kw)
|
|
io.NodeOutput = lambda *values, **kw: ("NodeOutput", values, kw)
|
|
io.NumberDisplay = types.SimpleNamespace(number="number")
|
|
io.Hidden = types.SimpleNamespace(unique_id="unique_id", extra_pnginfo="extra_pnginfo")
|
|
for name in ("Int", "Float", "String", "Boolean", "Combo", "Image", "Audio",
|
|
"AnyType", "Model", "Conditioning", "Vae"):
|
|
setattr(io, name, _io_type(name))
|
|
return io
|
|
|
|
|
|
@pytest.fixture
|
|
def v3(monkeypatch):
|
|
calls = []
|
|
|
|
class CollectorRuntime:
|
|
def run(self, **kwargs):
|
|
calls.append(kwargs)
|
|
return (kwargs["images"], kwargs["audio"])
|
|
|
|
def module(name, **attrs):
|
|
mod = types.ModuleType(name)
|
|
mod.__dict__.update(attrs)
|
|
monkeypatch.setitem(sys.modules, name, mod)
|
|
return mod
|
|
|
|
for name in [n for n in sys.modules if n == PKG or n.startswith(PKG + ".")]:
|
|
monkeypatch.delitem(sys.modules, name)
|
|
module(PKG, __path__=[])
|
|
module(f"{PKG}.nodes", __path__=[])
|
|
module(f"{PKG}.utils", __path__=[])
|
|
module(f"{PKG}.nodes.utilities")
|
|
module(f"{PKG}.nodes.distributed_upscale", UltimateSDUpscaleDistributed=object)
|
|
module(f"{PKG}.nodes.collector", DistributedCollectorNode=CollectorRuntime)
|
|
module("comfy", __path__=[])
|
|
module("comfy.samplers", KSampler=types.SimpleNamespace(SAMPLERS=["euler"], SCHEDULERS=["normal"]))
|
|
module("comfy_api", __path__=[])
|
|
module("comfy_api.v0_0_2", io=_fake_io())
|
|
|
|
codec_spec = importlib.util.spec_from_file_location(f"{PKG}.utils.transfer_codec", ROOT / "utils" / "transfer_codec.py")
|
|
codec = importlib.util.module_from_spec(codec_spec)
|
|
monkeypatch.setitem(sys.modules, f"{PKG}.utils.transfer_codec", codec)
|
|
codec_spec.loader.exec_module(codec)
|
|
|
|
spec = importlib.util.spec_from_file_location(f"{PKG}.nodes.v3", ROOT / "nodes" / "v3.py")
|
|
mod = importlib.util.module_from_spec(spec)
|
|
monkeypatch.setitem(sys.modules, f"{PKG}.nodes.v3", mod)
|
|
spec.loader.exec_module(mod)
|
|
return mod, codec, calls
|
|
|
|
|
|
def test_registered_collector_schema_exposes_optional_transfer_inputs(v3):
|
|
mod, codec, _ = v3
|
|
schema = mod.DistributedCollector.define_schema()
|
|
inputs = {field.id: field for field in schema.inputs}
|
|
|
|
assert [field.id for field in schema.inputs] == [
|
|
"load_balance", "images", "audio", "transfer_format", "transfer_quality"]
|
|
fmt = inputs["transfer_format"]
|
|
assert fmt.kind == "Combo"
|
|
assert fmt.kwargs["options"] == list(codec.TRANSFER_FORMATS)
|
|
assert fmt.kwargs["default"] == "legacy_png"
|
|
assert fmt.kwargs["optional"] is True
|
|
quality = inputs["transfer_quality"]
|
|
assert quality.kind == "Int"
|
|
assert (quality.kwargs["default"], quality.kwargs["min"], quality.kwargs["max"]) == (90, 1, 100)
|
|
assert quality.kwargs["optional"] is True
|
|
assert schema.is_input_list is True
|
|
|
|
|
|
def test_registered_collector_forwards_transfer_options(v3):
|
|
mod, _, calls = v3
|
|
|
|
mod.DistributedCollector.execute(images=["img"], audio=[None], transfer_format=["av1"], transfer_quality=[70],
|
|
multi_job_id=["job"], is_worker=[True])
|
|
|
|
assert calls[-1]["transfer_format"] == ["av1"]
|
|
assert calls[-1]["transfer_quality"] == [70]
|
|
assert calls[-1]["multi_job_id"] == ["job"]
|
|
|
|
|
|
def test_registered_collector_defaults_to_legacy_transfer(v3):
|
|
mod, _, calls = v3
|
|
|
|
mod.DistributedCollector.execute(images=["img"])
|
|
|
|
assert calls[-1]["transfer_format"] == "legacy_png"
|
|
assert calls[-1]["transfer_quality"] == 90
|