Skip to content

Conversation

@choovin
Copy link

@choovin choovin commented Jan 14, 2026

…cis)### Conclusion
The ComfyUI-TeaCache plugin is failing to import because of a code incompatibility with the installed version of ComfyUI.

Specific Error:

ImportError: cannot import name 'precompute_freqs_cis' from 'comfy.ldm.lightricks.model'

Reason:
The plugin's code (nodes.py) attempts to import precompute_freqs_cis from comfy.ldm.lightricks.model. However, in the current version of ComfyUI installed in the container, this function does not exist as a public export in that module. It appears to have been either renamed to _precompute_freqs_cis (making it private) or moved/refactored.

Verification Steps Performed:

  1. Filesystem Check: Confirmed the plugin exists in /workspace/ComfyUI/custom_nodes/ComfyUI-TeaCache.
  2. Dependency Check: einops and diffusers are installed and meet version requirements.
  3. Manual Reproduction: Executing the import manually in Python inside the container reproduced the ImportError.
  4. Code Inspection: Grepping the ComfyUI source code revealed that precompute_freqs_cis is only present as a private method (_precompute_freqs_cis) inside a class in model.py, not as a standalone public function.

Recommendation

The ComfyUI-TeaCache plugin (specifically the fork welltop-cn/ComfyUI-TeaCache) needs to be updated to match the current ComfyUI codebase, or a different compatible version/fork should be used. Alternatively, the plugin code can be patched to define or locate this function correctly.

修复方案

已通过修改 ComfyUI-TeaCache/nodes.py 源码修复此问题。

修复原理:
由于 ComfyUI 源码更新,原有的 precompute_freqs_cis 函数被移除或重构为私有方法。为了兼容,我们在插件中重新实现了 precompute_freqs_cis 函数,利用 comfy.ldm.lightricks.model 现有的辅助函数 (generate_freq_grid_pytorch, generate_freqs, interleaved_freqs_cis) 来生成位置编码。

具体修改内容:

/workspace/ComfyUI/custom_nodes/ComfyUI-TeaCache/nodes.py 中:

  1. 移除无效导入:

    - from comfy.ldm.lightricks.model import precompute_freqs_cis
  2. 添加新的导入:

    + from comfy.ldm.lightricks.model import generate_freq_grid_pytorch, generate_freqs, interleaved_freqs_cis
  3. 添加函数定义:

    def precompute_freqs_cis(
        indices_grid,
        dim,
        out_dtype,
        theta=10000.0,
        max_pos=[20, 2048, 2048],
        use_middle_indices_grid=False,
        num_attention_heads=32,
    ):
        indices = generate_freq_grid_pytorch(theta, indices_grid.shape[1], dim, indices_grid.device)
        freqs = generate_freqs(indices, indices_grid, max_pos, use_middle_indices_grid)
    
        # 2 because of cos and sin by 3 for (t, x, y), 1 for temporal only
        n_elem = 2 * indices_grid.shape[1]
        cos_freq, sin_freq = interleaved_freqs_cis(freqs, dim % n_elem)
        # The new LTXVModel in ComfyUI returns (cos, sin, split_mode)
        # Since we are using interleaved mode (default), split_mode is False
        return cos_freq.to(out_dtype), sin_freq.to(out_dtype), False

验证结果:
修改后,在容器内手动运行导入测试:

python3 -c "import sys; sys.path.append('/workspace/ComfyUI'); sys.path.append('/workspace/ComfyUI/custom_nodes/ComfyUI-TeaCache'); import nodes; print('Success')"

输出 Success,证明导入错误已解决。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant