ComfyUI-LTXVideo icon indicating copy to clipboard operation
ComfyUI-LTXVideo copied to clipboard

Cannot import name 'pad'

Open Lu-Gru opened this issue 6 months ago • 16 comments

Hello, After today update I did run into problem with nodes:

Traceback (most recent call last):
  File "Y:\ai_ComfyUi\git_nv2\ComfyUI\nodes.py", line 2204, in load_custom_node
    module_spec.loader.exec_module(module)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 1023, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "Y:\ai_ComfyUi\git_nv2\ComfyUI\custom_nodes\ComfyUI-LTXVideo\__init__.py", line 48, in <module>
    from .pyramid_blending import LTXVLaplacianPyramidBlend
  File "Y:\ai_ComfyUi\git_nv2\ComfyUI\custom_nodes\ComfyUI-LTXVideo\pyramid_blending.py", line 7, in <module>
    from kornia.geometry.transform.pyramid import (
    ...<6 lines>...
    )
ImportError: cannot import name 'pad' from 'kornia.geometry.transform.pyramid' (Y:\ai_ComfyUi\git_nv2\python_embeded\Lib\site-packages\kornia\geometry\transform\pyramid.py)

If I do understand this correctly I can also use normal vae decode node for LTX? Any help appreciated. This is portable version of comfyui.

Lu-Gru avatar May 20 '26 11:05 Lu-Gru

Ok seams that pad was moved to keypoints potential fix:

diff --git a/pyramid_blending.py b/pyramid_blending.py
index afc4bac..74ca289 100644
--- a/pyramid_blending.py
+++ b/pyramid_blending.py
@@ -10,8 +10,8 @@ from kornia.geometry.transform.pyramid import (
     build_pyramid,
     find_next_powerof_two,
     is_powerof_two,
-    pad,
 )
+from kornia.geometry import keypoints
 from torch import Tensor
 
 from .nodes_registry import comfy_node

Lu-Gru avatar May 20 '26 11:05 Lu-Gru

Gemini told me that I should "from torch.nn.functional import pad". I'm very curious. I checked the submission records here and at Kornia. In 'pyramid.py', there has never been a 'pad' module. So before this, how did everyone use this set of nodes? Has no one ever raised the same question?

suede299 avatar May 20 '26 14:05 suede299

pip uninstall -y kornia pip install kornia==0.6.12

problem fixed

scantraxx7800-cmd avatar May 20 '26 23:05 scantraxx7800-cmd

So, if you have any custom node requirements for the newer version of Kornia, you just need to remove the import of 'pad' and add the line "pad = F.pad" below

suede299 avatar May 21 '26 08:05 suede299

kornia==0.8.2 should work

Kornia only just released a few days back. Broke my build also.

Image

JoeGaffney avatar May 21 '26 18:05 JoeGaffney

fixed thanks, Downgrade Kornia with \python_embeded\python.exe -m pip uninstall -y kornia \python_embeded\python.exe -m pip install kornia==0.6.12

beast181 avatar May 24 '26 04:05 beast181

Confirming fresh repro on current main (commit 229437c, 2026-05-11) with kornia==0.8.3, torch==2.12.0, Python 3.13, ComfyUI 0.22.0, macOS arm64 / MPS. The bug is purely a kornia API change — not platform-specific.

Diagnosis: kornia previously re-exported torch.nn.functional.pad into kornia.geometry.transform.pyramid's namespace; that re-export was dropped in 0.8.x. The other 5 names in that import block (PyrUp, build_laplacian_pyramid, build_pyramid, find_next_powerof_two, is_powerof_two) are still exported — the fix only needs to relocate pad to its real home.

Clean one-line patch (call sites at lines 31 and 44 work unchanged):

 from kornia.geometry.transform.pyramid import (
     PyrUp,
     build_laplacian_pyramid,
     build_pyramid,
     find_next_powerof_two,
     is_powerof_two,
-    pad,
 )
 from torch import Tensor
+from torch.nn.functional import pad

Preferable to pad = F.pad (also valid) since the explicit import is greppable and doesn't introduce a local binding. The kornia==0.6.12 downgrade works as a stopgap but pins a 3+-year-old kornia, which conflicts with newer ComfyUI packs that need modern kornia features.

#496 looks like a duplicate of this — might be worth closing one to consolidate. Happy to open a PR with the diff above; let me know.

omniscia avatar May 25 '26 23:05 omniscia

How is this still not fixed? Downgrading the latest ComfyUI to kornia 0.6.12 breaks the install.

Currently, these nodes are unusable on a fresh install of ComfyUI.

drowai avatar Jun 05 '26 06:06 drowai

Исправлено, спасибо. Понизьте версию Kornia с помощью команды \python_embeded\python.exe -m pip uninstall -y kornia и \python_embeded\python.exe -m pip install kornia==0.6.12.

Downgrading kornia does not solve the issue, as other nodes will require a new kornia version.

andrej-ka avatar Jun 05 '26 06:06 andrej-ka

kornia==0.7.3 works for me. It looks like at some point thereafter, ComyUI-LTXVideo ceases to work properly. I hope this helps others.

technofox01 avatar Jun 05 '26 13:06 technofox01

kornia==0.7.3 works for me. It looks like at some point thereafter, ComyUI-LTXVideo ceases to work properly. I hope this helps others.

Thanks, it worked for me

supremo-omega avatar Jun 10 '26 02:06 supremo-omega

I fixed by pip install kornia==0.8.2

NRTnarathip avatar Jun 15 '26 08:06 NRTnarathip

Opened #516 with a fix for this. kornia 0.8.3 dropped the pad re-export from kornia.geometry.transform.pyramid; since it was just torch.nn.functional.pad, the fix swaps the two calls over to F.pad (already imported in the file). Drop-in, no behavior change — works on a current portable build here. Anyone hitting this can apply the same change to pyramid_blending.py while waiting for it to merge.

VixenVillainous avatar Jun 18 '26 17:06 VixenVillainous

I opened https://github.com/Lightricks/ComfyUI-LTXVideo/pull/506 And it's also sitting stagnant.

DevNullInc avatar Jun 20 '26 09:06 DevNullInc

This is still a problem, and there is an open PR that resolves it. This could use some attention. I've tested the change @VixenVillainous and @DevNullInc proposed on ComfyUI v0.29.0 (latest) and it is working.

rudikershaw avatar Jul 30 '26 13:07 rudikershaw

Confirming fresh repro on current main (commit 229437c, 2026-05-11) with kornia==0.8.3, torch==2.12.0, Python 3.13, ComfyUI 0.22.0, macOS arm64 / MPS. The bug is purely a kornia API change — not platform-specific.

Diagnosis: kornia previously re-exported torch.nn.functional.pad into kornia.geometry.transform.pyramid's namespace; that re-export was dropped in 0.8.x. The other 5 names in that import block (PyrUp, build_laplacian_pyramid, build_pyramid, find_next_powerof_two, is_powerof_two) are still exported — the fix only needs to relocate pad to its real home.

Clean one-line patch (call sites at lines 31 and 44 work unchanged):

from kornia.geometry.transform.pyramid import ( PyrUp, build_laplacian_pyramid, build_pyramid, find_next_powerof_two, is_powerof_two,

  • pad, ) from torch import Tensor +from torch.nn.functional import pad

Preferable to pad = F.pad (also valid) since the explicit import is greppable and doesn't introduce a local binding. The kornia==0.6.12 downgrade works as a stopgap but pins a 3+-year-old kornia, which conflicts with newer ComfyUI packs that need modern kornia features.

#496 looks like a duplicate of this — might be worth closing one to consolidate. Happy to open a PR with the diff above; let me know.

This one line changes worked here too ty

nammmmm avatar Sep 01 '26 15:09 nammmmm