Skip to content

Commit aedb908

Browse files
committed
Add version tuple check for ComfyUI version handling
Introduced a helper function to compare ComfyUI versions as tuples instead of strings, improving reliability of version-dependent logic in reshape_mask. Updated all version checks to use the new tuple-based comparison.
1 parent f9718ea commit aedb908

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/LanPaint/nodes.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
from comfy.model_base import WAN22
1313
import comfyui_version
1414

15+
def _version_tuple(value):
16+
return tuple(int(part) if part.isdigit() else 0 for part in value.split("."))
17+
18+
COMFYUI_VERSION_060_OR_NEWER = _version_tuple(comfyui_version.__version__) >= (0, 6, 0)
19+
1520
def reshape_mask(input_mask, output_shape,video_inpainting=False):
1621
dims = len(output_shape) - 2
1722
print('output shape',output_shape)
@@ -28,7 +33,7 @@ def reshape_mask(input_mask, output_shape,video_inpainting=False):
2833

2934
# Handle 5D output shape (B, C, F, H, W) by ensuring input is 5D
3035
if len(output_shape) == 5 and input_mask.ndim == 4:
31-
if comfyui_version.__version__ >= "0.6.0":
36+
if COMFYUI_VERSION_060_OR_NEWER:
3237
input_mask = input_mask.unsqueeze(2) # (B, C, 1, H, W)
3338

3439
# Handle video case with temporal dimension
@@ -41,7 +46,7 @@ def reshape_mask(input_mask, output_shape,video_inpainting=False):
4146
# First reshape input_mask to have proper dimensions for video processing
4247
# Assume input is (frames, channels, height, width) -> (1, channels, frames, height, width)
4348
## if comfy version < 0.6.0
44-
if comfyui_version.__version__ < "0.6.0":
49+
if not COMFYUI_VERSION_060_OR_NEWER:
4550
input_mask = input_mask.permute(1, 0, 2, 3).unsqueeze(0)
4651
print('Video case - input_mask after reshaping:', input_mask.shape)
4752
# Ensure we have the correct 5D shape: (batch, channels, frames, height, width)
@@ -65,7 +70,7 @@ def reshape_mask(input_mask, output_shape,video_inpainting=False):
6570
# Handle batch dimension
6671
mask = repeat_to_batch_size(mask, output_shape[0])
6772
else: # Original 2D image case
68-
if comfyui_version.__version__ < "0.6.0":
73+
if not COMFYUI_VERSION_060_OR_NEWER:
6974
mask = torch.nn.functional.interpolate(input_mask, size=output_shape[-2:], mode=scale_mode)
7075
else:
7176
mask = torch.nn.functional.interpolate(input_mask, size=output_shape[2:], mode=scale_mode)

0 commit comments

Comments
 (0)