Sparse / variable-length attention dispatch for ComfyUI custom nodes
Project description
comfy-sparse-attn
Sparse / variable-length attention dispatch for ComfyUI custom nodes, plus a
filesystem-link utility for staging sparse primitives under the comfy namespace
ahead of their upstream merge.
Quick Start
pip install comfy-sparse-attn
Varlen Attention
Handles the varlen case that ComfyUI's built-in attention doesn't cover: packed
sequences of different lengths across a batch, as produced by sparse 3D models
(point clouds, voxels, VarLenTensors). For ordinary dense attention use
optimized_attention_for_device from ComfyUI directly.
from comfy_sparse_attn import dispatch_varlen_attention
# q, k, v: [T, H, D] — total tokens packed across the batch
# cu_seqlens_q / cu_seqlens_kv: [B+1] int32 cumulative lengths
# max_seqlen_q / max_seqlen_kv: int, longest sequence in the batch
out = dispatch_varlen_attention(
q, k, v,
cu_seqlens_q, cu_seqlens_kv,
max_seqlen_q, max_seqlen_kv,
)
# out: [T, H, D]
Backend Priority
| GPU | Priority |
|---|---|
| SM ≥ 8.0 (Ampere / Ada / Hopper / Blackwell) | sage2 > flash > xformers > sdpa |
| Older / CPU | xformers > sdpa |
comfy Namespace Injection
Sparse primitives (comfy.sparse, comfy.ops_sparse, comfy.attention_sparse)
are written as if already merged into ComfyUI main. setup_link creates symlinks
at those paths at node-load time so the imports work today. When ComfyUI ships the
real files, setup_link detects them and becomes a no-op — no code changes needed.
Call it from your node's __init__.py before any model imports:
import pathlib
from comfy_sparse_attn import setup_link
_HERE = pathlib.Path(__file__).parent / "my_model"
setup_link(_HERE / "sparse.py", "sparse.py") # → comfy/sparse.py
setup_link(_HERE / "ops_sparse.py", "ops_sparse.py") # → comfy/ops_sparse.py
setup_link(_HERE / "attention_sparse.py", "attention_sparse.py") # → comfy/attention_sparse.py
setup_link skips silently if:
- The target is a real file (ComfyUI shipped it natively).
- The target is already a symlink pointing to the same source.
What This Package Is Not
- Not a dense attention dispatcher. Use
comfy.ldm.modules.attention.optimized_attention_for_device. - Not a kernel implementation. Routes to ComfyUI's built-in backends or xformers/SDPA.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file comfy_sparse_attn-0.0.4.tar.gz.
File metadata
- Download URL: comfy_sparse_attn-0.0.4.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb12be72d3daa01819b686f16e0d6100085b6aac4d5f3b42cdb52da0f5460260
|
|
| MD5 |
bb3c01301644e28d049ddb6ccc803e6e
|
|
| BLAKE2b-256 |
669ac3b12fb2659c84110c55196a9c4c37c19b52cd0346b0b576232b228a8372
|
Provenance
The following attestation bundles were made for comfy_sparse_attn-0.0.4.tar.gz:
Publisher:
publish.yml on PozzettiAndrea/comfy-sparse-attn
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
comfy_sparse_attn-0.0.4.tar.gz -
Subject digest:
fb12be72d3daa01819b686f16e0d6100085b6aac4d5f3b42cdb52da0f5460260 - Sigstore transparency entry: 976495594
- Sigstore integration time:
-
Permalink:
PozzettiAndrea/comfy-sparse-attn@9667d3fa9f6974d9d5123daaf0af70eab9c28fba -
Branch / Tag:
refs/heads/main - Owner: https://github.com/PozzettiAndrea
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9667d3fa9f6974d9d5123daaf0af70eab9c28fba -
Trigger Event:
push
-
Statement type:
File details
Details for the file comfy_sparse_attn-0.0.4-py3-none-any.whl.
File metadata
- Download URL: comfy_sparse_attn-0.0.4-py3-none-any.whl
- Upload date:
- Size: 20.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ea5cb4c81223c98b77fa07bc3c7efc4fb2f594b8d613a203b4b4a526b64ed1b
|
|
| MD5 |
af0be63f081786fdba9baf295309db7e
|
|
| BLAKE2b-256 |
368b97d4fc2b8066d00ce294bdedba69e50ae6469de91ecfe38e524182b21022
|
Provenance
The following attestation bundles were made for comfy_sparse_attn-0.0.4-py3-none-any.whl:
Publisher:
publish.yml on PozzettiAndrea/comfy-sparse-attn
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
comfy_sparse_attn-0.0.4-py3-none-any.whl -
Subject digest:
4ea5cb4c81223c98b77fa07bc3c7efc4fb2f594b8d613a203b4b4a526b64ed1b - Sigstore transparency entry: 976495596
- Sigstore integration time:
-
Permalink:
PozzettiAndrea/comfy-sparse-attn@9667d3fa9f6974d9d5123daaf0af70eab9c28fba -
Branch / Tag:
refs/heads/main - Owner: https://github.com/PozzettiAndrea
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9667d3fa9f6974d9d5123daaf0af70eab9c28fba -
Trigger Event:
push
-
Statement type: