[GH-ISSUE #114] na3d custom-op registration uses PEP-585 annotations, breaking import on torch < 2.7 #35

Open
opened 2026-10-26 22:19:28 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @j2gg0s on GitHub (Aug 13, 2026).
Original GitHub issue: https://github.com/Comfy-Org/comfy-kitchen/issues/114

Summary

Since v0.2.28, import comfy_kitchen fails outright on torch 2.6:

ValueError: infer_schema(func): Parameter kernel_size has unsupported type list[int].

The error is raised at package-import time, so the entire package becomes unimportable — not just the na3d op. Any downstream project on torch 2.6 breaks when it picks up a newer comfy-kitchen. That includes ComfyUI itself: its requirements.txt pins comfy-kitchen==0.2.31 but leaves torch unpinned, so whether it works depends entirely on which torch happens to be installed.

Root cause

comfy_kitchen/backends/eager/na.py (added in #95) registers the custom op with PEP-585 builtin-generic annotations:

@torch.library.custom_op("comfy_kitchen::na3d", mutates_args=())
def _op_na3d(
    q: torch.Tensor,
    k: torch.Tensor,
    v: torch.Tensor,
    kernel_size: list[int],
    is_causal: list[bool],
    scale: float | None,
) -> torch.Tensor:

torch.library.infer_schema only learned to accept builtin generics in torch 2.7.0: derived_seq_types() in torch/_library/infer_schema.py gained GenericAlias(list, (typ,)) and GenericAlias(collections.abc.Sequence, (typ,)) there (pytorch/pytorch#146594). On 2.6 it accepts only typing.List[int] / typing.Sequence[int].

Worth noting scale: float | None is not part of the problem — float | None compares and hashes equal to typing.Optional[float], so the dict lookup resolves fine even on 2.6. Only the two list[...] parameters fail.

Repro

torch 2.6.0+cu124, Python 3.10.12, Linux:

>>> import comfy_kitchen
ValueError: infer_schema(func): Parameter kernel_size has unsupported type list[int]

Import chain: comfy_kitchen/__init__.py:3 → backends/cuda/__init__.py:161 → backends/eager/__init__.py:71 → backends/eager/na.py:164.

Suggested fix

Two annotations, no behavior change, restores torch 2.6 compatibility at zero cost:

-    kernel_size: list[int],
-    is_causal: list[bool],
+    kernel_size: typing.List[int],
+    is_causal: typing.List[bool],

Alternatively, if torch >= 2.7 is intended as a real floor, it would help a lot to declare it — pyproject.toml currently has dependencies = [] with no mention of torch, so pip installs the package happily and the incompatibility only surfaces at runtime, with an error message that doesn't point at the version mismatch. Happy to send a PR for either direction.

Environment

  • comfy-kitchen 0.2.28 – 0.2.31 affected; 0.2.26 unaffected (predates #95)
  • torch 2.6.0+cu124
  • Python 3.10.12, Linux
Originally created by @j2gg0s on GitHub (Aug 13, 2026). Original GitHub issue: https://github.com/Comfy-Org/comfy-kitchen/issues/114 ## Summary Since **v0.2.28**, `import comfy_kitchen` fails outright on torch 2.6: ``` ValueError: infer_schema(func): Parameter kernel_size has unsupported type list[int]. ``` The error is raised at package-import time, so the entire package becomes unimportable — not just the `na3d` op. Any downstream project on torch 2.6 breaks when it picks up a newer comfy-kitchen. That includes ComfyUI itself: its `requirements.txt` pins `comfy-kitchen==0.2.31` but leaves `torch` unpinned, so whether it works depends entirely on which torch happens to be installed. ## Root cause `comfy_kitchen/backends/eager/na.py` (added in #95) registers the custom op with PEP-585 builtin-generic annotations: ```python @torch.library.custom_op("comfy_kitchen::na3d", mutates_args=()) def _op_na3d( q: torch.Tensor, k: torch.Tensor, v: torch.Tensor, kernel_size: list[int], is_causal: list[bool], scale: float | None, ) -> torch.Tensor: ``` `torch.library.infer_schema` only learned to accept builtin generics in **torch 2.7.0**: `derived_seq_types()` in `torch/_library/infer_schema.py` gained `GenericAlias(list, (typ,))` and `GenericAlias(collections.abc.Sequence, (typ,))` there (pytorch/pytorch#146594). On 2.6 it accepts only `typing.List[int]` / `typing.Sequence[int]`. Worth noting `scale: float | None` is *not* part of the problem — `float | None` compares and hashes equal to `typing.Optional[float]`, so the dict lookup resolves fine even on 2.6. Only the two `list[...]` parameters fail. ## Repro torch 2.6.0+cu124, Python 3.10.12, Linux: ```python >>> import comfy_kitchen ValueError: infer_schema(func): Parameter kernel_size has unsupported type list[int] ``` Import chain: `comfy_kitchen/__init__.py:3` → `backends/cuda/__init__.py:161` → `backends/eager/__init__.py:71` → `backends/eager/na.py:164`. ## Suggested fix Two annotations, no behavior change, restores torch 2.6 compatibility at zero cost: ```diff - kernel_size: list[int], - is_causal: list[bool], + kernel_size: typing.List[int], + is_causal: typing.List[bool], ``` Alternatively, if torch >= 2.7 is intended as a real floor, it would help a lot to declare it — `pyproject.toml` currently has `dependencies = []` with no mention of torch, so pip installs the package happily and the incompatibility only surfaces at runtime, with an error message that doesn't point at the version mismatch. Happy to send a PR for either direction. ## Environment - comfy-kitchen 0.2.28 – 0.2.31 affected; 0.2.26 unaffected (predates #95) - torch 2.6.0+cu124 - Python 3.10.12, Linux
Author
Owner

@coderabbitai[bot] commented on GitHub (Aug 13, 2026):

🔗 Related PRs

Comfy-Org/comfy-kitchen#105 - Document the actual PyTorch minimum (>=2.7.0) [open]


🧪 Issue enrichment is currently in open beta.

You can configure auto-planning by selecting labels in the issue_enrichment configuration.

To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

issue_enrichment:
  auto_enrich:
    enabled: false

💬 Have feedback or questions? Drop into our discord!

<!-- gh-comment-id:5277472083 --> @coderabbitai[bot] commented on GitHub (Aug 13, 2026): <!-- This is an auto-generated issue plan by CodeRabbit --> <details> <summary>🔗 Related PRs</summary> Comfy-Org/comfy-kitchen#105 - Document the actual PyTorch minimum (>=2.7.0) [open] </details> --- <details> <summary> 🧪 Issue enrichment is currently in open beta.</summary> You can configure auto-planning by selecting labels in the issue_enrichment configuration. To disable automatic issue enrichment, add the following to your `.coderabbit.yaml`: ```yaml issue_enrichment: auto_enrich: enabled: false ``` </details> 💬 Have feedback or questions? Drop into our [discord](https://discord.gg/coderabbit)!
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Comfy-Org/comfy-kitchen#35
No description provided.