--- id: colt5-attention version: "0.11.2" 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) license_treatment: permissive maintenance: active --- # CoLT5-attention — Conditionally Routed Attention License: permissive · Maintenance: active · Downloads: 82.5K/mo ## 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 above — 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 pip install colt5-attention uv add colt5-attention 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_current - Install friction: low - Maintenance: active - Downloads: 82.5K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags efficient attention pytorch, routed attention mechanism, conditional token routing, transformer attention optimization, sparse attention pytorch, colt5 attention, dynamic routing attention, attention-mechanism, transformer-optimization, pytorch [View on SkillFed](https://skillfed.io/packages/colt5-attention) · [View on PyPI](https://pypi.org/project/colt5-attention/)