diff --git a/comfy/context_windows.py b/comfy/context_windows.py index 5f9899c67..a7a25ff84 100644 --- a/comfy/context_windows.py +++ b/comfy/context_windows.py @@ -955,6 +955,8 @@ def create_weights_overlap_linear(length: int, full_length: int, idxs: list[int] # based on code in Kijai's WanVideoWrapper: https://github.com/kijai/ComfyUI-WanVideoWrapper/blob/dbb2523b37e4ccdf45127e5ae33e31362f755c8e/nodes.py#L1302 # only expected overlap is given different weights weights_torch = torch.ones((length)) + if context_overlap <= 0: + return weights_torch # blend left-side on all except first window if min(idxs) > 0: ramp_up = torch.linspace(1e-37, 1, context_overlap) diff --git a/tests-unit/comfy_test/context_windows_test.py b/tests-unit/comfy_test/context_windows_test.py new file mode 100644 index 000000000..40625784e --- /dev/null +++ b/tests-unit/comfy_test/context_windows_test.py @@ -0,0 +1,29 @@ +import sys +from unittest.mock import MagicMock, patch + +import torch + +# comfy.model_management initializes the torch device at import time and requires +# CUDA (or --cpu), which the unit-test environment does not provide. Stub it so +# importing comfy.context_windows does not trigger device initialization. +with patch.dict(sys.modules, {"comfy.model_management": MagicMock()}): + from comfy.context_windows import create_weights_overlap_linear + + +class TestCreateWeightsOverlapLinear: + def test_zero_overlap_returns_ones(self): + # context_overlap == 0 is reachable (the context-window nodes allow min=0, + # and the WAN/LTXV nodes derive it via max(overlap // 4, 0)). With no overlap + # band there is nothing to blend, so every weight is 1. + w = create_weights_overlap_linear(16, 100, list(range(20, 36)), 0) + assert w.shape == (16,) + assert torch.equal(w, torch.ones(16)) + + def test_overlap_ramps_edges(self): + w = create_weights_overlap_linear(16, 100, list(range(20, 36)), 4) + assert w.shape == (16,) + # middle (non-first) window: left edge ramps up to 1 over the overlap width + assert w[0] < w[3] + assert torch.isclose(w[3], torch.tensor(1.0)) + # right edge ramps back down + assert w[-1] < w[-4]