skillfed

CoLT5-attention

Conditionally Routed Attention

colt5-attention v0.11.2 82.5K downloads/30d#14,155 on PyPI231
Permissive 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) Active released

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-attention

uv

uv add colt5-attention

poetry

poetry add colt5-attention

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3.6Topic :: Scientific/Engineering :: Artificial Intelligence

Tags

efficient attention pytorchrouted attention mechanismconditional token routingtransformer attention optimizationsparse attention pytorchcolt5 attentiondynamic routing attention
attention-mechanismtransformer-optimizationpytorch

More Artificial Intelligence packages

Further reading