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
Metadata
Release files for comfy-sparse-attn 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| comfy_sparse_attn-0.1.3.tar.gz | 19.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| comfy_sparse_attn-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 41.7 kB
Release files / comfy_sparse_attn-0.1.3.tar.gz
| Download URL | comfy_sparse_attn-0.1.3.tar.gz |
|---|---|
| Size | 19.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0cf13a571cd54569d6e44c93f3b354fabd6e4fdf3be0c73f409f9e26a1f5210
|
|
BLAKE2b-256 checksum How to use checksums |
92ccbc3cbd70d78253bed48d06eb8b6546ea95a47f0f19b7b550f362406a63d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 18, 2026.
Transparency logRelease files / comfy_sparse_attn-0.1.3-py3-none-any.whl
| Download URL | comfy_sparse_attn-0.1.3-py3-none-any.whl |
|---|---|
| Size | 22.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
650f1b853f2214df8a169b80ac830e6d2ed2411ebc39f7a774acf62f56b87795
|
|
BLAKE2b-256 checksum How to use checksums |
c68b77eb6bdf50a3eb2510bfd975cc6aa9dd32bd796a8408bf7f7487f5d415d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 18, 2026.
Transparency log