CoLT5-attention
Conditionally Routed Attention
What it is and what it does
CoLT5-attention is a PyTorch implementation of conditionally routed efficient attention from the CoLT5 architecture. It splits token processing into light and heavy branches, routing only a subset of tokens through computationally expensive operations while keeping the rest in a lightweight path. This reduces overall computation while maintaining model capacity for important tokens.
The package provides multiple attention variants: standard conditional routed attention for sequence processing, cross-attention for long-context scenarios, autoregressive attention for generation, and image attention for vision feature maps. All variants use coordinate descent routing optimized with Triton kernels. The implementation includes feedforward routing and complete transformer blocks, making it suitable as a drop-in component for building efficient transformer encoders.
Use it for:
- Reduce attention computation in long-sequence transformers by routing only critical tokens through expensive attention heads.
- Build efficient vision transformers that can process large feature maps (e.g., 256×256) that would be prohibitive with standard attention.
- Implement cross-attention over very large context windows (millions of tokens) by selectively routing key-value pairs.
- Speed up autoregressive generation by applying conditional routing within windowed attention patterns.
- Replace standard attention blocks in existing transformer architectures to lower memory and compute requirements.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Implements conditionally routed efficient attention mechanisms for PyTorch, routing a subset of tokens through lighter and heavier branches to reduce computational cost in transformer architectures.
Yes, with conditions. The package is actively maintained, permissively licensed, and solves a real efficiency problem for transformer-based models. Install if you need efficient attention for long sequences or large feature maps. Be aware that routing behavior is still being refined (author notes improvisation in key-value normalization), and gradient stability at high iteration counts warrants testing on your specific workload before production use.
Install
colt5-attention on PyPI
pip
pip install colt5-attentionuv
uv add colt5-attentionpoetry
poetry add colt5-attentionInstalling CoLT5-attention
Before you install
Low friction installation as a pure Python wheel with four runtime dependencies (torch, einops, local-attention, packaging). Active maintenance with a recent release and 231 repository stars.
License in practice
MIT License permits unrestricted use, modification, and distribution with only attribution and inclusion of the license notice required.
Quickstart
pip install colt5-attention
import torch
from colt5_attention import ConditionalRoutedAttention
attn = ConditionalRoutedAttention(
dim=512,
light_heads=8,
heavy_heads=8,
num_heavy_tokens_q=1024
)
tokens = torch.randn(2, 32768, 512)
mask = torch.ones(2, 32768).bool()
out = attn(tokens, mask=mask)
Requires PyTorch and CUDA for GPU acceleration; some features (autoregressive attention, cross-attention) benefit from Triton kernel support.
Verify before relying
- Stability and gradient behavior at high iteration counts (author notes occasional 1e-1 gradient differences beyond 20 iterations).
- Performance benchmarks against standard attention on typical workloads.
- Full API surface and all available attention variants beyond the core examples.
Package facts
| License | MIT License Copyright (c) 2023 Phil Wang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 4 — einops, local-attention, packaging, torch |
| Maintenance | actively maintained — 0 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 82,549/month — #14,155 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: colt5_attention-0.11.2-py3-none-any.whl
Keywords: artificial intelligence, attention mechanism, dynamic routing
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
local-attentionImplements local windowed attention for…
permissive · top 15,000 on PyPI
mamba-ssmMamba-ssm implements state-space model…
permissive · top 15,000 on PyPI
rotary-embedding-torchImplements rotary positional embeddings for…
permissive · top 15,000 on PyPI
x-transformersx-transformers provides modular transformer…
permissive · top 5,000 on PyPI
vit-pytorchProvides PyTorch implementations of Vision…
permissive · top 15,000 on PyPI
axial-positional-embeddingProvides axial positional embeddings for…
permissive · top 15,000 on PyPI
hyper-connectionsImplements multiple residual streams in neural…
permissive · top 15,000 on PyPI
conformerProvides PyTorch implementations of the…
permissive · top 15,000 on PyPI
flash-attnProvides optimized GPU implementations of…
permissive · top 15,000 on PyPI
fa3-fwdProvides a lightweight Flash-Attention-3…
permissive · top 15,000 on PyPI